blob: a2ad4b8bdc6ad57e27cc6f11ed56996d3fc8761c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <vector>
21
Steve Anton64b626b2019-01-28 17:25:26 -080022#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080023#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080024#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020035#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020047
ossu7bb87ee2017-01-23 04:56:25 -080048#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080050#endif
Steve Anton10542f22019-01-11 09:11:00 -080051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080066using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020068using cricket::RtpDataContentDescription;
69using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080070using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080071using cricket::SimulcastDescription;
72using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using cricket::StreamParams;
74using cricket::STUN_PORT_TYPE;
75using cricket::TransportDescription;
76using cricket::TransportInfo;
77using cricket::VideoCodec;
78using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080079using ::testing::ElementsAre;
80using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::IceCandidateCollection;
82using webrtc::IceCandidateInterface;
83using webrtc::JsepIceCandidate;
84using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070085using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080086using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080088using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::SessionDescriptionInterface;
90
91typedef std::vector<AudioCodec> AudioCodecs;
92typedef std::vector<Candidate> Candidates;
93
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080095static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080098static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800100static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const char kCandidateFoundation1[] = "a0+B/1";
104static const char kCandidateFoundation2[] = "a0+B/2";
105static const char kCandidateFoundation3[] = "a0+B/3";
106static const char kCandidateFoundation4[] = "a0+B/4";
107static const char kAttributeCryptoVoice[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
109 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
110 "dummy_session_params\r\n";
111static const char kAttributeCryptoVideo[] =
112 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
113 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200114static const char kFingerprint[] =
115 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +0200117static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118static const int kExtmapId = 1;
119static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
120static const char kExtmap[] =
121 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
122static const char kExtmapWithDirectionAndAttribute[] =
123 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700124static const char kExtmapWithDirectionAndAttributeEncrypted[] =
125 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
126 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
Peter Boström0c4e06b2015-10-07 12:23:21 +0200128static const uint8_t kIdentityDigest[] = {
129 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
130 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
lally@webrtc.org34807282015-02-24 20:19:39 +0000132static const char kDtlsSctp[] = "DTLS/SCTP";
133static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
134static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136struct CodecParams {
137 int max_ptime;
138 int ptime;
139 int min_ptime;
140 int sprop_stereo;
141 int stereo;
142 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000143 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144};
145
deadbeef9d3584c2016-02-16 17:54:10 -0800146// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
147// instead of "a=crypto", and have an explicit test for adding "a=crypto".
148// Currently it's the other way around.
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150// Reference sdp string
151static const char kSdpFullString[] =
152 "v=0\r\n"
153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
154 "s=-\r\n"
155 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800156 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
158 "c=IN IP4 74.125.127.126\r\n"
159 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
169 "raddr 192.168.1.5 rport 2346 "
170 "generation 2\r\n"
171 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
172 "raddr 192.168.1.5 rport 2348 "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
175 "a=mid:audio_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800178 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
180 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
181 "dummy_session_params\r\n"
182 "a=rtpmap:111 opus/48000/2\r\n"
183 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000184 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 "a=ssrc:1 cname:stream_1_cname\r\n"
186 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000187 "a=ssrc:1 mslabel:local_stream_1\r\n"
188 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 "m=video 3457 RTP/SAVPF 120\r\n"
190 "c=IN IP4 74.125.224.39\r\n"
191 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
192 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
199 "generation 2\r\n"
200 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
201 "generation 2\r\n"
202 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
203 "generation 2\r\n"
204 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
205 "a=mid:video_content_name\r\n"
206 "a=sendrecv\r\n"
207 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
208 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
209 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800210 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:2 cname:stream_1_cname\r\n"
212 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000213 "a=ssrc:2 mslabel:local_stream_1\r\n"
214 "a=ssrc:2 label:video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000216 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
217 "a=ssrc:3 mslabel:local_stream_1\r\n"
218 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219
220// SDP reference string without the candidates.
221static const char kSdpString[] =
222 "v=0\r\n"
223 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
224 "s=-\r\n"
225 "t=0 0\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
264static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000265 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000266 "c=IN IP4 0.0.0.0\r\n"
267 "a=rtcp:9 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"
271 "a=sendrecv\r\n"
272 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
273 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
274 "a=rtpmap:101 google-data/90000\r\n"
275 "a=ssrc:10 cname:data_channel_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000276 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
277 "a=ssrc:10 mslabel:data_channel\r\n"
278 "a=ssrc:10 label:data_channeld0\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200280// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000282 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000283 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000287 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000289// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200290// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
291// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000292static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000293 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000294 "a=sctp-port 5000\r\n"
295 "c=IN IP4 0.0.0.0\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n";
299
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200300// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700301static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000302 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700303 "a=sctp-port:5000\r\n"
304 "c=IN IP4 0.0.0.0\r\n"
305 "a=ice-ufrag:ufrag_data\r\n"
306 "a=ice-pwd:pwd_data\r\n"
307 "a=mid:data_content_name\r\n";
308
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000310 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 "c=IN IP4 74.125.127.126\r\n"
312 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
317 "raddr 192.168.1.5 rport 2346 "
318 "generation 2\r\n"
319 "a=ice-ufrag:ufrag_data\r\n"
320 "a=ice-pwd:pwd_data\r\n"
321 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000322 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000324static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000325 "v=0\r\n"
326 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
327 "s=-\r\n"
328 "t=0 0\r\n"
329 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000330 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000331 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000335 "a=x-google-flag:conference\r\n";
336
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000337static const char kSdpSessionString[] =
338 "v=0\r\n"
339 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
340 "s=-\r\n"
341 "t=0 0\r\n"
342 "a=msid-semantic: WMS local_stream\r\n";
343
344static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000345 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000346 "c=IN IP4 0.0.0.0\r\n"
347 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000348 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
349 "a=mid:audio_content_name\r\n"
350 "a=sendrecv\r\n"
351 "a=rtpmap:111 opus/48000/2\r\n"
352 "a=ssrc:1 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000353 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
354 "a=ssrc:1 mslabel:local_stream\r\n"
355 "a=ssrc:1 label:audio_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000356
357static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000358 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000359 "c=IN IP4 0.0.0.0\r\n"
360 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000361 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
362 "a=mid:video_content_name\r\n"
363 "a=sendrecv\r\n"
364 "a=rtpmap:120 VP8/90000\r\n"
365 "a=ssrc:2 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000366 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
367 "a=ssrc:2 mslabel:local_stream\r\n"
368 "a=ssrc:2 label:video_track_id_1\r\n";
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000369
deadbeef25ed4352016-12-12 18:37:36 -0800370// Reference sdp string using bundle-only.
371static const char kBundleOnlySdpFullString[] =
372 "v=0\r\n"
373 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
374 "s=-\r\n"
375 "t=0 0\r\n"
376 "a=group:BUNDLE audio_content_name video_content_name\r\n"
377 "a=msid-semantic: WMS local_stream_1\r\n"
378 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
379 "c=IN IP4 74.125.127.126\r\n"
380 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
381 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
388 "generation 2\r\n"
389 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
390 "raddr 192.168.1.5 rport 2346 "
391 "generation 2\r\n"
392 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
393 "raddr 192.168.1.5 rport 2348 "
394 "generation 2\r\n"
395 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
396 "a=mid:audio_content_name\r\n"
397 "a=sendrecv\r\n"
398 "a=rtcp-mux\r\n"
399 "a=rtcp-rsize\r\n"
400 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
401 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
402 "dummy_session_params\r\n"
403 "a=rtpmap:111 opus/48000/2\r\n"
404 "a=rtpmap:103 ISAC/16000\r\n"
405 "a=rtpmap:104 ISAC/32000\r\n"
406 "a=ssrc:1 cname:stream_1_cname\r\n"
407 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000408 "a=ssrc:1 mslabel:local_stream_1\r\n"
409 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800410 "m=video 0 RTP/SAVPF 120\r\n"
411 "c=IN IP4 0.0.0.0\r\n"
412 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
413 "a=bundle-only\r\n"
414 "a=mid:video_content_name\r\n"
415 "a=sendrecv\r\n"
416 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
417 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
418 "a=rtpmap:120 VP8/90000\r\n"
419 "a=ssrc-group:FEC 2 3\r\n"
420 "a=ssrc:2 cname:stream_1_cname\r\n"
421 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000422 "a=ssrc:2 mslabel:local_stream_1\r\n"
423 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef25ed4352016-12-12 18:37:36 -0800424 "a=ssrc:3 cname:stream_1_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000425 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
426 "a=ssrc:3 mslabel:local_stream_1\r\n"
427 "a=ssrc:3 label:video_track_id_1\r\n";
deadbeef25ed4352016-12-12 18:37:36 -0800428
deadbeef9d3584c2016-02-16 17:54:10 -0800429// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
430// tracks.
431static const char kPlanBSdpFullString[] =
432 "v=0\r\n"
433 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
434 "s=-\r\n"
435 "t=0 0\r\n"
436 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
437 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
438 "c=IN IP4 74.125.127.126\r\n"
439 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
440 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
443 "generation 2\r\n"
444 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
449 "raddr 192.168.1.5 rport 2346 "
450 "generation 2\r\n"
451 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
452 "raddr 192.168.1.5 rport 2348 "
453 "generation 2\r\n"
454 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
455 "a=mid:audio_content_name\r\n"
456 "a=sendrecv\r\n"
457 "a=rtcp-mux\r\n"
458 "a=rtcp-rsize\r\n"
459 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
460 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
461 "dummy_session_params\r\n"
462 "a=rtpmap:111 opus/48000/2\r\n"
463 "a=rtpmap:103 ISAC/16000\r\n"
464 "a=rtpmap:104 ISAC/32000\r\n"
465 "a=ssrc:1 cname:stream_1_cname\r\n"
466 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000467 "a=ssrc:1 mslabel:local_stream_1\r\n"
468 "a=ssrc:1 label:audio_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800469 "a=ssrc:4 cname:stream_2_cname\r\n"
470 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000471 "a=ssrc:4 mslabel:local_stream_2\r\n"
472 "a=ssrc:4 label:audio_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800473 "m=video 3457 RTP/SAVPF 120\r\n"
474 "c=IN IP4 74.125.224.39\r\n"
475 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
476 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
479 "generation 2\r\n"
480 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
481 "generation 2\r\n"
482 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
483 "generation 2\r\n"
484 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
485 "generation 2\r\n"
486 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
487 "generation 2\r\n"
488 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
489 "a=mid:video_content_name\r\n"
490 "a=sendrecv\r\n"
491 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
492 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
493 "a=rtpmap:120 VP8/90000\r\n"
494 "a=ssrc-group:FEC 2 3\r\n"
495 "a=ssrc:2 cname:stream_1_cname\r\n"
496 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000497 "a=ssrc:2 mslabel:local_stream_1\r\n"
498 "a=ssrc:2 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800499 "a=ssrc:3 cname:stream_1_cname\r\n"
500 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000501 "a=ssrc:3 mslabel:local_stream_1\r\n"
502 "a=ssrc:3 label:video_track_id_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800503 "a=ssrc:5 cname:stream_2_cname\r\n"
504 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000505 "a=ssrc:5 mslabel:local_stream_2\r\n"
506 "a=ssrc:5 label:video_track_id_2\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800507 "a=ssrc:6 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000508 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
509 "a=ssrc:6 mslabel:local_stream_2\r\n"
510 "a=ssrc:6 label:video_track_id_3\r\n";
deadbeef9d3584c2016-02-16 17:54:10 -0800511
512// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
513// tracks.
514static const char kUnifiedPlanSdpFullString[] =
515 "v=0\r\n"
516 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
517 "s=-\r\n"
518 "t=0 0\r\n"
519 "a=msid-semantic: WMS local_stream_1\r\n"
520 // Audio track 1, stream 1 (with candidates).
521 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
522 "c=IN IP4 74.125.127.126\r\n"
523 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
524 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
533 "raddr 192.168.1.5 rport 2346 "
534 "generation 2\r\n"
535 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
536 "raddr 192.168.1.5 rport 2348 "
537 "generation 2\r\n"
538 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
539 "a=mid:audio_content_name\r\n"
540 "a=msid:local_stream_1 audio_track_id_1\r\n"
541 "a=sendrecv\r\n"
542 "a=rtcp-mux\r\n"
543 "a=rtcp-rsize\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
545 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
546 "dummy_session_params\r\n"
547 "a=rtpmap:111 opus/48000/2\r\n"
548 "a=rtpmap:103 ISAC/16000\r\n"
549 "a=rtpmap:104 ISAC/32000\r\n"
550 "a=ssrc:1 cname:stream_1_cname\r\n"
551 // Video track 1, stream 1 (with candidates).
552 "m=video 3457 RTP/SAVPF 120\r\n"
553 "c=IN IP4 74.125.224.39\r\n"
554 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
555 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
558 "generation 2\r\n"
559 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
560 "generation 2\r\n"
561 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
562 "generation 2\r\n"
563 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
564 "generation 2\r\n"
565 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
566 "generation 2\r\n"
567 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
568 "a=mid:video_content_name\r\n"
569 "a=msid:local_stream_1 video_track_id_1\r\n"
570 "a=sendrecv\r\n"
571 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
572 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
573 "a=rtpmap:120 VP8/90000\r\n"
574 "a=ssrc-group:FEC 2 3\r\n"
575 "a=ssrc:2 cname:stream_1_cname\r\n"
576 "a=ssrc:3 cname:stream_1_cname\r\n"
577 // Audio track 2, stream 2.
578 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
579 "c=IN IP4 0.0.0.0\r\n"
580 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
581 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
582 "a=mid:audio_content_name_2\r\n"
583 "a=msid:local_stream_2 audio_track_id_2\r\n"
584 "a=sendrecv\r\n"
585 "a=rtcp-mux\r\n"
586 "a=rtcp-rsize\r\n"
587 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
588 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
589 "dummy_session_params\r\n"
590 "a=rtpmap:111 opus/48000/2\r\n"
591 "a=rtpmap:103 ISAC/16000\r\n"
592 "a=rtpmap:104 ISAC/32000\r\n"
593 "a=ssrc:4 cname:stream_2_cname\r\n"
594 // Video track 2, stream 2.
595 "m=video 9 RTP/SAVPF 120\r\n"
596 "c=IN IP4 0.0.0.0\r\n"
597 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
598 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
599 "a=mid:video_content_name_2\r\n"
600 "a=msid:local_stream_2 video_track_id_2\r\n"
601 "a=sendrecv\r\n"
602 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
603 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
604 "a=rtpmap:120 VP8/90000\r\n"
605 "a=ssrc:5 cname:stream_2_cname\r\n"
606 // Video track 3, stream 2.
607 "m=video 9 RTP/SAVPF 120\r\n"
608 "c=IN IP4 0.0.0.0\r\n"
609 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
610 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
611 "a=mid:video_content_name_3\r\n"
612 "a=msid:local_stream_2 video_track_id_3\r\n"
613 "a=sendrecv\r\n"
614 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
615 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
616 "a=rtpmap:120 VP8/90000\r\n"
617 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618
Seth Hampson5b4f0752018-04-02 16:31:36 -0700619// Unified Plan SDP reference string:
620// - audio track 1 has 1 a=msid lines
621// - audio track 2 has 2 a=msid lines
622// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
623// there are 0 media stream ids.
624// This Unified Plan SDP represents a SDP that signals the msid using both
625// a=msid and a=ssrc msid semantics.
626static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
627 "v=0\r\n"
628 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
629 "s=-\r\n"
630 "t=0 0\r\n"
631 "a=msid-semantic: WMS local_stream_1\r\n"
632 // Audio track 1, with 1 stream id.
633 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
634 "c=IN IP4 74.125.127.126\r\n"
635 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
636 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
639 "generation 2\r\n"
640 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
641 "generation 2\r\n"
642 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
643 "generation 2\r\n"
644 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
645 "raddr 192.168.1.5 rport 2346 "
646 "generation 2\r\n"
647 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
648 "raddr 192.168.1.5 rport 2348 "
649 "generation 2\r\n"
650 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
651 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700652 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700653 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700654 "a=rtcp-mux\r\n"
655 "a=rtcp-rsize\r\n"
656 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
657 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
658 "dummy_session_params\r\n"
659 "a=rtpmap:111 opus/48000/2\r\n"
660 "a=rtpmap:103 ISAC/16000\r\n"
661 "a=rtpmap:104 ISAC/32000\r\n"
662 "a=ssrc:1 cname:stream_1_cname\r\n"
663 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000664 "a=ssrc:1 mslabel:local_stream_1\r\n"
665 "a=ssrc:1 label:audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700666 // Audio track 2, with two stream ids.
667 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
668 "c=IN IP4 0.0.0.0\r\n"
669 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
670 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
671 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700672 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700673 "a=msid:local_stream_1 audio_track_id_2\r\n"
674 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700675 "a=rtcp-mux\r\n"
676 "a=rtcp-rsize\r\n"
677 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
678 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
679 "dummy_session_params\r\n"
680 "a=rtpmap:111 opus/48000/2\r\n"
681 "a=rtpmap:103 ISAC/16000\r\n"
682 "a=rtpmap:104 ISAC/32000\r\n"
683 "a=ssrc:4 cname:stream_1_cname\r\n"
684 // The support for Plan B msid signaling only includes the
685 // first media stream id "local_stream_1."
686 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000687 "a=ssrc:4 mslabel:local_stream_1\r\n"
688 "a=ssrc:4 label:audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700689 // Audio track 3, with no stream ids.
690 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
691 "c=IN IP4 0.0.0.0\r\n"
692 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
693 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
694 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700695 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700696 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700697 "a=rtcp-mux\r\n"
698 "a=rtcp-rsize\r\n"
699 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
700 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
701 "dummy_session_params\r\n"
702 "a=rtpmap:111 opus/48000/2\r\n"
703 "a=rtpmap:103 ISAC/16000\r\n"
704 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700705 "a=ssrc:7 cname:stream_2_cname\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000706 "a=ssrc:7 msid:- audio_track_id_3\r\n"
707 "a=ssrc:7 mslabel:-\r\n"
708 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700709
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800710// SDP string for unified plan without SSRCs
711static const char kUnifiedPlanSdpFullStringNoSsrc[] =
712 "v=0\r\n"
713 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
714 "s=-\r\n"
715 "t=0 0\r\n"
716 "a=msid-semantic: WMS local_stream_1\r\n"
717 // Audio track 1, stream 1 (with candidates).
718 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
719 "c=IN IP4 74.125.127.126\r\n"
720 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
721 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
724 "generation 2\r\n"
725 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
726 "generation 2\r\n"
727 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
728 "generation 2\r\n"
729 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
730 "raddr 192.168.1.5 rport 2346 "
731 "generation 2\r\n"
732 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
733 "raddr 192.168.1.5 rport 2348 "
734 "generation 2\r\n"
735 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
736 "a=mid:audio_content_name\r\n"
737 "a=msid:local_stream_1 audio_track_id_1\r\n"
738 "a=sendrecv\r\n"
739 "a=rtcp-mux\r\n"
740 "a=rtcp-rsize\r\n"
741 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
742 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
743 "dummy_session_params\r\n"
744 "a=rtpmap:111 opus/48000/2\r\n"
745 "a=rtpmap:103 ISAC/16000\r\n"
746 "a=rtpmap:104 ISAC/32000\r\n"
747 // Video track 1, stream 1 (with candidates).
748 "m=video 3457 RTP/SAVPF 120\r\n"
749 "c=IN IP4 74.125.224.39\r\n"
750 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
751 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
754 "generation 2\r\n"
755 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
756 "generation 2\r\n"
757 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
758 "generation 2\r\n"
759 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
760 "generation 2\r\n"
761 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
762 "generation 2\r\n"
763 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
764 "a=mid:video_content_name\r\n"
765 "a=msid:local_stream_1 video_track_id_1\r\n"
766 "a=sendrecv\r\n"
767 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
768 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
769 "a=rtpmap:120 VP8/90000\r\n"
770 // Audio track 2, stream 2.
771 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
772 "c=IN IP4 0.0.0.0\r\n"
773 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
774 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
775 "a=mid:audio_content_name_2\r\n"
776 "a=msid:local_stream_2 audio_track_id_2\r\n"
777 "a=sendrecv\r\n"
778 "a=rtcp-mux\r\n"
779 "a=rtcp-rsize\r\n"
780 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
781 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
782 "dummy_session_params\r\n"
783 "a=rtpmap:111 opus/48000/2\r\n"
784 "a=rtpmap:103 ISAC/16000\r\n"
785 "a=rtpmap:104 ISAC/32000\r\n"
786 // Video track 2, stream 2.
787 "m=video 9 RTP/SAVPF 120\r\n"
788 "c=IN IP4 0.0.0.0\r\n"
789 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
790 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
791 "a=mid:video_content_name_2\r\n"
792 "a=msid:local_stream_2 video_track_id_2\r\n"
793 "a=sendrecv\r\n"
794 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
795 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
796 "a=rtpmap:120 VP8/90000\r\n"
797 // Video track 3, stream 2.
798 "m=video 9 RTP/SAVPF 120\r\n"
799 "c=IN IP4 0.0.0.0\r\n"
800 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
801 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
802 "a=mid:video_content_name_3\r\n"
803 "a=msid:local_stream_2 video_track_id_3\r\n"
804 "a=sendrecv\r\n"
805 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
806 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
807 "a=rtpmap:120 VP8/90000\r\n";
808
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809// One candidate reference string as per W3c spec.
810// candidate:<blah> not a=candidate:<blah>CRLF
811static const char kRawCandidate[] =
812 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
813// One candidate reference string.
814static const char kSdpOneCandidate[] =
815 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
816 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000817
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000818static const char kSdpTcpActiveCandidate[] =
819 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
820 "tcptype active generation 2";
821static const char kSdpTcpPassiveCandidate[] =
822 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
823 "tcptype passive generation 2";
824static const char kSdpTcpSOCandidate[] =
825 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
826 "tcptype so generation 2";
827static const char kSdpTcpInvalidCandidate[] =
828 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
829 "tcptype invalid generation 2";
830
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000831// One candidate reference string with IPV6 address.
832static const char kRawIPV6Candidate[] =
833 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700834 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835
836// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800837static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800839 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840
Zach Steinb336c272018-08-09 01:16:13 -0700841static const char kRawHostnameCandidate[] =
842 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
843
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844// Session id and version
845static const char kSessionId[] = "18446744069414584320";
846static const char kSessionVersion[] = "18446462598732840960";
847
deadbeef9d3584c2016-02-16 17:54:10 -0800848// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849static const char kIceOption1[] = "iceoption1";
850static const char kIceOption2[] = "iceoption2";
851static const char kIceOption3[] = "iceoption3";
852
deadbeef9d3584c2016-02-16 17:54:10 -0800853// ICE ufrags/passwords.
854static const char kUfragVoice[] = "ufrag_voice";
855static const char kPwdVoice[] = "pwd_voice";
856static const char kUfragVideo[] = "ufrag_video";
857static const char kPwdVideo[] = "pwd_video";
858static const char kUfragData[] = "ufrag_data";
859static const char kPwdData[] = "pwd_data";
860
861// Extra ufrags/passwords for extra unified plan m= sections.
862static const char kUfragVoice2[] = "ufrag_voice_2";
863static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700864static const char kUfragVoice3[] = "ufrag_voice_3";
865static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800866static const char kUfragVideo2[] = "ufrag_video_2";
867static const char kPwdVideo2[] = "pwd_video_2";
868static const char kUfragVideo3[] = "ufrag_video_3";
869static const char kPwdVideo3[] = "pwd_video_3";
870
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871// Content name
872static const char kAudioContentName[] = "audio_content_name";
873static const char kVideoContentName[] = "video_content_name";
874static const char kDataContentName[] = "data_content_name";
875
deadbeef9d3584c2016-02-16 17:54:10 -0800876// Extra content names for extra unified plan m= sections.
877static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700878static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800879static const char kVideoContentName2[] = "video_content_name_2";
880static const char kVideoContentName3[] = "video_content_name_3";
881
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800883static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884static const char kStream1Cname[] = "stream_1_cname";
885static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200886static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800888static const uint32_t kVideoTrack1Ssrc1 = 2;
889static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
891// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800892static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893static const char kStream2Cname[] = "stream_2_cname";
894static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200895static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800896static const char kVideoTrackId2[] = "video_track_id_2";
897static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800899static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700900static const char kAudioTrackId3[] = "audio_track_id_3";
901static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
903// DataChannel
904static const char kDataChannelLabel[] = "data_channel";
905static const char kDataChannelMsid[] = "data_channeld0";
906static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200907static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
909// Candidate
910static const char kDummyMid[] = "dummy_mid";
911static const int kDummyIndex = 123;
912
913// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800914static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
916// Helper functions
917
918static bool SdpDeserialize(const std::string& message,
919 JsepSessionDescription* jdesc) {
920 return webrtc::SdpDeserialize(message, jdesc, NULL);
921}
922
923static bool SdpDeserializeCandidate(const std::string& message,
924 JsepIceCandidate* candidate) {
925 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
926}
927
928// Add some extra |newlines| to the |message| after |line|.
929static void InjectAfter(const std::string& line,
930 const std::string& newlines,
931 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800932 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933}
934
935static void Replace(const std::string& line,
936 const std::string& newlines,
937 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800938 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939}
940
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000941// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
942// message.
943static void ExpectParseFailure(const std::string& bad_sdp,
944 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800945 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000947 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000949 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
950}
951
952// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
953static void ExpectParseFailure(const char* good_part, const char* bad_part) {
954 std::string bad_sdp = kSdpFullString;
955 Replace(good_part, bad_part, &bad_sdp);
956 ExpectParseFailure(bad_sdp, bad_part);
957}
958
959// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
960static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
961 const std::string& newlines,
962 const std::string& bad_part) {
963 std::string bad_sdp = kSdpFullString;
964 InjectAfter(injectpoint, newlines, &bad_sdp);
965 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966}
967
Steve Anton4e70a722017-11-28 14:57:10 -0800968static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 std::string* message) {
970 std::string new_direction;
971 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800972 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 new_direction = "a=inactive";
974 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800975 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 new_direction = "a=sendonly";
977 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800978 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 new_direction = "a=recvonly";
980 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800981 case RtpTransceiverDirection::kSendRecv:
Markus Handell45c104b2020-03-11 10:51:13 +0100982 new_direction = "a=sendrecv";
983 break;
984 case RtpTransceiverDirection::kStopped:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 default:
Markus Handell45c104b2020-03-11 10:51:13 +0100986 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 new_direction = "a=sendrecv";
988 break;
989 }
990 Replace("a=sendrecv", new_direction, message);
991}
992
Yves Gerey665174f2018-06-19 15:03:05 +0200993static void ReplaceRejected(bool audio_rejected,
994 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 std::string* message) {
996 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800997 Replace("m=audio 9", "m=audio 0", message);
998 Replace(kAttributeIceUfragVoice, "", message);
999 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 }
1001 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001002 Replace("m=video 9", "m=video 0", message);
1003 Replace(kAttributeIceUfragVideo, "", message);
1004 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 }
1006}
1007
1008// WebRtcSdpTest
1009
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001010class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001012 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001013#ifdef WEBRTC_ANDROID
1014 webrtc::InitializeAndroidObjects();
1015#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // AudioContentDescription
1017 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001018 StreamParams audio_stream;
1019 audio_stream.id = kAudioTrackId1;
1020 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001021 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001022 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1023 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001024 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1025 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001026 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1027 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028
1029 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001030 video_desc_ = CreateVideoContentDescription();
1031 StreamParams video_stream;
1032 video_stream.id = kVideoTrackId1;
1033 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001034 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001035 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1036 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1037 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1038 video_stream.ssrc_groups.push_back(ssrc_group);
1039 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001040 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1041 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001042 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1043 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044
1045 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001046 desc_.AddTransportInfo(TransportInfo(
1047 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1048 desc_.AddTransportInfo(TransportInfo(
1049 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050
1051 // v4 host
1052 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001053 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001058 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001059 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1060 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001062 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001063 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1064 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001066 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001067 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1068 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069
1070 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001071 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001072 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1073 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001074 cricket::LOCAL_PORT_TYPE,
1075 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001077 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1078 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001079 cricket::LOCAL_PORT_TYPE,
1080 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001082 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1083 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001084 cricket::LOCAL_PORT_TYPE,
1085 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001087 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1088 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001089 cricket::LOCAL_PORT_TYPE,
1090 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091
1092 // stun
1093 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001094 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1095 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001096 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1097 address_stun, kCandidatePriority, "", "",
1098 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001099 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 candidate9.set_related_address(rel_address_stun);
1101
1102 address_stun.SetPort(port_stun++);
1103 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001104 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1105 address_stun, kCandidatePriority, "", "",
1106 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001107 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 candidate10.set_related_address(rel_address_stun);
1109
1110 // relay
1111 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001112 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001113 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1114 address_relay, kCandidatePriority, "", "",
1115 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001116 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001118 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1119 address_relay, kCandidatePriority, "", "",
1120 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001121 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122
1123 // voice
1124 candidates_.push_back(candidate1);
1125 candidates_.push_back(candidate2);
1126 candidates_.push_back(candidate5);
1127 candidates_.push_back(candidate6);
1128 candidates_.push_back(candidate9);
1129 candidates_.push_back(candidate10);
1130
1131 // video
1132 candidates_.push_back(candidate3);
1133 candidates_.push_back(candidate4);
1134 candidates_.push_back(candidate7);
1135 candidates_.push_back(candidate8);
1136 candidates_.push_back(candidate11);
1137 candidates_.push_back(candidate12);
1138
Yves Gerey665174f2018-06-19 15:03:05 +02001139 jcandidate_.reset(
1140 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141
1142 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001143 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 std::string mline_id;
1145 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001146 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 // In this test, the audio m line index will be 0, and the video m line
1148 // will be 1.
1149 bool is_video = (i > 5);
1150 mline_id = is_video ? "video_content_name" : "audio_content_name";
1151 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001152 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 jdesc_.AddCandidate(&jice);
1154 }
1155 }
1156
Seth Hampson5b4f0752018-04-02 16:31:36 -07001157 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001158 const IceCandidateCollection* video_candidates_collection =
1159 jdesc_.candidates(1);
1160 ASSERT_NE(nullptr, video_candidates_collection);
1161 std::vector<cricket::Candidate> video_candidates;
1162 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1163 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1164 c.set_transport_name("video_content_name");
1165 video_candidates.push_back(c);
1166 }
1167 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001168 }
1169
1170 // Turns the existing reference description into a description using
1171 // a=bundle-only. This means no transport attributes and a 0 port value on
1172 // the m= sections not associated with the BUNDLE-tag.
1173 void MakeBundleOnlyDescription() {
1174 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001175
1176 // And the rest of the transport attributes.
1177 desc_.transport_infos()[1].description.ice_ufrag.clear();
1178 desc_.transport_infos()[1].description.ice_pwd.clear();
1179 desc_.transport_infos()[1].description.connection_role =
1180 cricket::CONNECTIONROLE_NONE;
1181
1182 // Set bundle-only flag.
1183 desc_.contents()[1].bundle_only = true;
1184
1185 // Add BUNDLE group.
1186 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1187 group.AddContentName(kAudioContentName);
1188 group.AddContentName(kVideoContentName);
1189 desc_.AddGroup(group);
1190
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001191 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001192 jdesc_.session_version()));
1193 }
1194
deadbeef9d3584c2016-02-16 17:54:10 -08001195 // Turns the existing reference description into a plan B description,
1196 // with 2 audio tracks and 3 video tracks.
1197 void MakePlanBDescription() {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001198 audio_desc_ = new AudioContentDescription(*audio_desc_);
1199 video_desc_ = new VideoContentDescription(*video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001200
1201 StreamParams audio_track_2;
1202 audio_track_2.id = kAudioTrackId2;
1203 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001204 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001205 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1206 audio_desc_->AddStream(audio_track_2);
1207
1208 StreamParams video_track_2;
1209 video_track_2.id = kVideoTrackId2;
1210 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001211 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001212 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1213 video_desc_->AddStream(video_track_2);
1214
1215 StreamParams video_track_3;
1216 video_track_3.id = kVideoTrackId3;
1217 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001218 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001219 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1220 video_desc_->AddStream(video_track_3);
1221
1222 desc_.RemoveContentByName(kAudioContentName);
1223 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001224 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1225 absl::WrapUnique(audio_desc_));
1226 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1227 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001228
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001229 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001230 jdesc_.session_version()));
1231 }
1232
1233 // Turns the existing reference description into a unified plan description,
1234 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001235 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001236 // Audio track 2.
1237 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1238 StreamParams audio_track_2;
1239 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001240 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001241 if (use_ssrcs) {
1242 audio_track_2.cname = kStream2Cname;
1243 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1244 }
deadbeef9d3584c2016-02-16 17:54:10 -08001245 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001246 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1247 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001248 desc_.AddTransportInfo(TransportInfo(
1249 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001250 // Video track 2, in stream 2.
1251 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1252 StreamParams video_track_2;
1253 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001254 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001255 if (use_ssrcs) {
1256 video_track_2.cname = kStream2Cname;
1257 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1258 }
deadbeef9d3584c2016-02-16 17:54:10 -08001259 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001260 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1261 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001262 desc_.AddTransportInfo(TransportInfo(
1263 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001264
1265 // Video track 3, in stream 2.
1266 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1267 StreamParams video_track_3;
1268 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001269 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001270 if (use_ssrcs) {
1271 video_track_3.cname = kStream2Cname;
1272 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1273 }
deadbeef9d3584c2016-02-16 17:54:10 -08001274 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001275 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1276 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001277 desc_.AddTransportInfo(TransportInfo(
1278 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001279 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001280
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001281 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001282 jdesc_.session_version()));
1283 }
1284
1285 // Creates an audio content description with no streams, and some default
1286 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 AudioContentDescription* CreateAudioContentDescription() {
1288 AudioContentDescription* audio = new AudioContentDescription();
1289 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001290 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001291 audio->AddCrypto(CryptoParams(
1292 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1294 "dummy_session_params"));
1295 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001296 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001297 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001298 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1299 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 return audio;
1301 }
1302
Seth Hampson5b4f0752018-04-02 16:31:36 -07001303 // Turns the existing reference description into a unified plan description,
1304 // with 3 audio MediaContentDescriptions with special StreamParams that
1305 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1306 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001307 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001308 desc_.RemoveContentByName(kVideoContentName);
1309 desc_.RemoveTransportInfoByName(kVideoContentName);
1310 RemoveVideoCandidates();
1311
1312 // Audio track 2 has 2 media stream ids.
1313 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1314 StreamParams audio_track_2;
1315 audio_track_2.id = kAudioTrackId2;
1316 audio_track_2.cname = kStream1Cname;
1317 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1318 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1319 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001320 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1321 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001322 desc_.AddTransportInfo(TransportInfo(
1323 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001324
1325 // Audio track 3 has no stream ids.
1326 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1327 StreamParams audio_track_3;
1328 audio_track_3.id = kAudioTrackId3;
1329 audio_track_3.cname = kStream2Cname;
1330 audio_track_3.set_stream_ids({});
1331 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1332 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001333 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1334 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001335 desc_.AddTransportInfo(TransportInfo(
1336 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001337 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001338 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001339 jdesc_.session_version()));
1340 }
1341
Seth Hampson5897a6e2018-04-03 11:16:33 -07001342 // Turns the existing reference description into a unified plan description
1343 // with one audio MediaContentDescription that contains one StreamParams with
1344 // 0 ssrcs.
1345 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1346 desc_.RemoveContentByName(kVideoContentName);
1347 desc_.RemoveContentByName(kAudioContentName);
1348 desc_.RemoveTransportInfoByName(kVideoContentName);
1349 RemoveVideoCandidates();
1350
1351 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1352 StreamParams audio_track;
1353 audio_track.id = kAudioTrackId1;
1354 audio_track.set_stream_ids({kStreamId1});
1355 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001356 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1357 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001358
1359 // Enable signaling a=msid lines.
1360 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001361 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001362 jdesc_.session_version()));
1363 }
1364
deadbeef9d3584c2016-02-16 17:54:10 -08001365 // Creates a video content description with no streams, and some default
1366 // configuration.
1367 VideoContentDescription* CreateVideoContentDescription() {
1368 VideoContentDescription* video = new VideoContentDescription();
1369 video->AddCrypto(CryptoParams(
1370 1, "AES_CM_128_HMAC_SHA1_80",
1371 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1372 video->set_protocol(cricket::kMediaProtocolSavpf);
1373 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001374 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001375 return video;
1376 }
1377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001379 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001381 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382
1383 // content direction
1384 EXPECT_EQ(cd1->direction(), cd2->direction());
1385
1386 // rtcp_mux
1387 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1388
deadbeef13871492015-12-09 12:37:51 -08001389 // rtcp_reduced_size
1390 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 // cryptos
1393 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1394 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1395 ADD_FAILURE();
1396 return;
1397 }
Yves Gerey665174f2018-06-19 15:03:05 +02001398 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 const CryptoParams c1 = cd1->cryptos().at(i);
1400 const CryptoParams c2 = cd2->cryptos().at(i);
1401 EXPECT_TRUE(c1.Matches(c2));
1402 EXPECT_EQ(c1.key_params, c2.key_params);
1403 EXPECT_EQ(c1.session_params, c2.session_params);
1404 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001405
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001407 // Use an equivalence class here, for old and new versions of the
1408 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001409 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1410 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1411 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001412 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001413 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1414 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1415 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001416 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001417 } else {
1418 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1419 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420
1421 // codecs
1422 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1423
1424 // bandwidth
1425 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1426
1427 // streams
1428 EXPECT_EQ(cd1->streams(), cd2->streams());
1429
Johannes Kron0854eb62018-10-10 22:33:20 +02001430 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001431 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 // extmap
1434 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1435 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001436 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001437 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1438 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 EXPECT_EQ(ext1.uri, ext2.uri);
1440 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001441 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 }
1444
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001445 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1446 const std::vector<std::string>& ids) {
1447 // Order of elements does not matter, only equivalence of sets.
1448 EXPECT_EQ(rids.size(), ids.size());
1449 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001450 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1451 return rid.rid == id;
1452 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001453 }
1454 }
1455
Amit Hilbucha2012042018-12-03 11:35:05 -08001456 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1457 const SimulcastDescription& simulcast2) {
1458 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1459 EXPECT_EQ(simulcast1.receive_layers().size(),
1460 simulcast2.receive_layers().size());
1461 }
1462
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001463 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1464 const RtpDataContentDescription* dcd2) {
1465 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1466 }
1467
1468 void CompareSctpDataContentDescription(
1469 const SctpDataContentDescription* dcd1,
1470 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001471 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001472 EXPECT_EQ(dcd1->port(), dcd2->port());
1473 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001474 }
1475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 void CompareSessionDescription(const SessionDescription& desc1,
1477 const SessionDescription& desc2) {
1478 // Compare content descriptions.
1479 if (desc1.contents().size() != desc2.contents().size()) {
1480 ADD_FAILURE();
1481 return;
1482 }
Yves Gerey665174f2018-06-19 15:03:05 +02001483 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1485 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001486 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001488 EXPECT_EQ(c1.type, c2.type);
1489 EXPECT_EQ(c1.rejected, c2.rejected);
1490 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491
1492 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1493 if (IsAudioContent(&c1)) {
1494 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001495 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001497 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1499 }
1500
1501 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1502 if (IsVideoContent(&c1)) {
1503 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001504 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001506 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1508 }
1509
1510 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001511 if (c1.media_description()->as_sctp()) {
1512 ASSERT_TRUE(c2.media_description()->as_sctp());
1513 const SctpDataContentDescription* scd1 =
1514 c1.media_description()->as_sctp();
1515 const SctpDataContentDescription* scd2 =
1516 c2.media_description()->as_sctp();
1517 CompareSctpDataContentDescription(scd1, scd2);
1518 } else {
1519 if (IsDataContent(&c1)) {
1520 const RtpDataContentDescription* dcd1 =
1521 c1.media_description()->as_rtp_data();
1522 const RtpDataContentDescription* dcd2 =
1523 c2.media_description()->as_rtp_data();
1524 CompareRtpDataContentDescription(dcd1, dcd2);
1525 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001527
1528 CompareSimulcastDescription(
1529 c1.media_description()->simulcast_description(),
1530 c2.media_description()->simulcast_description());
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07001531 EXPECT_EQ(c1.media_description()->alt_protocol(),
1532 c2.media_description()->alt_protocol());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 }
1534
1535 // group
1536 const cricket::ContentGroups groups1 = desc1.groups();
1537 const cricket::ContentGroups groups2 = desc2.groups();
1538 EXPECT_EQ(groups1.size(), groups1.size());
1539 if (groups1.size() != groups2.size()) {
1540 ADD_FAILURE();
1541 return;
1542 }
1543 for (size_t i = 0; i < groups1.size(); ++i) {
1544 const cricket::ContentGroup group1 = groups1.at(i);
1545 const cricket::ContentGroup group2 = groups2.at(i);
1546 EXPECT_EQ(group1.semantics(), group2.semantics());
1547 const cricket::ContentNames names1 = group1.content_names();
1548 const cricket::ContentNames names2 = group2.content_names();
1549 EXPECT_EQ(names1.size(), names2.size());
1550 if (names1.size() != names2.size()) {
1551 ADD_FAILURE();
1552 return;
1553 }
1554 cricket::ContentNames::const_iterator iter1 = names1.begin();
1555 cricket::ContentNames::const_iterator iter2 = names2.begin();
1556 while (iter1 != names1.end()) {
1557 EXPECT_EQ(*iter1++, *iter2++);
1558 }
1559 }
1560
1561 // transport info
1562 const cricket::TransportInfos transports1 = desc1.transport_infos();
1563 const cricket::TransportInfos transports2 = desc2.transport_infos();
1564 EXPECT_EQ(transports1.size(), transports2.size());
1565 if (transports1.size() != transports2.size()) {
1566 ADD_FAILURE();
1567 return;
1568 }
1569 for (size_t i = 0; i < transports1.size(); ++i) {
1570 const cricket::TransportInfo transport1 = transports1.at(i);
1571 const cricket::TransportInfo transport2 = transports2.at(i);
1572 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 EXPECT_EQ(transport1.description.ice_ufrag,
1574 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001575 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001576 EXPECT_EQ(transport1.description.ice_mode,
1577 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 if (transport1.description.identity_fingerprint) {
1579 EXPECT_EQ(*transport1.description.identity_fingerprint,
1580 *transport2.description.identity_fingerprint);
1581 } else {
1582 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1583 transport2.description.identity_fingerprint.get());
1584 }
1585 EXPECT_EQ(transport1.description.transport_options,
1586 transport2.description.transport_options);
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001587 EXPECT_EQ(transport1.description.opaque_parameters,
1588 transport2.description.opaque_parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 }
deadbeefc80741f2015-10-22 13:14:45 -07001590
1591 // global attributes
1592 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001593 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 }
1595
Yves Gerey665174f2018-06-19 15:03:05 +02001596 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1597 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1599 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1600 CompareSessionDescription(*desc1.description(), *desc2.description());
1601 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1602 return false;
1603 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1604 const IceCandidateCollection* cc1 = desc1.candidates(i);
1605 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001606 if (cc1->count() != cc2->count()) {
1607 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001609 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 for (size_t j = 0; j < cc1->count(); ++j) {
1611 const IceCandidateInterface* c1 = cc1->at(j);
1612 const IceCandidateInterface* c2 = cc2->at(j);
1613 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1614 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1615 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1616 }
1617 }
1618 return true;
1619 }
1620
1621 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1622 // them with invalid keywords so that the parser will just ignore them.
1623 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001624 absl::StrReplaceAll(
1625 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 return true;
1627 }
1628
1629 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001630 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1631 int mline_index,
1632 const std::string& ufrag,
1633 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 std::string content_name;
1635 if (mline_index == 0) {
1636 content_name = kAudioContentName;
1637 } else if (mline_index == 1) {
1638 content_name = kVideoContentName;
1639 } else {
nissec80e7412017-01-11 05:56:46 -08001640 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 }
Yves Gerey665174f2018-06-19 15:03:05 +02001642 TransportInfo transport_info(content_name,
1643 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 SessionDescription* desc =
1645 const_cast<SessionDescription*>(jdesc->description());
1646 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001647 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1649 const IceCandidateCollection* cc = jdesc_.candidates(i);
1650 for (size_t j = 0; j < cc->count(); ++j) {
1651 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001652 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1653 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 }
1655 }
1656 }
1657 return true;
1658 }
1659
1660 void AddIceOptions(const std::string& content_name,
1661 const std::vector<std::string>& transport_options) {
1662 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1663 cricket::TransportInfo transport_info =
1664 *(desc_.GetTransportInfoByName(content_name));
1665 desc_.RemoveTransportInfoByName(content_name);
1666 transport_info.description.transport_options = transport_options;
1667 desc_.AddTransportInfo(transport_info);
1668 }
1669
deadbeef3f7219b2015-12-28 15:17:14 -08001670 void SetIceUfragPwd(const std::string& content_name,
1671 const std::string& ice_ufrag,
1672 const std::string& ice_pwd) {
1673 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1674 cricket::TransportInfo transport_info =
1675 *(desc_.GetTransportInfoByName(content_name));
1676 desc_.RemoveTransportInfoByName(content_name);
1677 transport_info.description.ice_ufrag = ice_ufrag;
1678 transport_info.description.ice_pwd = ice_pwd;
1679 desc_.AddTransportInfo(transport_info);
1680 }
1681
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001682 void AddOpaqueTransportParameters(const std::string& content_name,
1683 cricket::OpaqueTransportParameters params) {
1684 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1685 cricket::TransportInfo info = *(desc_.GetTransportInfoByName(content_name));
1686 desc_.RemoveTransportInfoByName(content_name);
1687 info.description.opaque_parameters = params;
1688 desc_.AddTransportInfo(info);
1689 }
1690
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07001691 void AddAltProtocol(const std::string& content_name,
1692 const std::string& alt_protocol) {
1693 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1694 cricket::MediaContentDescription* description =
1695 desc_.GetContentDescriptionByName(content_name);
1696 description->set_alt_protocol(alt_protocol);
1697 }
1698
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 void AddFingerprint() {
1700 desc_.RemoveTransportInfoByName(kAudioContentName);
1701 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001702 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001703 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001704 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001705 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1706 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001707 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1708 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001709 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001710 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1711 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001712 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 }
1714
jbauch5869f502017-06-29 12:31:36 -07001715 void AddExtmap(bool encrypted) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001716 audio_desc_ = new AudioContentDescription(*audio_desc_);
1717 video_desc_ = new VideoContentDescription(*video_desc_);
jbauch5869f502017-06-29 12:31:36 -07001718 audio_desc_->AddRtpHeaderExtension(
1719 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1720 video_desc_->AddRtpHeaderExtension(
1721 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 desc_.RemoveContentByName(kAudioContentName);
1723 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001724 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1725 absl::WrapUnique(audio_desc_));
1726 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1727 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 }
1729
1730 void RemoveCryptos() {
1731 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1732 video_desc_->set_cryptos(std::vector<CryptoParams>());
1733 }
1734
Seth Hampson5897a6e2018-04-03 11:16:33 -07001735 // Removes everything in StreamParams from the session description that is
1736 // used for a=ssrc lines.
1737 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001738 for (cricket::ContentInfo& content_info :
1739 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001740 // With Unified Plan there should be one StreamParams per m= section.
1741 StreamParams& stream =
1742 content_info.media_description()->mutable_streams()[0];
1743 stream.ssrcs.clear();
1744 stream.ssrc_groups.clear();
1745 stream.cname.clear();
1746 }
1747 }
1748
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001749 // Removes all a=ssrc lines from the SDP string, except for the
1750 // "a=ssrc:... cname:..." lines.
1751 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1752 const char kAttributeSsrc[] = "a=ssrc";
1753 const char kAttributeCname[] = "cname";
1754 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1755 while (ssrc_line_pos != std::string::npos) {
1756 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1757 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1758 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1759 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1760 // Only erase a=ssrc lines that don't contain "cname".
1761 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1762 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1763 } else {
1764 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1765 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1766 }
1767 }
1768 }
1769
Seth Hampson5897a6e2018-04-03 11:16:33 -07001770 // Removes all a=ssrc lines from the SDP string.
1771 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1772 const char kAttributeSsrc[] = "a=ssrc";
1773 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1774 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1775 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1776 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1777 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1778 }
1779 }
1780
Steve Anton4e70a722017-11-28 14:57:10 -08001781 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 audio_desc_->set_direction(direction);
1783 video_desc_->set_direction(direction);
1784 std::string new_sdp = kSdpFullString;
1785 ReplaceDirection(direction, &new_sdp);
1786
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001787 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 jdesc_.session_version())) {
1789 return false;
1790 }
Steve Antone831b8c2018-02-01 12:22:16 -08001791 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 EXPECT_EQ(new_sdp, message);
1793 return true;
1794 }
1795
1796 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001797 audio_desc_ = new AudioContentDescription(*audio_desc_);
1798 video_desc_ = new VideoContentDescription(*video_desc_);
zhihuang38989e52017-03-21 11:04:53 -07001799
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 desc_.RemoveContentByName(kAudioContentName);
1801 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001802 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001803 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001804 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001805 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001806 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1807 audio_rejected ? "" : kPwdVoice);
1808 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1809 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001810
1811 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1813
Steve Antona3a92c22017-12-07 10:27:41 -08001814 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001815 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001816 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 EXPECT_EQ(new_sdp, message);
1818 return true;
1819 }
1820
zstein4b2e0822017-02-17 19:48:38 -08001821 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001822 std::unique_ptr<SctpDataContentDescription> data(
1823 new SctpDataContentDescription());
1824 sctp_desc_ = data.get();
1825 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001826 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001827 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001828 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001829 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001830 desc_.AddTransportInfo(TransportInfo(
1831 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 }
1833
1834 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001835 std::unique_ptr<RtpDataContentDescription> data(
1836 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 data_desc_ = data.get();
1838
deadbeef67cf2c12016-04-13 10:07:16 -07001839 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 StreamParams data_stream;
1841 data_stream.id = kDataChannelMsid;
1842 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001843 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 data_stream.ssrcs.push_back(kDataChannelSsrc);
1845 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001846 data_desc_->AddCrypto(
1847 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1848 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001850 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1851 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001852 desc_.AddTransportInfo(TransportInfo(
1853 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 }
1855
Steve Anton4e70a722017-11-28 14:57:10 -08001856 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 std::string new_sdp = kSdpFullString;
1858 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001859 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860
1861 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1862
1863 audio_desc_->set_direction(direction);
1864 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001865 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 jdesc_.session_version())) {
1867 return false;
1868 }
1869 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1870 return true;
1871 }
1872
1873 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001874 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001876 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001878
Harald Alvestrandb97d2fe2020-02-28 11:54:40 +01001879 audio_desc_ = new AudioContentDescription(*audio_desc_);
1880 video_desc_ = new VideoContentDescription(*video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 desc_.RemoveContentByName(kAudioContentName);
1882 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001883 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001884 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001885 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001886 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001887 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1888 audio_rejected ? "" : kPwdVoice);
1889 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1890 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001891 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001892 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001893 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 return false;
1895 }
deadbeef3f7219b2015-12-28 15:17:14 -08001896 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 return true;
1898 }
1899
Yves Gerey665174f2018-06-19 15:03:05 +02001900 void TestDeserializeExtmap(bool session_level,
1901 bool media_level,
1902 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001903 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001904 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001905 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001907 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 std::string sdp_with_extmap = kSdpString;
1909 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001910 InjectAfter(kSessionTime,
1911 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1912 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 &sdp_with_extmap);
1914 }
1915 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001916 InjectAfter(kAttributeIcePwdVoice,
1917 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1918 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001920 InjectAfter(kAttributeIcePwdVideo,
1921 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1922 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 &sdp_with_extmap);
1924 }
1925 // The extmap can't be present at the same time in both session level and
1926 // media level.
1927 if (session_level && media_level) {
1928 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001929 EXPECT_FALSE(
1930 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1932 } else {
1933 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1934 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1935 }
1936 }
1937
1938 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001939 const std::string& name,
1940 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 cricket::CodecParameterMap::const_iterator found = params.find(name);
1942 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001943 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 }
1945
1946 void TestDeserializeCodecParams(const CodecParams& params,
1947 JsepSessionDescription* jdesc_output) {
1948 std::string sdp =
1949 "v=0\r\n"
1950 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1951 "s=-\r\n"
1952 "t=0 0\r\n"
1953 // Include semantics for WebRTC Media Streams since it is supported by
1954 // this parser, and will be added to the SDP when serializing a session
1955 // description.
1956 "a=msid-semantic: WMS\r\n"
1957 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001958 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 // Pltype 111 listed before 103 and 104 in the map.
1960 "a=rtpmap:111 opus/48000/2\r\n"
1961 // Pltype 103 listed before 104.
1962 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001963 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001964 "a=fmtp:111 0-15,66,70\r\n"
1965 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001967 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001968 << "; sprop-stereo=" << params.sprop_stereo
1969 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 12:11:31 +01001970 << "; maxaveragebitrate=" << params.maxaveragebitrate
1971 << "\r\n"
1972 "a=ptime:"
1973 << params.ptime
1974 << "\r\n"
1975 "a=maxptime:"
1976 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 sdp += os.str();
1978
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001979 os.clear();
1980 os.str("");
1981 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001982 os << "m=video 9 RTP/SAVPF 99 95\r\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01001983 "a=rtpmap:99 VP8/90000\r\n"
1984 "a=rtpmap:95 RTX/90000\r\n"
1985 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001986 sdp += os.str();
1987
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 // Deserialize
1989 SdpParseError error;
1990 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1991
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001993 GetFirstAudioContentDescription(jdesc_output->description());
1994 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 ASSERT_FALSE(acd->codecs().empty());
1996 cricket::AudioCodec opus = acd->codecs()[0];
1997 EXPECT_EQ("opus", opus.name);
1998 EXPECT_EQ(111, opus.id);
1999 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
2000 VerifyCodecParameter(opus.params, "stereo", params.stereo);
2001 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
2002 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002003 VerifyCodecParameter(opus.params, "maxaveragebitrate",
2004 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 for (size_t i = 0; i < acd->codecs().size(); ++i) {
2006 cricket::AudioCodec codec = acd->codecs()[i];
2007 VerifyCodecParameter(codec.params, "ptime", params.ptime);
2008 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00002010
stefan@webrtc.org85d27942014-06-09 12:51:39 +00002011 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002012 GetFirstVideoContentDescription(jdesc_output->description());
2013 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00002014 ASSERT_FALSE(vcd->codecs().empty());
2015 cricket::VideoCodec vp8 = vcd->codecs()[0];
2016 EXPECT_EQ("VP8", vp8.name);
2017 EXPECT_EQ(99, vp8.id);
2018 cricket::VideoCodec rtx = vcd->codecs()[1];
2019 EXPECT_EQ("RTX", rtx.name);
2020 EXPECT_EQ(95, rtx.id);
2021 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 }
2023
2024 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
2025 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002026 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 "v=0\r\n"
2028 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2029 "s=-\r\n"
2030 "t=0 0\r\n"
2031 // Include semantics for WebRTC Media Streams since it is supported by
2032 // this parser, and will be added to the SDP when serializing a session
2033 // description.
2034 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002035 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002036 "a=rtpmap:111 opus/48000/2\r\n";
2037 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 "m=video 3457 RTP/SAVPF 101\r\n"
2039 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02002040 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002042 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002043 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002045 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02002046 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002047 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002048 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002049 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 // Deserialize
2051 SdpParseError error;
2052 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002054 GetFirstAudioContentDescription(jdesc_output->description());
2055 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 ASSERT_FALSE(acd->codecs().empty());
2057 cricket::AudioCodec opus = acd->codecs()[0];
2058 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002059 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2060 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002063 GetFirstVideoContentDescription(jdesc_output->description());
2064 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 ASSERT_FALSE(vcd->codecs().empty());
2066 cricket::VideoCodec vp8 = vcd->codecs()[0];
2067 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2068 vp8.name.c_str());
2069 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002070 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002071 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2072 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002073 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2074 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2075 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2076 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2077 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2078 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2079 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 }
2081
2082 // Two SDP messages can mean the same thing but be different strings, e.g.
2083 // some of the lines can be serialized in different order.
2084 // However, a deserialized description can be compared field by field and has
2085 // no order. If deserializer has already been tested, serializing then
2086 // deserializing and comparing JsepSessionDescription will test
2087 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002088 void TestSerialize(const JsepSessionDescription& jdesc) {
2089 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 SdpParseError error;
2092 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2093 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2094 }
2095
zhihuang38989e52017-03-21 11:04:53 -07002096 // Calling 'Initialize' with a copy of the inner SessionDescription will
2097 // create a copy of the JsepSessionDescription without candidates. The
2098 // 'connection address' field, previously set from the candidates, must also
2099 // be reset.
2100 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2101 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2102 rtc::SocketAddress video_addr("0.0.0.0", 9);
2103 audio_desc_->set_connection_address(audio_addr);
2104 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002105 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002106 }
2107
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 protected:
2109 SessionDescription desc_;
2110 AudioContentDescription* audio_desc_;
2111 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002112 RtpDataContentDescription* data_desc_;
2113 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002115 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 JsepSessionDescription jdesc_;
2117};
2118
2119void TestMismatch(const std::string& string1, const std::string& string2) {
2120 int position = 0;
2121 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2122 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002123 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 break;
2125 }
2126 }
2127 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2128 << " character\n"
Jonas Olssonb2b20312020-01-14 12:11:31 +01002129 " 1: "
2130 << string1.substr(position, 20)
2131 << "\n"
2132 " 2: "
2133 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134}
2135
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2137 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002138 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 TestMismatch(std::string(kSdpFullString), message);
2140}
2141
2142TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002143 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002144 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145}
2146
2147// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2148// the case in a DTLS offer.
2149TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2150 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002151 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002152 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002153 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
2155 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002156 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2157 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158
2159 EXPECT_EQ(sdp_with_fingerprint, message);
2160}
2161
2162// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2163// be the case in a DTLS answer.
2164TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2165 AddFingerprint();
2166 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002167 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002168 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002169 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170
2171 std::string sdp_with_fingerprint = kSdpString;
2172 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2173 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002174 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2175 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176
2177 EXPECT_EQ(sdp_with_fingerprint, message);
2178}
2179
2180TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2181 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002182 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002183 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002184 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 EXPECT_EQ(std::string(kSdpString), message);
2186}
2187
2188TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2189 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2190 group.AddContentName(kAudioContentName);
2191 group.AddContentName(kVideoContentName);
2192 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002193 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002195 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196 std::string sdp_with_bundle = kSdpFullString;
2197 InjectAfter(kSessionTime,
2198 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2199 &sdp_with_bundle);
2200 EXPECT_EQ(sdp_with_bundle, message);
2201}
2202
2203TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002204 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002206 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002208 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002210 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002212 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002214 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 &sdp_with_bandwidth);
2216 EXPECT_EQ(sdp_with_bandwidth, message);
2217}
2218
2219TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2220 std::vector<std::string> transport_options;
2221 transport_options.push_back(kIceOption1);
2222 transport_options.push_back(kIceOption3);
2223 AddIceOptions(kAudioContentName, transport_options);
2224 transport_options.clear();
2225 transport_options.push_back(kIceOption2);
2226 transport_options.push_back(kIceOption3);
2227 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002228 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002230 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002232 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002234 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 &sdp_with_ice_options);
2236 EXPECT_EQ(sdp_with_ice_options, message);
2237}
2238
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002239TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithOpaqueTransportParams) {
2240 cricket::OpaqueTransportParameters params;
2241 params.protocol = "foo";
2242 params.parameters = "test64";
2243 AddOpaqueTransportParameters(kAudioContentName, params);
2244 AddOpaqueTransportParameters(kVideoContentName, params);
2245
2246 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2247 jdesc_.session_version()));
2248 std::string message = webrtc::SdpSerialize(jdesc_);
2249
2250 std::string sdp_with_transport_parameters = kSdpFullString;
2251 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2252 &sdp_with_transport_parameters);
2253 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2254 &sdp_with_transport_parameters);
2255 EXPECT_EQ(message, sdp_with_transport_parameters);
2256}
2257
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07002258TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAltProtocol) {
2259 AddAltProtocol(kAudioContentName, "foo");
2260 AddAltProtocol(kVideoContentName, "bar");
2261
2262 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2263 jdesc_.session_version()));
2264 std::string message = webrtc::SdpSerialize(jdesc_);
2265
2266 std::string sdp_with_alt_protocol = kSdpFullString;
2267 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2268 &sdp_with_alt_protocol);
2269 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2270 &sdp_with_alt_protocol);
2271 EXPECT_EQ(message, sdp_with_alt_protocol);
2272}
2273
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002275 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276}
2277
2278TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002279 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280}
2281
2282TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002283 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284}
2285
2286TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2287 EXPECT_TRUE(TestSerializeRejected(true, false));
2288}
2289
2290TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2291 EXPECT_TRUE(TestSerializeRejected(false, true));
2292}
2293
2294TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2295 EXPECT_TRUE(TestSerializeRejected(true, true));
2296}
2297
2298TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2299 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002300 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301
zhihuang38989e52017-03-21 11:04:53 -07002302 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002303 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304
2305 std::string expected_sdp = kSdpString;
2306 expected_sdp.append(kSdpRtpDataChannelString);
2307 EXPECT_EQ(expected_sdp, message);
2308}
2309
2310TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002311 bool use_sctpmap = true;
2312 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002313 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314
zhihuang38989e52017-03-21 11:04:53 -07002315 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002316 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317
2318 std::string expected_sdp = kSdpString;
2319 expected_sdp.append(kSdpSctpDataChannelString);
2320 EXPECT_EQ(message, expected_sdp);
2321}
2322
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002323void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2324 const SessionDescription& desc,
2325 int port) {
2326 // Take our pre-built session description and change the SCTP port.
2327 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2328 SctpDataContentDescription* dcdesc =
2329 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2330 dcdesc->set_port(port);
2331 ASSERT_TRUE(
2332 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2333}
2334
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002335TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002336 bool use_sctpmap = true;
2337 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002338 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002339 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002340
2341 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002342 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002343
Steve Antone831b8c2018-02-01 12:22:16 -08002344 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002345
2346 std::string expected_sdp = kSdpString;
2347 expected_sdp.append(kSdpSctpDataChannelString);
2348
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002349 absl::StrReplaceAll(
2350 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2351 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002352
2353 EXPECT_EQ(expected_sdp, message);
2354}
2355
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002356TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002357 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002358 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002359 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002360 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002361 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002362
2363 std::string expected_sdp = kSdpString;
2364 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002365 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002366 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002367 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002368 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002369}
2370
Johannes Kron0854eb62018-10-10 22:33:20 +02002371TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002372 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002373 TestSerialize(jdesc_);
2374}
2375
2376TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2377 cricket::MediaContentDescription* video_desc =
2378 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2379 ASSERT_TRUE(video_desc);
2380 cricket::MediaContentDescription* audio_desc =
2381 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2382 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002383 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002384 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002385 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002386 cricket::MediaContentDescription::kMedia);
2387 TestSerialize(jdesc_);
2388}
2389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002391 bool encrypted = false;
2392 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002393 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002394 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002395 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396
2397 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002398 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2399 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
2401 EXPECT_EQ(sdp_with_extmap, message);
2402}
2403
jbauch5869f502017-06-29 12:31:36 -07002404TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2405 bool encrypted = true;
2406 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002407 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002408 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002409 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002410 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002411}
2412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413TEST_F(WebRtcSdpTest, SerializeCandidates) {
2414 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002415 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002416
2417 Candidate candidate_with_ufrag(candidates_.front());
2418 candidate_with_ufrag.set_username("ABC");
2419 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2420 candidate_with_ufrag));
2421 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2422 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002423
2424 Candidate candidate_with_network_info(candidates_.front());
2425 candidate_with_network_info.set_network_id(1);
2426 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2427 candidate_with_network_info));
2428 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2429 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2430 candidate_with_network_info.set_network_cost(999);
2431 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2432 candidate_with_network_info));
2433 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2434 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2435 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436}
2437
Zach Steinb336c272018-08-09 01:16:13 -07002438TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2439 rtc::SocketAddress address("a.test", 1234);
2440 cricket::Candidate candidate(
2441 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2442 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2443 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2444 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2445 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2446}
2447
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002448// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2449// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002450TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002451 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002452 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2453 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2454 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002455 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002456 std::unique_ptr<IceCandidateInterface> jcandidate(
2457 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002458
2459 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2460 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2461}
2462
Taylor Brandstetter8206bc02020-04-02 12:36:38 -07002463// Test serializing a TCP candidate that came in with a missing tcptype. This
2464// shouldn't happen according to the spec, but our implementation has been
2465// accepting this for quite some time, treating it as a passive candidate.
2466//
2467// So, we should be able to at least convert such candidates to and from SDP.
2468// See: bugs.webrtc.org/11423
2469TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) {
2470 std::string missing_tcptype =
2471 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host";
2472 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2473 EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate));
2474
2475 EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR),
2476 jcandidate.candidate().tcptype());
2477}
2478
2479TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) {
2480 std::string ssltcp =
2481 "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype "
2482 "passive";
2483 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2484 EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate));
2485
2486 EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol());
2487}
2488
htaa6b99442016-04-12 10:29:17 -07002489TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002490 cricket::VideoCodec h264_codec("H264");
2491 h264_codec.SetParam("profile-level-id", "42e01f");
2492 h264_codec.SetParam("level-asymmetry-allowed", "1");
2493 h264_codec.SetParam("packetization-mode", "1");
2494 video_desc_->AddCodec(h264_codec);
2495
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002496 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002497
Steve Antone831b8c2018-02-01 12:22:16 -08002498 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002499 size_t after_pt = message.find(" H264/90000");
2500 ASSERT_NE(after_pt, std::string::npos);
2501 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2502 ASSERT_NE(before_pt, std::string::npos);
2503 before_pt += strlen("a=rtpmap:");
2504 std::string pt = message.substr(before_pt, after_pt - before_pt);
2505 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2506 std::string to_find = "a=fmtp:" + pt + " ";
2507 size_t fmtp_pos = message.find(to_find);
2508 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002509 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002510 ASSERT_NE(std::string::npos, fmtp_endpos);
2511 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2512 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2513 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2514 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002515 // Check that there are no spaces after semicolons.
2516 // https://bugs.webrtc.org/5793
2517 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002518}
2519
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002521 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 // Deserialize
2523 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2524 // Verify
2525 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2526}
2527
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002528TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002529 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002530 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002531 "v=0\r\n"
2532 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2533 "s=-\r\n"
2534 "t=0 0\r\n"
2535 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002536 // Deserialize
2537 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2538 EXPECT_EQ(0u, jdesc.description()->contents().size());
2539}
2540
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002542 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543 std::string sdp_without_carriage_return = kSdpFullString;
2544 Replace("\r\n", "\n", &sdp_without_carriage_return);
2545 // Deserialize
2546 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2547 // Verify
2548 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2549}
2550
2551TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2552 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002553 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002554 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002555 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002556 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2558 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2559}
2560
2561TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2562 static const char kSdpNoRtpmapString[] =
2563 "v=0\r\n"
2564 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2565 "s=-\r\n"
2566 "t=0 0\r\n"
2567 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2568 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002569 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 // The rtpmap line for static payload codec is optional.
2571 "a=rtpmap:18 G729/16000\r\n"
2572 "a=rtpmap:103 ISAC/16000\r\n";
2573
Steve Antona3a92c22017-12-07 10:27:41 -08002574 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2576 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002577 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002579 // The codecs in the AudioContentDescription should be in the same order as
2580 // the payload types (<fmt>s) on the m= line.
2581 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2582 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002583 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 EXPECT_EQ(ref_codecs, audio->codecs());
2585}
2586
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002587TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2588 static const char kSdpNoRtpmapString[] =
2589 "v=0\r\n"
2590 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2591 "s=-\r\n"
2592 "t=0 0\r\n"
2593 "m=audio 49232 RTP/AVP 18 103\r\n"
2594 "a=fmtp:18 annexb=yes\r\n"
2595 "a=rtpmap:103 ISAC/16000\r\n";
2596
Steve Antona3a92c22017-12-07 10:27:41 -08002597 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002598 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2599 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002600 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002601
2602 cricket::AudioCodec g729 = audio->codecs()[0];
2603 EXPECT_EQ("G729", g729.name);
2604 EXPECT_EQ(8000, g729.clockrate);
2605 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002606 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002607 ASSERT_TRUE(found != g729.params.end());
2608 EXPECT_EQ(found->second, "yes");
2609
2610 cricket::AudioCodec isac = audio->codecs()[1];
2611 EXPECT_EQ("ISAC", isac.name);
2612 EXPECT_EQ(103, isac.id);
2613 EXPECT_EQ(16000, isac.clockrate);
2614}
2615
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616// Ensure that we can deserialize SDP with a=fingerprint properly.
2617TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2618 // Add a DTLS a=fingerprint attribute to our session description.
2619 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002620 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002621 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 jdesc_.session_version()));
2623
Steve Antona3a92c22017-12-07 10:27:41 -08002624 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 std::string sdp_with_fingerprint = kSdpString;
2626 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2627 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2628 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2629 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2630}
2631
2632TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002633 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 std::string sdp_with_bundle = kSdpFullString;
2635 InjectAfter(kSessionTime,
2636 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2637 &sdp_with_bundle);
2638 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2639 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2640 group.AddContentName(kAudioContentName);
2641 group.AddContentName(kVideoContentName);
2642 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002643 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 jdesc_.session_version()));
2645 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2646}
2647
2648TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002649 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002651 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002653 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002655 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002656 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002658 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002660 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 jdesc_.session_version()));
2662 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2663}
2664
2665TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002666 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002668 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002670 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002672 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673 &sdp_with_ice_options);
2674 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2675 std::vector<std::string> transport_options;
2676 transport_options.push_back(kIceOption3);
2677 transport_options.push_back(kIceOption1);
2678 AddIceOptions(kAudioContentName, transport_options);
2679 transport_options.clear();
2680 transport_options.push_back(kIceOption3);
2681 transport_options.push_back(kIceOption2);
2682 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002683 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 jdesc_.session_version()));
2685 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2686}
2687
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002688TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithOpaqueTransportParams) {
2689 std::string sdp_with_transport_parameters = kSdpFullString;
2690 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2691 &sdp_with_transport_parameters);
2692 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2693 &sdp_with_transport_parameters);
2694
2695 JsepSessionDescription jdesc_with_transport_parameters(kDummyType);
2696 EXPECT_TRUE(SdpDeserialize(sdp_with_transport_parameters,
2697 &jdesc_with_transport_parameters));
2698
2699 cricket::OpaqueTransportParameters params;
2700 params.protocol = "foo";
2701 params.parameters = "test64";
2702
2703 AddOpaqueTransportParameters(kAudioContentName, params);
2704 AddOpaqueTransportParameters(kVideoContentName, params);
2705
2706 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2707 jdesc_.session_version()));
2708 EXPECT_TRUE(
2709 CompareSessionDescription(jdesc_, jdesc_with_transport_parameters));
2710}
2711
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -07002712TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithAltProtocol) {
2713 std::string sdp_with_alt_protocol = kSdpFullString;
2714 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2715 &sdp_with_alt_protocol);
2716 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2717 &sdp_with_alt_protocol);
2718
2719 JsepSessionDescription jdesc_with_alt_protocol(kDummyType);
2720 EXPECT_TRUE(SdpDeserialize(sdp_with_alt_protocol, &jdesc_with_alt_protocol));
2721
2722 AddAltProtocol(kAudioContentName, "foo");
2723 AddAltProtocol(kVideoContentName, "bar");
2724
2725 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2726 jdesc_.session_version()));
2727 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_alt_protocol));
2728}
2729
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2731 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002732 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 std::string sdp_with_ufrag_pwd = kSdpFullString;
2734 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2735 // Add session level ufrag and pwd
2736 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002737 "a=ice-pwd:session+level+icepwd\r\n"
2738 "a=ice-ufrag:session+level+iceufrag\r\n",
2739 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002741 InjectAfter(
2742 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2744 &sdp_with_ufrag_pwd);
2745 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002746 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2747 "media+level+icepwd"));
2748 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2749 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2751 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2752}
2753
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002755 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756}
2757
2758TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002759 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760}
2761
2762TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002763 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002764}
2765
2766TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2767 EXPECT_TRUE(TestDeserializeRejected(true, false));
2768}
2769
2770TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2771 EXPECT_TRUE(TestDeserializeRejected(false, true));
2772}
2773
2774TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2775 EXPECT_TRUE(TestDeserializeRejected(true, true));
2776}
2777
Artem Titovf0a34f22020-03-16 17:52:04 +00002778// Tests that we can still handle the sdp uses mslabel and label instead of
2779// msid for backward compatibility.
2780TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2781 jdesc_.description()->set_msid_supported(false);
2782 JsepSessionDescription jdesc(kDummyType);
2783 std::string sdp_without_msid = kSdpFullString;
2784 Replace("msid", "xmsid", &sdp_without_msid);
2785 // Deserialize
2786 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2787 // Verify
2788 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2789 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2790 ~cricket::kMsidSignalingSsrcAttribute);
2791}
2792
Johannes Kron0854eb62018-10-10 22:33:20 +02002793TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002794 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002795 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2796 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2797 // Deserialize
2798 JsepSessionDescription jdesc_deserialized(kDummyType);
2799 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2800 // Verify
2801 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2802}
2803
2804TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002805 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002806 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2807 // Deserialize
2808 JsepSessionDescription jdesc_deserialized(kDummyType);
2809 EXPECT_TRUE(
2810 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2811 // Verify
2812 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2813}
2814
2815TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2816 cricket::MediaContentDescription* video_desc =
2817 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2818 ASSERT_TRUE(video_desc);
2819 cricket::MediaContentDescription* audio_desc =
2820 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2821 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002822 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002823 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002824 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002825 cricket::MediaContentDescription::kMedia);
2826
2827 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2828 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2829 &sdp_with_extmap_allow_mixed);
2830 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2831 &sdp_with_extmap_allow_mixed);
2832
2833 // Deserialize
2834 JsepSessionDescription jdesc_deserialized(kDummyType);
2835 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2836 // Verify
2837 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2838}
2839
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2841 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2842
2843 std::string sdp = kSdpOneCandidate;
2844 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2845 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2846 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2847 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002848 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849
2850 // Candidate line without generation extension.
2851 sdp = kSdpOneCandidate;
2852 Replace(" generation 2", "", &sdp);
2853 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2854 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2855 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2856 Candidate expected = jcandidate_->candidate();
2857 expected.set_generation(0);
2858 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2859
honghaiza0c44ea2016-03-23 16:07:48 -07002860 // Candidate with network id and/or cost.
2861 sdp = kSdpOneCandidate;
2862 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2863 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2864 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2865 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2866 expected = jcandidate_->candidate();
2867 expected.set_network_id(2);
2868 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2869 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2870 // Add network cost
2871 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2872 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2873 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2874 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2875
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002876 sdp = kSdpTcpActiveCandidate;
2877 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2878 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002879 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002880 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2881 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2882 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002883 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2884 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002885 EXPECT_TRUE(
2886 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002887 sdp = kSdpTcpPassiveCandidate;
2888 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2889 sdp = kSdpTcpSOCandidate;
2890 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891}
2892
2893// This test verifies the deserialization of candidate-attribute
2894// as per RFC 5245. Candiate-attribute will be of the format
2895// candidate:<blah>. This format will be used when candidates
2896// are trickled.
2897TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2898 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2899
2900 std::string candidate_attribute = kRawCandidate;
2901 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2902 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2903 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2904 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2905 EXPECT_EQ(2u, jcandidate.candidate().generation());
2906
2907 // Candidate line without generation extension.
2908 candidate_attribute = kRawCandidate;
2909 Replace(" generation 2", "", &candidate_attribute);
2910 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2911 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2912 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2913 Candidate expected = jcandidate_->candidate();
2914 expected.set_generation(0);
2915 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2916
2917 // Candidate line without candidate:
2918 candidate_attribute = kRawCandidate;
2919 Replace("candidate:", "", &candidate_attribute);
2920 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2921
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002922 // Candidate line with IPV6 address.
2923 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002924
2925 // Candidate line with hostname address.
2926 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002927}
2928
2929// This test verifies that the deserialization of an invalid candidate string
2930// fails.
2931TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002932 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002933
2934 std::string candidate_attribute = kRawCandidate;
2935 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002937
2938 candidate_attribute = kSdpOneCandidate;
2939 candidate_attribute.replace(0, 1, "x");
2940 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2941
2942 candidate_attribute = kRawCandidate;
2943 candidate_attribute.append("\r\n");
2944 candidate_attribute.append(kRawCandidate);
2945 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2946
2947 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002948}
2949
2950TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2951 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002952 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002953 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954
2955 std::string sdp_with_data = kSdpString;
2956 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002957 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958
2959 // Deserialize
2960 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2961 // Verify
2962 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2963}
2964
2965TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002966 bool use_sctpmap = true;
2967 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002968 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002969 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970
2971 std::string sdp_with_data = kSdpString;
2972 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002973 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002975 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002976 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2977 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2978
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002979 // Verify with DTLS/SCTP.
2980 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2981 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002982 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2983 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2984
2985 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002986 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002987 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2989 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2990}
2991
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002992TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002993 bool use_sctpmap = false;
2994 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002995 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002996 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002997
2998 std::string sdp_with_data = kSdpString;
2999 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08003000 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003001
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00003002 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3003 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3004}
3005
lally69f57602015-10-08 10:15:04 -07003006TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08003007 bool use_sctpmap = false;
3008 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003009 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003010 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07003011
3012 std::string sdp_with_data = kSdpString;
3013 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08003014 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07003015
lally69f57602015-10-08 10:15:04 -07003016 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3017 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3018}
3019
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003020// Helper function to set the max-message-size parameter in the
3021// SCTP data codec.
3022void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003023 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003024 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02003025 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003026 SctpDataContentDescription* dcdesc =
3027 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
3028 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02003029 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003030}
3031
3032TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
3033 bool use_sctpmap = false;
3034 AddSctpDataChannel(use_sctpmap);
3035 JsepSessionDescription jdesc(kDummyType);
3036 std::string sdp_with_data = kSdpString;
3037
3038 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
3039 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003040 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003041 JsepSessionDescription jdesc_output(kDummyType);
3042
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02003043 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3044 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3045}
3046
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02003047TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
3048 bool use_sctpmap = false;
3049 AddSctpDataChannel(use_sctpmap);
3050 JsepSessionDescription jdesc(kDummyType);
3051 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
3052 std::string message = webrtc::SdpSerialize(jdesc);
3053 EXPECT_NE(std::string::npos,
3054 message.find("\r\na=max-message-size:12345\r\n"));
3055 JsepSessionDescription jdesc_output(kDummyType);
3056 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3057 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3058}
3059
3060TEST_F(WebRtcSdpTest,
3061 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
3062 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
3063 // The default max message size is 64K.
3064 bool use_sctpmap = false;
3065 AddSctpDataChannel(use_sctpmap);
3066 JsepSessionDescription jdesc(kDummyType);
3067 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
3068 std::string message = webrtc::SdpSerialize(jdesc);
3069 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
3070 JsepSessionDescription jdesc_output(kDummyType);
3071 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3072 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3073}
3074
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003075// Test to check the behaviour if sctp-port is specified
3076// on the m= line and in a=sctp-port.
3077TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08003078 bool use_sctpmap = true;
3079 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003080 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003081 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003082
3083 std::string sdp_with_data = kSdpString;
3084 // Append m= attributes
3085 sdp_with_data.append(kSdpSctpDataChannelString);
3086 // Append a=sctp-port attribute
3087 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08003088 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003089
3090 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3091}
3092
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003093// Test behavior if a=rtpmap occurs in an SCTP section.
3094TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
3095 std::string sdp_with_data = kSdpString;
3096 // Append m= attributes
3097 sdp_with_data.append(kSdpSctpDataChannelString);
3098 // Append a=rtpmap attribute
3099 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
3100 JsepSessionDescription jdesc_output(kDummyType);
3101 // Correct behavior is to ignore the extra attribute.
3102 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3103}
3104
3105TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
3106 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
3107 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
3108 for (auto proto : bad_strings) {
3109 std::string sdp_with_data = kSdpString;
3110 sdp_with_data.append("m=application 9 ");
3111 sdp_with_data.append(proto);
3112 sdp_with_data.append(" 47\r\n");
3113 JsepSessionDescription jdesc_output(kDummyType);
3114 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3115 << "Parsing should have failed on " << proto;
3116 }
3117 // The following strings are strange, but acceptable as RTP.
3118 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
3119 "obviously-bogus/RTP/"};
3120 for (auto proto : weird_strings) {
3121 std::string sdp_with_data = kSdpString;
3122 sdp_with_data.append("m=application 9 ");
3123 sdp_with_data.append(proto);
3124 sdp_with_data.append(" 47\r\n");
3125 JsepSessionDescription jdesc_output(kDummyType);
3126 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
3127 << "Parsing should have succeeded on " << proto;
3128 }
3129}
3130
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003131// For crbug/344475.
3132TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3133 std::string sdp_with_data = kSdpString;
3134 sdp_with_data.append(kSdpSctpDataChannelString);
3135 // Remove the "\n" at the end.
3136 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003137 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003138
3139 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3140 // No crash is a pass.
3141}
3142
zstein4b2e0822017-02-17 19:48:38 -08003143TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3144 bool use_sctpmap = true;
3145 AddSctpDataChannel(use_sctpmap);
3146
3147 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003148 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003149 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003150
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003151 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003152 std::string sdp_with_data = kSdpString;
3153 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003154 absl::StrReplaceAll(
3155 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3156 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003157 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003158
3159 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3160 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003161}
3162
3163TEST_F(WebRtcSdpTest,
3164 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3165 bool use_sctpmap = false;
3166 AddSctpDataChannel(use_sctpmap);
3167
Steve Antona3a92c22017-12-07 10:27:41 -08003168 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003169 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003170
3171 // We need to test the deserialized JsepSessionDescription from
3172 // kSdpSctpDataChannelStringWithSctpPort for
3173 // draft-ietf-mmusic-sctp-sdp-07
3174 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003175 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003176 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003177 absl::StrReplaceAll(
3178 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3179 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003180 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003181
3182 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3183 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003184}
3185
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003186TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003187 // We want to test that deserializing data content limits bandwidth
3188 // settings (it should never be greater than the default).
3189 // This should prevent someone from using unlimited data bandwidth through
3190 // JS and "breaking the Internet".
3191 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003192 std::string sdp_with_bandwidth = kSdpString;
3193 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003194 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003195 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003196 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003197
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003198 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3199}
3200
3201TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003202 bool use_sctpmap = true;
3203 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003204 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003205 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003206 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003207 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003208
3209 std::string sdp_with_bandwidth = kSdpString;
3210 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003211 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003212 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003213 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003214
3215 // SCTP has congestion control, so we shouldn't limit the bandwidth
3216 // as we do for RTP.
3217 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003218 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3219}
3220
Yves Gerey665174f2018-06-19 15:03:05 +02003221class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003222 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003223
3224TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003225 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003226 bool encrypted = GetParam();
3227 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228}
3229
Yves Gerey665174f2018-06-19 15:03:05 +02003230TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003231 bool encrypted = GetParam();
3232 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233}
3234
Yves Gerey665174f2018-06-19 15:03:05 +02003235TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003236 bool encrypted = GetParam();
3237 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238}
3239
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003240INSTANTIATE_TEST_SUITE_P(Encrypted,
3241 WebRtcSdpExtmapTest,
3242 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003243
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003244TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003245 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003246 std::string sdp = kSdpFullString;
3247 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3248 // Deserialize
3249 SdpParseError error;
3250 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
Artem Titovf0a34f22020-03-16 17:52:04 +00003251 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003252 EXPECT_EQ(lastline, error.line);
3253 EXPECT_EQ("Invalid SDP line.", error.description);
3254}
3255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3257 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3258 std::string new_sdp = kSdpOneCandidate;
3259 Replace("udp", "unsupported_transport", &new_sdp);
3260 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3261 new_sdp = kSdpOneCandidate;
3262 Replace("udp", "uDP", &new_sdp);
3263 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3264 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3265 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3266 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3267}
3268
honghaiza54a0802015-12-16 18:37:23 -08003269TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003271 EXPECT_TRUE(
3272 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3274 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3275 Candidate ref_candidate = jcandidate_->candidate();
3276 ref_candidate.set_username("user_rtp");
3277 ref_candidate.set_password("password_rtp");
3278 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3279}
3280
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003281TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003282 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003283
3284 // Deserialize
3285 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3286
3287 // Verify
3288 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003289 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003290 EXPECT_TRUE(audio->conference_mode());
3291
3292 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003293 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003294 EXPECT_TRUE(video->conference_mode());
3295}
3296
deadbeefd45aea82017-09-16 01:24:29 -07003297TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003298 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003299
3300 // We tested deserialization already above, so just test that if we serialize
3301 // and deserialize the flag doesn't disappear.
3302 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003303 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003304 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3305
3306 // Verify.
3307 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003308 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003309 EXPECT_TRUE(audio->conference_mode());
3310
3311 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003312 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003313 EXPECT_TRUE(video->conference_mode());
3314}
3315
Sebastian Jansson97321b62019-07-24 14:01:18 +02003316TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3317 {
3318 // By default remote estimates are disabled.
3319 JsepSessionDescription dst(kDummyType);
3320 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3321 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3322 ->remote_estimate());
3323 }
3324 {
3325 // When remote estimate is enabled, the setting is propagated via SDP.
3326 cricket::GetFirstVideoContentDescription(jdesc_.description())
3327 ->set_remote_estimate(true);
3328 JsepSessionDescription dst(kDummyType);
3329 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3330 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3331 ->remote_estimate());
3332 }
3333}
3334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3336 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003337 const char kSdpEmptyType[] = " =candidate";
3338 const char kSdpEqualAsPlus[] = "a+candidate";
3339 const char kSdpSpaceAfterEqual[] = "a= candidate";
3340 const char kSdpUpperType[] = "A=candidate";
3341 const char kSdpEmptyLine[] = "";
3342 const char kSdpMissingValue[] = "a=";
3343
Yves Gerey665174f2018-06-19 15:03:05 +02003344 const char kSdpBrokenFingerprint[] =
3345 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 "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 +02003347 const char kSdpExtraField[] =
3348 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003349 "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 +02003350 const char kSdpMissingSpace[] =
3351 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352 "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 +00003353 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003354 const char kSdpMd5[] =
3355 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003356 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357
3358 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003359 ExpectParseFailure("v=", kSdpDestroyer);
3360 ExpectParseFailure("o=", kSdpDestroyer);
3361 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003363 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364
3365 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003366 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3367 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368
3369 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003370 ExpectParseFailure("a=candidate", kSdpEmptyType);
3371 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3372 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3373 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374
3375 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3376 // because it's orthogonal to what we are replacing and hence
3377 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003378 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3379 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3380 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3381 ExpectParseFailure("a=sendrecv", kSdpMd5);
3382
3383 // Empty Line
3384 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3385 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003386}
3387
3388TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3389 // ssrc
3390 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003391 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003392 // crypto
3393 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3394 // rtpmap
3395 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3396 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3397 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3398 // candidate
3399 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3400 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3401 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3402 ExpectParseFailure("rport 2346", "rport badvalue");
3403 ExpectParseFailure("rport 2346 generation 2",
3404 "rport 2346 generation badvalue");
3405 // m line
3406 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3407 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3408
3409 // bandwidth
3410 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003411 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003412 // rtcp-fb
3413 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3414 "a=rtcp-fb:badvalue nack\r\n",
3415 "a=rtcp-fb:badvalue nack");
3416 // extmap
3417 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3418 "a=extmap:badvalue http://example.com\r\n",
3419 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420}
3421
3422TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003423 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424
3425 const char kSdpWithReorderedPlTypesString[] =
3426 "v=0\r\n"
3427 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3428 "s=-\r\n"
3429 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003430 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003431 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3432 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003434 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435
3436 // Deserialize
3437 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3438
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003440 GetFirstAudioContentDescription(jdesc_output.description());
3441 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003443 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3444 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 EXPECT_EQ(104, acd->codecs()[0].id);
3446}
3447
3448TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003449 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 CodecParams params;
3451 params.max_ptime = 40;
3452 params.ptime = 30;
3453 params.min_ptime = 10;
3454 params.sprop_stereo = 1;
3455 params.stereo = 1;
3456 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003457 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003459 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460}
3461
3462TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3463 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003464 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003466 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467}
3468
3469TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3470 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003471 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003473 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474}
3475
3476TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003477 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478
3479 const char kSdpWithFmtpString[] =
3480 "v=0\r\n"
3481 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3482 "s=-\r\n"
3483 "t=0 0\r\n"
3484 "m=video 3457 RTP/SAVPF 120\r\n"
3485 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003486 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3487
3488 // Deserialize
3489 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003490 EXPECT_TRUE(
3491 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003492
Donald Curtis0e07f922015-05-15 09:21:23 -07003493 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003494 GetFirstVideoContentDescription(jdesc_output.description());
3495 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003496 ASSERT_FALSE(vcd->codecs().empty());
3497 cricket::VideoCodec vp8 = vcd->codecs()[0];
3498 EXPECT_EQ("VP8", vp8.name);
3499 EXPECT_EQ(120, vp8.id);
3500 cricket::CodecParameterMap::iterator found =
3501 vp8.params.find("x-google-min-bitrate");
3502 ASSERT_TRUE(found != vp8.params.end());
3503 EXPECT_EQ(found->second, "10");
3504 found = vp8.params.find("x-google-max-quantization");
3505 ASSERT_TRUE(found != vp8.params.end());
3506 EXPECT_EQ(found->second, "40");
3507}
3508
johan2d8d23e2016-06-03 01:22:42 -07003509TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003510 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003511
3512 const char kSdpWithFmtpString[] =
3513 "v=0\r\n"
3514 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3515 "s=-\r\n"
3516 "t=0 0\r\n"
3517 "m=video 49170 RTP/AVP 98\r\n"
3518 "a=rtpmap:98 H264/90000\r\n"
3519 "a=fmtp:98 profile-level-id=42A01E; "
3520 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3521
3522 // Deserialize.
3523 SdpParseError error;
3524 EXPECT_TRUE(
3525 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3526
johan2d8d23e2016-06-03 01:22:42 -07003527 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003528 GetFirstVideoContentDescription(jdesc_output.description());
3529 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003530 ASSERT_FALSE(vcd->codecs().empty());
3531 cricket::VideoCodec h264 = vcd->codecs()[0];
3532 EXPECT_EQ("H264", h264.name);
3533 EXPECT_EQ(98, h264.id);
3534 cricket::CodecParameterMap::const_iterator found =
3535 h264.params.find("profile-level-id");
3536 ASSERT_TRUE(found != h264.params.end());
3537 EXPECT_EQ(found->second, "42A01E");
3538 found = h264.params.find("sprop-parameter-sets");
3539 ASSERT_TRUE(found != h264.params.end());
3540 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3541}
3542
Donald Curtis0e07f922015-05-15 09:21:23 -07003543TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003544 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003545
3546 const char kSdpWithFmtpString[] =
3547 "v=0\r\n"
3548 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3549 "s=-\r\n"
3550 "t=0 0\r\n"
3551 "m=video 3457 RTP/SAVPF 120\r\n"
3552 "a=rtpmap:120 VP8/90000\r\n"
3553 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554
3555 // Deserialize
3556 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003557 EXPECT_TRUE(
3558 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003561 GetFirstVideoContentDescription(jdesc_output.description());
3562 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 ASSERT_FALSE(vcd->codecs().empty());
3564 cricket::VideoCodec vp8 = vcd->codecs()[0];
3565 EXPECT_EQ("VP8", vp8.name);
3566 EXPECT_EQ(120, vp8.id);
3567 cricket::CodecParameterMap::iterator found =
3568 vp8.params.find("x-google-min-bitrate");
3569 ASSERT_TRUE(found != vp8.params.end());
3570 EXPECT_EQ(found->second, "10");
3571 found = vp8.params.find("x-google-max-quantization");
3572 ASSERT_TRUE(found != vp8.params.end());
3573 EXPECT_EQ(found->second, "40");
3574}
3575
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003576TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3577 JsepSessionDescription jdesc_output(kDummyType);
3578
3579 const char kSdpWithPacketizationString[] =
3580 "v=0\r\n"
3581 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3582 "s=-\r\n"
3583 "t=0 0\r\n"
3584 "m=audio 9 RTP/SAVPF 111\r\n"
3585 "a=rtpmap:111 opus/48000/2\r\n"
3586 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3587 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3588 "a=rtpmap:120 VP8/90000\r\n"
3589 "a=packetization:120 raw\r\n"
3590 "a=rtpmap:121 VP9/90000\r\n"
3591 "a=rtpmap:122 H264/90000\r\n"
3592 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3593
3594 SdpParseError error;
3595 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3596 &error));
3597
3598 AudioContentDescription* acd =
3599 GetFirstAudioContentDescription(jdesc_output.description());
3600 ASSERT_TRUE(acd);
3601 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3602 cricket::AudioCodec opus = acd->codecs()[0];
3603 EXPECT_EQ(opus.name, "opus");
3604 EXPECT_EQ(opus.id, 111);
3605
3606 const VideoContentDescription* vcd =
3607 GetFirstVideoContentDescription(jdesc_output.description());
3608 ASSERT_TRUE(vcd);
3609 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3610 cricket::VideoCodec vp8 = vcd->codecs()[0];
3611 EXPECT_EQ(vp8.name, "VP8");
3612 EXPECT_EQ(vp8.id, 120);
3613 EXPECT_EQ(vp8.packetization, "raw");
3614 cricket::VideoCodec vp9 = vcd->codecs()[1];
3615 EXPECT_EQ(vp9.name, "VP9");
3616 EXPECT_EQ(vp9.id, 121);
3617 EXPECT_EQ(vp9.packetization, absl::nullopt);
3618 cricket::VideoCodec h264 = vcd->codecs()[2];
3619 EXPECT_EQ(h264.name, "H264");
3620 EXPECT_EQ(h264.id, 122);
3621 EXPECT_EQ(h264.packetization, absl::nullopt);
3622}
3623
ossuaa4b0772017-01-30 07:41:18 -08003624TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003625 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003626
3627 cricket::AudioCodecs codecs = acd->codecs();
3628 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3629 acd->set_codecs(codecs);
3630
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003631 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003632 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003633 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003634 std::string sdp_with_fmtp = kSdpFullString;
3635 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3636 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3637 &sdp_with_fmtp);
3638 EXPECT_EQ(sdp_with_fmtp, message);
3639}
3640
3641TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003642 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003643
3644 cricket::AudioCodecs codecs = acd->codecs();
3645 codecs[0].params["stereo"] = "1";
3646 acd->set_codecs(codecs);
3647
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003648 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003649 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003650 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003651 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003652 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003653 &sdp_with_fmtp);
3654 EXPECT_EQ(sdp_with_fmtp, message);
3655}
3656
3657TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003658 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003659
3660 cricket::AudioCodecs codecs = acd->codecs();
3661 codecs[0].params["ptime"] = "20";
3662 codecs[0].params["maxptime"] = "120";
3663 acd->set_codecs(codecs);
3664
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003665 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003666 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003667 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003668 std::string sdp_with_fmtp = kSdpFullString;
3669 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3670 "a=maxptime:120\r\n" // No comma here. String merging!
3671 "a=ptime:20\r\n",
3672 &sdp_with_fmtp);
3673 EXPECT_EQ(sdp_with_fmtp, message);
3674}
3675
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003677 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003678
3679 cricket::VideoCodecs codecs = vcd->codecs();
3680 codecs[0].params["x-google-min-bitrate"] = "10";
3681 vcd->set_codecs(codecs);
3682
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003683 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003685 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686 std::string sdp_with_fmtp = kSdpFullString;
3687 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003688 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003689 EXPECT_EQ(sdp_with_fmtp, message);
3690}
3691
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003692TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3693 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3694
3695 cricket::VideoCodecs codecs = vcd->codecs();
3696 codecs[0].packetization = "raw";
3697 vcd->set_codecs(codecs);
3698
3699 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3700 jdesc_.session_version()));
3701 std::string message = webrtc::SdpSerialize(jdesc_);
3702 std::string sdp_with_packetization = kSdpFullString;
3703 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3704 &sdp_with_packetization);
3705 EXPECT_EQ(sdp_with_packetization, message);
3706}
3707
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003708TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3709 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003710 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003711 std::string sdp_with_icelite = kSdpFullString;
3712 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3713 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3714 const cricket::TransportInfo* tinfo1 =
3715 desc->GetTransportInfoByName("audio_content_name");
3716 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3717 const cricket::TransportInfo* tinfo2 =
3718 desc->GetTransportInfoByName("video_content_name");
3719 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003720
3721 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003722 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3724 desc = jdesc_with_icelite.description();
3725 const cricket::TransportInfo* atinfo =
3726 desc->GetTransportInfoByName("audio_content_name");
3727 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3728 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003729 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003730 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003731
3732 // Now that we know deserialization works, we can use TestSerialize to test
3733 // serialization.
3734 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003735}
3736
3737// Verifies that the candidates in the input SDP are parsed and serialized
3738// correctly in the output SDP.
3739TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3740 std::string sdp_with_data = kSdpString;
3741 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003742 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
3744 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003745 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003747
3748TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3749 AddFingerprint();
3750 TransportInfo audio_transport_info =
3751 *(desc_.GetTransportInfoByName(kAudioContentName));
3752 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3753 audio_transport_info.description.connection_role);
3754 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003755 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003756
3757 TransportInfo video_transport_info =
3758 *(desc_.GetTransportInfoByName(kVideoContentName));
3759 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3760 video_transport_info.description.connection_role);
3761 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003762 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003763
3764 desc_.RemoveTransportInfoByName(kAudioContentName);
3765 desc_.RemoveTransportInfoByName(kVideoContentName);
3766
3767 desc_.AddTransportInfo(audio_transport_info);
3768 desc_.AddTransportInfo(video_transport_info);
3769
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003770 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003771 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003772 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003773 std::string sdp_with_dtlssetup = kSdpFullString;
3774
3775 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003776 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3777 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003778 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003779 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003780 EXPECT_EQ(sdp_with_dtlssetup, message);
3781}
3782
3783TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003784 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003785 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003786 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003787 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3788 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3789 const cricket::TransportInfo* atinfo =
3790 desc->GetTransportInfoByName("audio_content_name");
3791 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3792 atinfo->description.connection_role);
3793 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003794 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003795 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3796 vtinfo->description.connection_role);
3797}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003798
3799// Verifies that the order of the serialized m-lines follows the order of the
3800// ContentInfo in SessionDescription, and vise versa for deserialization.
3801TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003802 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003803 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3804 kSdpSctpDataChannelString};
3805 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3806 cricket::MEDIA_TYPE_VIDEO,
3807 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003808
3809 // Verifies all 6 permutations.
3810 for (size_t i = 0; i < 6; ++i) {
3811 size_t media_content_in_sdp[3];
3812 // The index of the first media content.
3813 media_content_in_sdp[0] = i / 2;
3814 // The index of the second media content.
3815 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3816 // The index of the third media content.
3817 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3818
3819 std::string sdp_string = kSdpSessionString;
3820 for (size_t i = 0; i < 3; ++i)
3821 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3822
3823 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3824 cricket::SessionDescription* desc = jdesc.description();
3825 EXPECT_EQ(3u, desc->contents().size());
3826
3827 for (size_t i = 0; i < 3; ++i) {
3828 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003829 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003830 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3831 }
3832
Steve Antone831b8c2018-02-01 12:22:16 -08003833 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003834 EXPECT_EQ(sdp_string, serialized_sdp);
3835 }
3836}
deadbeef9d3584c2016-02-16 17:54:10 -08003837
deadbeef25ed4352016-12-12 18:37:36 -08003838TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3839 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003840 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003841 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003842 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3843 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3844}
3845
deadbeef12771a12017-01-03 13:53:47 -08003846// The semantics of "a=bundle-only" are only defined when it's used in
3847// combination with a 0 port on the m= line. We should ignore it if used with a
3848// nonzero port.
3849TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3850 // Make the base bundle-only description but unset the bundle-only flag.
3851 MakeBundleOnlyDescription();
3852 jdesc_.description()->contents()[1].bundle_only = false;
3853
3854 std::string modified_sdp = kBundleOnlySdpFullString;
3855 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003856 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003857 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3858 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003859}
3860
3861TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3862 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003863 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003864}
3865
deadbeef9d3584c2016-02-16 17:54:10 -08003866TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3867 MakePlanBDescription();
3868
Steve Antona3a92c22017-12-07 10:27:41 -08003869 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003870 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3871
3872 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3873}
3874
3875TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3876 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003877 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003878}
3879
3880TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3881 MakeUnifiedPlanDescription();
3882
Steve Antona3a92c22017-12-07 10:27:41 -08003883 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003884 EXPECT_TRUE(
3885 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3886
3887 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3888}
3889
3890TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3891 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003892 TestSerialize(jdesc_);
3893}
3894
Seth Hampson5b4f0752018-04-02 16:31:36 -07003895// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003896// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3897// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003898// with no stream ids and multiple stream ids. For parsing this, the Unified
3899// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3900// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003901TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3902 // Create both msid lines for Plan B and Unified Plan support.
3903 MakeUnifiedPlanDescriptionMultipleStreamIds(
3904 cricket::kMsidSignalingMediaSection |
3905 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003906
3907 JsepSessionDescription deserialized_description(kDummyType);
3908 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3909 &deserialized_description));
3910
3911 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003912 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3913 cricket::kMsidSignalingSsrcAttribute,
3914 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003915}
3916
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003917// Tests the serialization of a Unified Plan SDP that is compatible for both
3918// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3919// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3920// multiple stream ids.
3921TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3922 // Create both msid lines for Plan B and Unified Plan support.
3923 MakeUnifiedPlanDescriptionMultipleStreamIds(
3924 cricket::kMsidSignalingMediaSection |
3925 cricket::kMsidSignalingSsrcAttribute);
3926 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3927 // We explicitly test that the serialized SDP string is equal to the hard
3928 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3929 // take priority over "a=ssrc msid" lines. This means if we just used
3930 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3931 // and still pass, because the deserialized version would be the same.
3932 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3933}
3934
3935// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3936// that signal stream IDs) is deserialized appropriately. It tests the case for
3937// no stream ids and multiple stream ids.
3938TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3939 // Only create a=msid lines for strictly Unified Plan stream ID support.
3940 MakeUnifiedPlanDescriptionMultipleStreamIds(
3941 cricket::kMsidSignalingMediaSection);
3942
3943 JsepSessionDescription deserialized_description(kDummyType);
3944 std::string unified_plan_sdp_string =
3945 kUnifiedPlanSdpFullStringWithSpecialMsid;
3946 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3947 EXPECT_TRUE(
3948 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3949
3950 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3951}
3952
3953// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3954// that signal stream IDs) is serialized appropriately. It tests the case for no
3955// stream ids and multiple stream ids.
3956TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3957 // Only create a=msid lines for strictly Unified Plan stream ID support.
3958 MakeUnifiedPlanDescriptionMultipleStreamIds(
3959 cricket::kMsidSignalingMediaSection);
3960
Seth Hampson5b4f0752018-04-02 16:31:36 -07003961 TestSerialize(jdesc_);
3962}
3963
Seth Hampson5897a6e2018-04-03 11:16:33 -07003964// This tests that a Unified Plan SDP with no a=ssrc lines is
3965// serialized/deserialized appropriately. In this case the
3966// MediaContentDescription will contain a StreamParams object that doesn't have
3967// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3968// SSRC lines.
3969TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3970 MakeUnifiedPlanDescription();
3971 RemoveSsrcSignalingFromStreamParams();
3972 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3973 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3974
3975 JsepSessionDescription deserialized_description(kDummyType);
3976 EXPECT_TRUE(
3977 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3978 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3979}
3980
3981TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3982 MakeUnifiedPlanDescription();
3983 RemoveSsrcSignalingFromStreamParams();
3984
3985 TestSerialize(jdesc_);
3986}
3987
Steve Antone831b8c2018-02-01 12:22:16 -08003988TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3989 JsepSessionDescription jsep_desc(kDummyType);
3990 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3991 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3992}
3993
3994TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3995 JsepSessionDescription jsep_desc(kDummyType);
3996 std::string sdp = kSdpSessionString;
3997 sdp += kSdpSctpDataChannelString;
3998 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3999 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
4000}
4001
4002TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
4003 JsepSessionDescription jsep_desc(kDummyType);
4004 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
4005 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
4006 jsep_desc.description()->msid_signaling());
4007}
4008
4009TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
4010 JsepSessionDescription jsep_desc(kDummyType);
4011 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
4012 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
4013 jsep_desc.description()->msid_signaling());
4014}
4015
4016const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
4017const char kSsrcAttributeMsidLine[] =
4018 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
4019
4020TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
4021 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
4022 std::string sdp = webrtc::SdpSerialize(jdesc_);
4023
4024 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
4025 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
4026}
4027
4028TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
4029 jdesc_.description()->set_msid_signaling(
4030 cricket::kMsidSignalingSsrcAttribute);
4031 std::string sdp = webrtc::SdpSerialize(jdesc_);
4032
4033 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
4034 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
4035}
4036
4037TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
4038 jdesc_.description()->set_msid_signaling(
4039 cricket::kMsidSignalingMediaSection |
4040 cricket::kMsidSignalingSsrcAttribute);
4041 std::string sdp = webrtc::SdpSerialize(jdesc_);
4042
4043 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
4044 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08004045}
deadbeef7e146cb2016-09-28 10:04:34 -07004046
4047// Regression test for heap overflow bug:
4048// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
4049TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07004050 // The issue occurs when the sctp-port attribute is found in a video
4051 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08004052 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07004053 "v=0\r\n"
4054 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4055 "s=-\r\n"
4056 "t=0 0\r\n"
4057 "m=video 9 UDP/DTLS/SCTP 120\r\n"
4058 "a=sctp-port 5000\r\n"
4059 "a=fmtp:108 foo=10\r\n";
4060
4061 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
4062 "sctp-port");
4063}
deadbeefb2362572016-12-13 16:37:06 -08004064
4065// Regression test for integer overflow bug:
4066// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
4067TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08004068 // Bandwidth attribute is the max signed 32-bit int, which will get
4069 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08004070 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08004071 "v=0\r\n"
4072 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4073 "s=-\r\n"
4074 "t=0 0\r\n"
4075 "m=video 3457 RTP/SAVPF 120\r\n"
4076 "b=AS:2147483647\r\n"
4077 "foo=fail\r\n";
4078
4079 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
4080}
deadbeef7bcdb692017-01-20 12:43:58 -08004081
deadbeefbc88c6b2017-08-02 11:26:34 -07004082// Similar to the above, except that negative values are illegal, not just
4083// error-prone as large values are.
4084// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
4085TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
4086 static const char kSdpWithNegativeBandwidth[] =
4087 "v=0\r\n"
4088 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4089 "s=-\r\n"
4090 "t=0 0\r\n"
4091 "m=video 3457 RTP/SAVPF 120\r\n"
4092 "b=AS:-1000\r\n";
4093
4094 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
4095}
4096
deadbeef3e8016e2017-08-03 17:49:30 -07004097// An exception to the above rule: a value of -1 for b=AS should just be
4098// ignored, resulting in "kAutoBandwidth" in the deserialized object.
4099// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4100// limit", but this is now what ommitting the attribute entirely will do, so
4101// ignoring it will have the intended effect.
4102TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4103 static const char kSdpWithBandwidthOfNegativeOne[] =
4104 "v=0\r\n"
4105 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4106 "s=-\r\n"
4107 "t=0 0\r\n"
4108 "m=video 3457 RTP/SAVPF 120\r\n"
4109 "b=AS:-1\r\n";
4110
Steve Antona3a92c22017-12-07 10:27:41 -08004111 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07004112 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07004113 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08004114 GetFirstVideoContentDescription(jdesc_output.description());
4115 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07004116 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4117}
4118
deadbeef7bcdb692017-01-20 12:43:58 -08004119// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4120// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4121// Regression test for:
4122// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4123TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4124 // Important piece is "ufrag foo pwd bar".
4125 static const char kSdpWithIceCredentialsInCandidateString[] =
4126 "v=0\r\n"
4127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4128 "s=-\r\n"
4129 "t=0 0\r\n"
4130 "m=audio 9 RTP/SAVPF 111\r\n"
4131 "c=IN IP4 0.0.0.0\r\n"
4132 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4133 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4134 "a=rtpmap:111 opus/48000/2\r\n"
4135 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4136 "generation 2 ufrag foo pwd bar\r\n";
4137
Steve Antona3a92c22017-12-07 10:27:41 -08004138 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004139 EXPECT_TRUE(
4140 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4141 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4142 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004143 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004144 cricket::Candidate c = candidates->at(0)->candidate();
4145 EXPECT_EQ("ufrag_voice", c.username());
4146 EXPECT_EQ("pwd_voice", c.password());
4147}
deadbeef90f1e1e2017-02-10 12:35:05 -08004148
Johannes Kron211856b2018-09-06 12:12:28 +02004149// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4150// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4151// Regression test for:
4152// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4153TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4154 static const char kSdpWithFooIceCredentials[] =
4155 "v=0\r\n"
4156 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4157 "s=-\r\n"
4158 "t=0 0\r\n"
4159 "m=audio 9 RTP/SAVPF 111\r\n"
4160 "c=IN IP4 0.0.0.0\r\n"
4161 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4162 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4163 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4164 "a=rtpmap:111 opus/48000/2\r\n"
4165 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4166 "generation 2\r\n";
4167
4168 JsepSessionDescription jdesc_output(kDummyType);
4169 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4170 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4171 ASSERT_NE(nullptr, candidates);
4172 ASSERT_EQ(1U, candidates->count());
4173 cricket::Candidate c = candidates->at(0)->candidate();
4174 EXPECT_EQ("ufrag_voice", c.username());
4175 EXPECT_EQ("pwd_voice", c.password());
4176}
4177
deadbeef90f1e1e2017-02-10 12:35:05 -08004178// Test that SDP with an invalid port number in "a=candidate" lines is
4179// rejected, without crashing.
4180// Regression test for:
4181// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4182TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4183 static const char kSdpWithInvalidCandidatePort[] =
4184 "v=0\r\n"
4185 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4186 "s=-\r\n"
4187 "t=0 0\r\n"
4188 "m=audio 9 RTP/SAVPF 111\r\n"
4189 "c=IN IP4 0.0.0.0\r\n"
4190 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4191 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4192 "a=rtpmap:111 opus/48000/2\r\n"
4193 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4194 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4195
Steve Antona3a92c22017-12-07 10:27:41 -08004196 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004197 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4198}
deadbeefa4549d62017-02-10 17:26:22 -08004199
4200// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4201// Regression test for:
4202// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4203TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4204 static const char kSdpWithMissingTrackId[] =
4205 "v=0\r\n"
4206 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4207 "s=-\r\n"
4208 "t=0 0\r\n"
4209 "m=audio 9 RTP/SAVPF 111\r\n"
4210 "c=IN IP4 0.0.0.0\r\n"
4211 "a=rtpmap:111 opus/48000/2\r\n"
4212 "a=msid:stream_id \r\n";
4213
Steve Antona3a92c22017-12-07 10:27:41 -08004214 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004215 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4216}
4217
4218TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4219 static const char kSdpWithMissingStreamId[] =
4220 "v=0\r\n"
4221 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4222 "s=-\r\n"
4223 "t=0 0\r\n"
4224 "m=audio 9 RTP/SAVPF 111\r\n"
4225 "c=IN IP4 0.0.0.0\r\n"
4226 "a=rtpmap:111 opus/48000/2\r\n"
4227 "a=msid: track_id\r\n";
4228
Steve Antona3a92c22017-12-07 10:27:41 -08004229 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004230 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4231}
zhihuang38989e52017-03-21 11:04:53 -07004232
4233// Tests that if both session-level address and media-level address exist, use
4234// the media-level address.
4235TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004236 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004237
4238 // Sesssion-level address.
4239 std::string sdp = kSdpFullString;
4240 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4241 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4242
4243 const auto& content1 = jsep_desc.description()->contents()[0];
4244 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004245 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004246 const auto& content2 = jsep_desc.description()->contents()[1];
4247 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004248 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004249}
4250
4251// Tests that the session-level connection address will be used if the media
4252// level-addresses are not specified.
4253TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004254 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004255
4256 // Sesssion-level address.
4257 std::string sdp = kSdpString;
4258 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4259 // Remove the media level addresses.
4260 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4261 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4262 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4263
4264 const auto& content1 = jsep_desc.description()->contents()[0];
4265 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004266 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004267 const auto& content2 = jsep_desc.description()->contents()[1];
4268 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004269 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004270}
4271
4272TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004273 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004274
4275 std::string sdp = kSdpString;
4276 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4277 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4278 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4279 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4280 &sdp);
4281 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4282 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4283 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4284 &sdp);
4285 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4286 const auto& content1 = jsep_desc.description()->contents()[0];
4287 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004288 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004289 const auto& content2 = jsep_desc.description()->contents()[1];
4290 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004291 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004292}
4293
Qingsi Wang56991422019-02-08 12:53:06 -08004294// Test that a c= line that contains a hostname connection address can be
4295// parsed.
4296TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4297 JsepSessionDescription jsep_desc(kDummyType);
4298 std::string sdp = kSdpString;
4299 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4300
4301 sdp = kSdpString;
4302 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4303 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4304 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4305
4306 ASSERT_NE(nullptr, jsep_desc.description());
4307 const auto& content1 = jsep_desc.description()->contents()[0];
4308 EXPECT_EQ("example.local:9",
4309 content1.media_description()->connection_address().ToString());
4310 const auto& content2 = jsep_desc.description()->contents()[1];
4311 EXPECT_EQ("example.local:9",
4312 content2.media_description()->connection_address().ToString());
4313}
4314
4315// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004316TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004317 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004318 std::string sdp = kSdpString;
4319 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4320
4321 // Unsupported multicast IPv4 address.
4322 sdp = kSdpFullString;
4323 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4324 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4325
4326 // Unsupported multicast IPv6 address.
4327 sdp = kSdpFullString;
4328 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4329 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4330
4331 // Mismatched address type.
4332 sdp = kSdpFullString;
4333 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4334 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4335
4336 sdp = kSdpFullString;
4337 Replace("c=IN IP4 74.125.224.39\r\n",
4338 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4339 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4340}
4341
4342TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004343 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004344 MakeDescriptionWithoutCandidates(&expected_jsep);
4345 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004346 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004347 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004348 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004349 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004350 auto audio_desc = jdesc.description()
4351 ->GetContentByName(kAudioContentName)
4352 ->media_description();
4353 auto video_desc = jdesc.description()
4354 ->GetContentByName(kVideoContentName)
4355 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004356 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4357 audio_desc->connection_address().ToString());
4358 EXPECT_EQ(video_desc_->connection_address().ToString(),
4359 video_desc->connection_address().ToString());
4360}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004361
4362// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4363// used (i.e., a single space as the session name)." So we should accept that.
4364TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4365 JsepSessionDescription jsep_desc(kDummyType);
4366 std::string sdp = kSdpString;
4367 Replace("s=-\r\n", "s= \r\n", &sdp);
4368 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4369}
Amit Hilbucha2012042018-12-03 11:35:05 -08004370
4371// Simulcast malformed input test for invalid format.
4372TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004373 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4374 "a=simulcast:\r\n", "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004375}
4376
4377// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4378TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
Artem Titovf0a34f22020-03-16 17:52:04 +00004379 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4380 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4381 "a=simulcast:");
Amit Hilbucha2012042018-12-03 11:35:05 -08004382}
4383
4384// Validates that deserialization uses the a=simulcast: attribute
4385TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004386 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4387 sdp += "a=rid:1 send\r\n";
4388 sdp += "a=rid:2 send\r\n";
4389 sdp += "a=rid:3 send\r\n";
4390 sdp += "a=rid:4 recv\r\n";
4391 sdp += "a=rid:5 recv\r\n";
4392 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004393 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4394 JsepSessionDescription output(kDummyType);
4395 SdpParseError error;
4396 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4397 const cricket::ContentInfos& contents = output.description()->contents();
4398 const cricket::MediaContentDescription* media =
4399 contents.back().media_description();
4400 EXPECT_TRUE(media->HasSimulcast());
4401 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4402 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004403 EXPECT_FALSE(media->streams().empty());
4404 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4405 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004406}
4407
4408// Validates that deserialization removes rids that do not appear in SDP
4409TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4410 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4411 sdp += "a=rid:1 send\r\n";
4412 sdp += "a=rid:3 send\r\n";
4413 sdp += "a=rid:4 recv\r\n";
4414 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4415 JsepSessionDescription output(kDummyType);
4416 SdpParseError error;
4417 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4418 const cricket::ContentInfos& contents = output.description()->contents();
4419 const cricket::MediaContentDescription* media =
4420 contents.back().media_description();
4421 EXPECT_TRUE(media->HasSimulcast());
4422 const SimulcastDescription& simulcast = media->simulcast_description();
4423 EXPECT_EQ(2ul, simulcast.send_layers().size());
4424 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4425
4426 std::vector<SimulcastLayer> all_send_layers =
4427 simulcast.send_layers().GetAllLayers();
4428 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004429 EXPECT_EQ(0,
4430 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4431 return layer.rid == "2";
4432 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004433
4434 std::vector<SimulcastLayer> all_receive_layers =
4435 simulcast.receive_layers().GetAllLayers();
4436 ASSERT_EQ(1ul, all_receive_layers.size());
4437 EXPECT_EQ("4", all_receive_layers[0].rid);
4438
4439 EXPECT_FALSE(media->streams().empty());
4440 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4441 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004442}
4443
4444// Validates that Simulcast removes rids that appear in both send and receive.
4445TEST_F(WebRtcSdpTest,
4446 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4447 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4448 sdp += "a=rid:1 send\r\n";
4449 sdp += "a=rid:2 send\r\n";
4450 sdp += "a=rid:3 send\r\n";
4451 sdp += "a=rid:4 recv\r\n";
4452 sdp += "a=simulcast:send 1;2;3 recv 2;4\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_TRUE(media->HasSimulcast());
4460 const SimulcastDescription& simulcast = media->simulcast_description();
4461 EXPECT_EQ(2ul, simulcast.send_layers().size());
4462 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4463 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4464 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4465
4466 EXPECT_FALSE(media->streams().empty());
4467 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4468 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004469}
4470
4471// Ignores empty rid line.
4472TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4473 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4474 sdp += "a=rid:1 send\r\n";
4475 sdp += "a=rid:2 send\r\n";
4476 sdp += "a=rid\r\n"; // Should ignore this line.
4477 sdp += "a=rid:\r\n"; // Should ignore this line.
4478 sdp += "a=simulcast:send 1;2\r\n";
4479 JsepSessionDescription output(kDummyType);
4480 SdpParseError error;
4481 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4482 const cricket::ContentInfos& contents = output.description()->contents();
4483 const cricket::MediaContentDescription* media =
4484 contents.back().media_description();
4485 EXPECT_TRUE(media->HasSimulcast());
4486 const SimulcastDescription& simulcast = media->simulcast_description();
4487 EXPECT_TRUE(simulcast.receive_layers().empty());
4488 EXPECT_EQ(2ul, simulcast.send_layers().size());
4489 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4490
4491 EXPECT_FALSE(media->streams().empty());
4492 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4493 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004494}
4495
4496// Ignores malformed rid lines.
4497TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4498 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4499 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4500 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4501 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4502 sdp += "a=rid:4\r\n"; // Should ignore this line.
4503 sdp += "a=rid:5 send\r\n";
4504 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4505 JsepSessionDescription output(kDummyType);
4506 SdpParseError error;
4507 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4508 const cricket::ContentInfos& contents = output.description()->contents();
4509 const cricket::MediaContentDescription* media =
4510 contents.back().media_description();
4511 EXPECT_TRUE(media->HasSimulcast());
4512 const SimulcastDescription& simulcast = media->simulcast_description();
4513 EXPECT_TRUE(simulcast.receive_layers().empty());
4514 EXPECT_EQ(1ul, simulcast.send_layers().size());
4515 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4516
4517 EXPECT_FALSE(media->streams().empty());
4518 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4519 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004520}
4521
4522// Removes RIDs that specify a different format than the m= section.
4523TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4524 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4525 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4526 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4527 sdp += "a=simulcast:send 1;2\r\n";
4528 JsepSessionDescription output(kDummyType);
4529 SdpParseError error;
4530 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4531 const cricket::ContentInfos& contents = output.description()->contents();
4532 const cricket::MediaContentDescription* media =
4533 contents.back().media_description();
4534 EXPECT_TRUE(media->HasSimulcast());
4535 const SimulcastDescription& simulcast = media->simulcast_description();
4536 EXPECT_TRUE(simulcast.receive_layers().empty());
4537 EXPECT_EQ(1ul, simulcast.send_layers().size());
4538 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4539 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4540 EXPECT_EQ(1ul, media->streams().size());
4541 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4542 EXPECT_EQ(1ul, rids.size());
4543 EXPECT_EQ("1", rids[0].rid);
4544 EXPECT_EQ(1ul, rids[0].payload_types.size());
4545 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004546}
4547
4548// Ignores duplicate rid lines
4549TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4550 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4551 sdp += "a=rid:1 send\r\n";
4552 sdp += "a=rid:2 send\r\n";
4553 sdp += "a=rid:2 send\r\n";
4554 sdp += "a=rid:3 send\r\n";
4555 sdp += "a=rid:4 recv\r\n";
4556 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4557 JsepSessionDescription output(kDummyType);
4558 SdpParseError error;
4559 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4560 const cricket::ContentInfos& contents = output.description()->contents();
4561 const cricket::MediaContentDescription* media =
4562 contents.back().media_description();
4563 EXPECT_TRUE(media->HasSimulcast());
4564 const SimulcastDescription& simulcast = media->simulcast_description();
4565 EXPECT_EQ(2ul, simulcast.send_layers().size());
4566 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4567 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4568 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4569
4570 EXPECT_FALSE(media->streams().empty());
4571 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4572 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004573}
4574
Florent Castellic4421972019-07-02 20:27:42 +02004575TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4576 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4577 sdp += "a=rid:1 recv\r\n";
4578 sdp += "a=rid:2 recv\r\n";
4579 sdp += "a=simulcast:send 1;2\r\n";
4580 JsepSessionDescription output(kDummyType);
4581 SdpParseError error;
4582 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4583 const cricket::ContentInfos& contents = output.description()->contents();
4584 const cricket::MediaContentDescription* media =
4585 contents.back().media_description();
4586 EXPECT_FALSE(media->HasSimulcast());
4587}
4588
4589TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4590 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4591 sdp += "a=rid:1 send\r\n";
4592 sdp += "a=rid:2 send\r\n";
4593 sdp += "a=simulcast:recv 1;2\r\n";
4594 JsepSessionDescription output(kDummyType);
4595 SdpParseError error;
4596 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4597 const cricket::ContentInfos& contents = output.description()->contents();
4598 const cricket::MediaContentDescription* media =
4599 contents.back().media_description();
4600 EXPECT_FALSE(media->HasSimulcast());
4601}
4602
4603TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4604 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4605 sdp += "a=rid:1 send\r\n";
4606 sdp += "a=rid:2 send\r\n";
4607 sdp += "a=rid:3 send\r\n";
4608 sdp += "a=rid:4 recv\r\n";
4609 sdp += "a=rid:5 recv\r\n";
4610 sdp += "a=rid:6 recv\r\n";
4611 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4612 JsepSessionDescription output(kDummyType);
4613 SdpParseError error;
4614 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4615 const cricket::ContentInfos& contents = output.description()->contents();
4616 const cricket::MediaContentDescription* media =
4617 contents.back().media_description();
4618 EXPECT_TRUE(media->HasSimulcast());
4619 const SimulcastDescription& simulcast = media->simulcast_description();
4620 EXPECT_EQ(2ul, simulcast.send_layers().size());
4621 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4622 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4623 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4624
4625 EXPECT_FALSE(media->streams().empty());
4626 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4627 CompareRidDescriptionIds(rids, {"1", "3"});
4628}
4629
Amit Hilbucha2012042018-12-03 11:35:05 -08004630// Simulcast serialization integration test.
4631// This test will serialize and deserialize the description and compare.
4632// More detailed tests for parsing simulcast can be found in
4633// unit tests for SdpSerializer.
4634TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004635 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004636 auto description = jdesc_.description();
4637 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004638 ASSERT_EQ(media->streams().size(), 1ul);
4639 StreamParams& send_stream = media->mutable_streams()[0];
4640 std::vector<RidDescription> send_rids;
4641 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4642 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4643 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4644 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4645 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004646 std::vector<RidDescription> receive_rids;
4647 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4648 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4649 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4650 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004651
Amit Hilbucha2012042018-12-03 11:35:05 -08004652 SimulcastDescription& simulcast = media->simulcast_description();
4653 simulcast.send_layers().AddLayerWithAlternatives(
4654 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4655 simulcast.send_layers().AddLayerWithAlternatives(
4656 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004657 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4658 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4659 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004660
Amit Hilbucha2012042018-12-03 11:35:05 -08004661 TestSerialize(jdesc_);
4662}
Steve Anton06817cd2018-12-18 15:55:30 -08004663
4664// Test that the content name is empty if the media section does not have an
4665// a=mid line.
4666TEST_F(WebRtcSdpTest, ParseNoMid) {
4667 std::string sdp = kSdpString;
4668 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4669 Replace("a=mid:video_content_name\r\n", "", &sdp);
4670
4671 JsepSessionDescription output(kDummyType);
4672 SdpParseError error;
4673 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4674
4675 EXPECT_THAT(output.description()->contents(),
4676 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4677 Field("name", &cricket::ContentInfo::name, "")));
4678}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004679
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004680TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4681 AddSctpDataChannel(false); // Don't use sctpmap
4682 JsepSessionDescription jsep_desc(kDummyType);
4683 MakeDescriptionWithoutCandidates(&jsep_desc);
4684 std::string message = webrtc::SdpSerialize(jsep_desc);
4685 EXPECT_NE(std::string::npos,
4686 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4687}
4688
4689TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4690 AddSctpDataChannel(false);
4691 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4692 cricket::kMediaProtocolUdpDtlsSctp,
4693 cricket::kMediaProtocolTcpDtlsSctp};
4694 for (const auto& protocol : protocols) {
4695 sctp_desc_->set_protocol(protocol);
4696 JsepSessionDescription jsep_desc(kDummyType);
4697 MakeDescriptionWithoutCandidates(&jsep_desc);
4698 std::string message = webrtc::SdpSerialize(jsep_desc);
4699 EXPECT_NE(std::string::npos, message.find(protocol));
4700 JsepSessionDescription jsep_output(kDummyType);
4701 SdpParseError error;
4702 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4703 }
4704}
Taylor Brandstetter4256df02020-02-18 14:05:07 -08004705
4706// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4707// attribute is mandatory, but we relax that restriction.
4708TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4709 std::string sdp_without_cname = kSdpFullString;
4710 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4711 JsepSessionDescription new_jdesc(kDummyType);
4712 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4713
4714 audio_desc_->mutable_streams()[0].cname = "";
4715 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4716 jdesc_.session_version()));
4717 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4718}