blob: 5fdf5f61aba084b28ecda84be648fec691b29a8a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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:369 */
10
Yves Gerey3e707812018-11-28 15:47:4911#include <stdio.h>
12#include <string.h>
Harald Alvestrand4d7160e2019-04-12 05:01:2913#include <algorithm>
Yves Gerey3e707812018-11-28 15:47:4914#include <cstdint>
15#include <map>
kwibergd1fe2812016-04-27 13:47:2916#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3617#include <string>
Yves Gerey3e707812018-11-28 15:47:4918#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:3619#include <vector>
20
Steve Anton64b626b2019-01-29 01:25:2621#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:0522#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 23:13:0923#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 15:47:4924#include "api/array_view.h"
Steve Anton10542f22019-01-11 17:11:0025#include "api/crypto_params.h"
26#include "api/jsep_session_description.h"
27#include "api/media_types.h"
28#include "api/rtp_parameters.h"
29#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 15:47:4930#include "media/base/codec.h"
Steve Anton10542f22019-01-11 17:11:0031#include "media/base/media_constants.h"
32#include "media/base/stream_params.h"
33#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 13:03:0534#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 17:11:0035#include "p2p/base/transport_description.h"
36#include "p2p/base/transport_info.h"
37#include "pc/media_session.h"
38#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3139#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0040#include "rtc_base/message_digest.h"
41#include "rtc_base/socket_address.h"
42#include "rtc_base/ssl_fingerprint.h"
43#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 23:55:3044#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4945#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 07:04:2846
ossu7bb87ee2017-01-23 12:56:2547#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 17:11:0048#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 12:56:2549#endif
Steve Anton10542f22019-01-11 17:11:0050#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:3651
52using cricket::AudioCodec;
53using cricket::AudioContentDescription;
54using cricket::Candidate;
Steve Anton06817cd2018-12-18 23:55:3055using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:3656using cricket::ContentInfo;
57using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:3658using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:3659using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
60using cricket::ICE_CANDIDATE_COMPONENT_RTP;
61using cricket::kFecSsrcGroupSemantics;
62using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-21 00:34:0063using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 23:55:3064using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 23:30:1165using cricket::RidDescription;
66using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 11:36:1667using cricket::RtpDataContentDescription;
68using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 23:55:3069using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 19:35:0570using cricket::SimulcastDescription;
71using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:3672using cricket::StreamParams;
73using cricket::STUN_PORT_TYPE;
74using cricket::TransportDescription;
75using cricket::TransportInfo;
76using cricket::VideoCodec;
77using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 23:55:3078using ::testing::ElementsAre;
79using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:3680using webrtc::IceCandidateCollection;
81using webrtc::IceCandidateInterface;
82using webrtc::JsepIceCandidate;
83using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 18:24:5584using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 22:57:1085using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:3686using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 18:27:4187using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:3688using webrtc::SessionDescriptionInterface;
89
90typedef std::vector<AudioCodec> AudioCodecs;
91typedef std::vector<Candidate> Candidates;
92
Peter Boström0c4e06b2015-10-07 10:23:2193static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-18 03:48:3894static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:3695static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2196static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1497static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3698static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:1499static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36100static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:21101static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36102static const char kCandidateFoundation1[] = "a0+B/1";
103static const char kCandidateFoundation2[] = "a0+B/2";
104static const char kCandidateFoundation3[] = "a0+B/3";
105static const char kCandidateFoundation4[] = "a0+B/4";
106static const char kAttributeCryptoVoice[] =
107 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
108 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
109 "dummy_session_params\r\n";
110static const char kAttributeCryptoVideo[] =
111 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
112 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 13:03:05113static const char kFingerprint[] =
114 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36115 "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 20:33:20116static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36117static const int kExtmapId = 1;
118static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
119static const char kExtmap[] =
120 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
121static const char kExtmapWithDirectionAndAttribute[] =
122 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 19:31:36123static const char kExtmapWithDirectionAndAttributeEncrypted[] =
124 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
125 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36126
Peter Boström0c4e06b2015-10-07 10:23:21127static const uint8_t kIdentityDigest[] = {
128 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
129 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36130
lally@webrtc.org34807282015-02-24 20:19:39131static const char kDtlsSctp[] = "DTLS/SCTP";
132static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
133static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35134
henrike@webrtc.org28e20752013-07-10 00:45:36135struct CodecParams {
136 int max_ptime;
137 int ptime;
138 int min_ptime;
139 int sprop_stereo;
140 int stereo;
141 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59142 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36143};
144
deadbeef9d3584c2016-02-17 01:54:10145// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
146// instead of "a=crypto", and have an explicit test for adding "a=crypto".
147// Currently it's the other way around.
148
henrike@webrtc.org28e20752013-07-10 00:45:36149// Reference sdp string
150static const char kSdpFullString[] =
151 "v=0\r\n"
152 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
153 "s=-\r\n"
154 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10155 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36156 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
157 "c=IN IP4 74.125.127.126\r\n"
158 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
159 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
168 "raddr 192.168.1.5 rport 2346 "
169 "generation 2\r\n"
170 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
171 "raddr 192.168.1.5 rport 2348 "
172 "generation 2\r\n"
173 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
174 "a=mid:audio_content_name\r\n"
175 "a=sendrecv\r\n"
176 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51177 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36178 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
179 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
180 "dummy_session_params\r\n"
181 "a=rtpmap:111 opus/48000/2\r\n"
182 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41183 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36184 "a=ssrc:1 cname:stream_1_cname\r\n"
185 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
186 "a=ssrc:1 mslabel:local_stream_1\r\n"
187 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36188 "m=video 3457 RTP/SAVPF 120\r\n"
189 "c=IN IP4 74.125.224.39\r\n"
190 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
191 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
200 "generation 2\r\n"
201 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
202 "generation 2\r\n"
203 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
204 "a=mid:video_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
207 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
208 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10209 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36210 "a=ssrc:2 cname:stream_1_cname\r\n"
211 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
212 "a=ssrc:2 mslabel:local_stream_1\r\n"
213 "a=ssrc:2 label:video_track_id_1\r\n"
214 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10215 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36216 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10217 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36218
219// SDP reference string without the candidates.
220static const char kSdpString[] =
221 "v=0\r\n"
222 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
223 "s=-\r\n"
224 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10225 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22226 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06227 "c=IN IP4 0.0.0.0\r\n"
228 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36229 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
230 "a=mid:audio_content_name\r\n"
231 "a=sendrecv\r\n"
232 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51233 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36234 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
235 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
236 "dummy_session_params\r\n"
237 "a=rtpmap:111 opus/48000/2\r\n"
238 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41239 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36240 "a=ssrc:1 cname:stream_1_cname\r\n"
241 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
242 "a=ssrc:1 mslabel:local_stream_1\r\n"
243 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22244 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06245 "c=IN IP4 0.0.0.0\r\n"
246 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36247 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
248 "a=mid:video_content_name\r\n"
249 "a=sendrecv\r\n"
250 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
251 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
252 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10253 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36254 "a=ssrc:2 cname:stream_1_cname\r\n"
255 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
256 "a=ssrc:2 mslabel:local_stream_1\r\n"
257 "a=ssrc:2 label:video_track_id_1\r\n"
258 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10259 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36260 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10261 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36262
263static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22264 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
Harald Alvestrand5fc28b12019-05-13 11:36:16279// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36280static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38281 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06282 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36283 "a=ice-ufrag:ufrag_data\r\n"
284 "a=ice-pwd:pwd_data\r\n"
285 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33286 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36287
lally@webrtc.orgec97c652015-02-24 20:18:48288// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 08:41:24289// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
290// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56291static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38292 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26293 "a=sctp-port 5000\r\n"
294 "c=IN IP4 0.0.0.0\r\n"
295 "a=ice-ufrag:ufrag_data\r\n"
296 "a=ice-pwd:pwd_data\r\n"
297 "a=mid:data_content_name\r\n";
298
Harald Alvestrand48cce4d2019-04-11 08:41:24299// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 17:15:04300static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38301 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 17:15:04302 "a=sctp-port:5000\r\n"
303 "c=IN IP4 0.0.0.0\r\n"
304 "a=ice-ufrag:ufrag_data\r\n"
305 "a=ice-pwd:pwd_data\r\n"
306 "a=mid:data_content_name\r\n";
307
henrike@webrtc.org28e20752013-07-10 00:45:36308static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38309 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36310 "c=IN IP4 74.125.127.126\r\n"
311 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
312 "generation 2\r\n"
313 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
314 "generation 2\r\n"
315 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
316 "raddr 192.168.1.5 rport 2346 "
317 "generation 2\r\n"
318 "a=ice-ufrag:ufrag_data\r\n"
319 "a=ice-pwd:pwd_data\r\n"
320 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33321 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36322
jiayl@webrtc.org9c16c392014-05-01 18:30:30323static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04324 "v=0\r\n"
325 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
326 "s=-\r\n"
327 "t=0 0\r\n"
328 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22329 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06330 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04331 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06333 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04334 "a=x-google-flag:conference\r\n";
335
jiayl@webrtc.orge7d47a12014-08-05 19:19:05336static const char kSdpSessionString[] =
337 "v=0\r\n"
338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
339 "s=-\r\n"
340 "t=0 0\r\n"
341 "a=msid-semantic: WMS local_stream\r\n";
342
343static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22344 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06345 "c=IN IP4 0.0.0.0\r\n"
346 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05347 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
348 "a=mid:audio_content_name\r\n"
349 "a=sendrecv\r\n"
350 "a=rtpmap:111 opus/48000/2\r\n"
351 "a=ssrc:1 cname:stream_1_cname\r\n"
352 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
353 "a=ssrc:1 mslabel:local_stream\r\n"
354 "a=ssrc:1 label:audio_track_id_1\r\n";
355
356static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22357 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06358 "c=IN IP4 0.0.0.0\r\n"
359 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05360 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
361 "a=mid:video_content_name\r\n"
362 "a=sendrecv\r\n"
363 "a=rtpmap:120 VP8/90000\r\n"
364 "a=ssrc:2 cname:stream_1_cname\r\n"
365 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
366 "a=ssrc:2 mslabel:local_stream\r\n"
367 "a=ssrc:2 label:video_track_id_1\r\n";
368
deadbeef25ed4352016-12-13 02:37:36369// Reference sdp string using bundle-only.
370static const char kBundleOnlySdpFullString[] =
371 "v=0\r\n"
372 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
373 "s=-\r\n"
374 "t=0 0\r\n"
375 "a=group:BUNDLE audio_content_name video_content_name\r\n"
376 "a=msid-semantic: WMS local_stream_1\r\n"
377 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
378 "c=IN IP4 74.125.127.126\r\n"
379 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
380 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
381 "generation 2\r\n"
382 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
383 "generation 2\r\n"
384 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
385 "generation 2\r\n"
386 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
387 "generation 2\r\n"
388 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
389 "raddr 192.168.1.5 rport 2346 "
390 "generation 2\r\n"
391 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
392 "raddr 192.168.1.5 rport 2348 "
393 "generation 2\r\n"
394 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
395 "a=mid:audio_content_name\r\n"
396 "a=sendrecv\r\n"
397 "a=rtcp-mux\r\n"
398 "a=rtcp-rsize\r\n"
399 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
400 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
401 "dummy_session_params\r\n"
402 "a=rtpmap:111 opus/48000/2\r\n"
403 "a=rtpmap:103 ISAC/16000\r\n"
404 "a=rtpmap:104 ISAC/32000\r\n"
405 "a=ssrc:1 cname:stream_1_cname\r\n"
406 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
407 "a=ssrc:1 mslabel:local_stream_1\r\n"
408 "a=ssrc:1 label:audio_track_id_1\r\n"
409 "m=video 0 RTP/SAVPF 120\r\n"
410 "c=IN IP4 0.0.0.0\r\n"
411 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
412 "a=bundle-only\r\n"
413 "a=mid:video_content_name\r\n"
414 "a=sendrecv\r\n"
415 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
416 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
417 "a=rtpmap:120 VP8/90000\r\n"
418 "a=ssrc-group:FEC 2 3\r\n"
419 "a=ssrc:2 cname:stream_1_cname\r\n"
420 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
421 "a=ssrc:2 mslabel:local_stream_1\r\n"
422 "a=ssrc:2 label:video_track_id_1\r\n"
423 "a=ssrc:3 cname:stream_1_cname\r\n"
424 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
425 "a=ssrc:3 mslabel:local_stream_1\r\n"
426 "a=ssrc:3 label:video_track_id_1\r\n";
427
deadbeef9d3584c2016-02-17 01:54:10428// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
429// tracks.
430static const char kPlanBSdpFullString[] =
431 "v=0\r\n"
432 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
433 "s=-\r\n"
434 "t=0 0\r\n"
435 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
436 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
437 "c=IN IP4 74.125.127.126\r\n"
438 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
439 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
440 "generation 2\r\n"
441 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
442 "generation 2\r\n"
443 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
444 "generation 2\r\n"
445 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
446 "generation 2\r\n"
447 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
448 "raddr 192.168.1.5 rport 2346 "
449 "generation 2\r\n"
450 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
451 "raddr 192.168.1.5 rport 2348 "
452 "generation 2\r\n"
453 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
454 "a=mid:audio_content_name\r\n"
455 "a=sendrecv\r\n"
456 "a=rtcp-mux\r\n"
457 "a=rtcp-rsize\r\n"
458 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
459 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
460 "dummy_session_params\r\n"
461 "a=rtpmap:111 opus/48000/2\r\n"
462 "a=rtpmap:103 ISAC/16000\r\n"
463 "a=rtpmap:104 ISAC/32000\r\n"
464 "a=ssrc:1 cname:stream_1_cname\r\n"
465 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
466 "a=ssrc:1 mslabel:local_stream_1\r\n"
467 "a=ssrc:1 label:audio_track_id_1\r\n"
468 "a=ssrc:4 cname:stream_2_cname\r\n"
469 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
470 "a=ssrc:4 mslabel:local_stream_2\r\n"
471 "a=ssrc:4 label:audio_track_id_2\r\n"
472 "m=video 3457 RTP/SAVPF 120\r\n"
473 "c=IN IP4 74.125.224.39\r\n"
474 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
475 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
476 "generation 2\r\n"
477 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
478 "generation 2\r\n"
479 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
480 "generation 2\r\n"
481 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
482 "generation 2\r\n"
483 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
484 "generation 2\r\n"
485 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
486 "generation 2\r\n"
487 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
488 "a=mid:video_content_name\r\n"
489 "a=sendrecv\r\n"
490 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
491 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
492 "a=rtpmap:120 VP8/90000\r\n"
493 "a=ssrc-group:FEC 2 3\r\n"
494 "a=ssrc:2 cname:stream_1_cname\r\n"
495 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
496 "a=ssrc:2 mslabel:local_stream_1\r\n"
497 "a=ssrc:2 label:video_track_id_1\r\n"
498 "a=ssrc:3 cname:stream_1_cname\r\n"
499 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
500 "a=ssrc:3 mslabel:local_stream_1\r\n"
501 "a=ssrc:3 label:video_track_id_1\r\n"
502 "a=ssrc:5 cname:stream_2_cname\r\n"
503 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
504 "a=ssrc:5 mslabel:local_stream_2\r\n"
505 "a=ssrc:5 label:video_track_id_2\r\n"
506 "a=ssrc:6 cname:stream_2_cname\r\n"
507 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
508 "a=ssrc:6 mslabel:local_stream_2\r\n"
509 "a=ssrc:6 label:video_track_id_3\r\n";
510
511// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
512// tracks.
513static const char kUnifiedPlanSdpFullString[] =
514 "v=0\r\n"
515 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
516 "s=-\r\n"
517 "t=0 0\r\n"
518 "a=msid-semantic: WMS local_stream_1\r\n"
519 // Audio track 1, stream 1 (with candidates).
520 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
521 "c=IN IP4 74.125.127.126\r\n"
522 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
523 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
524 "generation 2\r\n"
525 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
526 "generation 2\r\n"
527 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
528 "generation 2\r\n"
529 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
532 "raddr 192.168.1.5 rport 2346 "
533 "generation 2\r\n"
534 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
535 "raddr 192.168.1.5 rport 2348 "
536 "generation 2\r\n"
537 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
538 "a=mid:audio_content_name\r\n"
539 "a=msid:local_stream_1 audio_track_id_1\r\n"
540 "a=sendrecv\r\n"
541 "a=rtcp-mux\r\n"
542 "a=rtcp-rsize\r\n"
543 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
544 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
545 "dummy_session_params\r\n"
546 "a=rtpmap:111 opus/48000/2\r\n"
547 "a=rtpmap:103 ISAC/16000\r\n"
548 "a=rtpmap:104 ISAC/32000\r\n"
549 "a=ssrc:1 cname:stream_1_cname\r\n"
550 // Video track 1, stream 1 (with candidates).
551 "m=video 3457 RTP/SAVPF 120\r\n"
552 "c=IN IP4 74.125.224.39\r\n"
553 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
554 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
555 "generation 2\r\n"
556 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
557 "generation 2\r\n"
558 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
559 "generation 2\r\n"
560 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
561 "generation 2\r\n"
562 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
563 "generation 2\r\n"
564 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
565 "generation 2\r\n"
566 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
567 "a=mid:video_content_name\r\n"
568 "a=msid:local_stream_1 video_track_id_1\r\n"
569 "a=sendrecv\r\n"
570 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
571 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
572 "a=rtpmap:120 VP8/90000\r\n"
573 "a=ssrc-group:FEC 2 3\r\n"
574 "a=ssrc:2 cname:stream_1_cname\r\n"
575 "a=ssrc:3 cname:stream_1_cname\r\n"
576 // Audio track 2, stream 2.
577 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
578 "c=IN IP4 0.0.0.0\r\n"
579 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
580 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
581 "a=mid:audio_content_name_2\r\n"
582 "a=msid:local_stream_2 audio_track_id_2\r\n"
583 "a=sendrecv\r\n"
584 "a=rtcp-mux\r\n"
585 "a=rtcp-rsize\r\n"
586 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
587 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
588 "dummy_session_params\r\n"
589 "a=rtpmap:111 opus/48000/2\r\n"
590 "a=rtpmap:103 ISAC/16000\r\n"
591 "a=rtpmap:104 ISAC/32000\r\n"
592 "a=ssrc:4 cname:stream_2_cname\r\n"
593 // Video track 2, stream 2.
594 "m=video 9 RTP/SAVPF 120\r\n"
595 "c=IN IP4 0.0.0.0\r\n"
596 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
597 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
598 "a=mid:video_content_name_2\r\n"
599 "a=msid:local_stream_2 video_track_id_2\r\n"
600 "a=sendrecv\r\n"
601 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
602 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
603 "a=rtpmap:120 VP8/90000\r\n"
604 "a=ssrc:5 cname:stream_2_cname\r\n"
605 // Video track 3, stream 2.
606 "m=video 9 RTP/SAVPF 120\r\n"
607 "c=IN IP4 0.0.0.0\r\n"
608 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
609 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
610 "a=mid:video_content_name_3\r\n"
611 "a=msid:local_stream_2 video_track_id_3\r\n"
612 "a=sendrecv\r\n"
613 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
614 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
615 "a=rtpmap:120 VP8/90000\r\n"
616 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36617
Seth Hampson5b4f0752018-04-02 23:31:36618// Unified Plan SDP reference string:
619// - audio track 1 has 1 a=msid lines
620// - audio track 2 has 2 a=msid lines
621// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
622// there are 0 media stream ids.
623// This Unified Plan SDP represents a SDP that signals the msid using both
624// a=msid and a=ssrc msid semantics.
625static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
626 "v=0\r\n"
627 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
628 "s=-\r\n"
629 "t=0 0\r\n"
630 "a=msid-semantic: WMS local_stream_1\r\n"
631 // Audio track 1, with 1 stream id.
632 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
633 "c=IN IP4 74.125.127.126\r\n"
634 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
635 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
636 "generation 2\r\n"
637 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
638 "generation 2\r\n"
639 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
640 "generation 2\r\n"
641 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
642 "generation 2\r\n"
643 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
644 "raddr 192.168.1.5 rport 2346 "
645 "generation 2\r\n"
646 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
647 "raddr 192.168.1.5 rport 2348 "
648 "generation 2\r\n"
649 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
650 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36651 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28652 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36653 "a=rtcp-mux\r\n"
654 "a=rtcp-rsize\r\n"
655 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
656 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
657 "dummy_session_params\r\n"
658 "a=rtpmap:111 opus/48000/2\r\n"
659 "a=rtpmap:103 ISAC/16000\r\n"
660 "a=rtpmap:104 ISAC/32000\r\n"
661 "a=ssrc:1 cname:stream_1_cname\r\n"
662 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
663 "a=ssrc:1 mslabel:local_stream_1\r\n"
664 "a=ssrc:1 label:audio_track_id_1\r\n"
665 // Audio track 2, with two stream ids.
666 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
667 "c=IN IP4 0.0.0.0\r\n"
668 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
669 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
670 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28671 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36672 "a=msid:local_stream_1 audio_track_id_2\r\n"
673 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36674 "a=rtcp-mux\r\n"
675 "a=rtcp-rsize\r\n"
676 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
677 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
678 "dummy_session_params\r\n"
679 "a=rtpmap:111 opus/48000/2\r\n"
680 "a=rtpmap:103 ISAC/16000\r\n"
681 "a=rtpmap:104 ISAC/32000\r\n"
682 "a=ssrc:4 cname:stream_1_cname\r\n"
683 // The support for Plan B msid signaling only includes the
684 // first media stream id "local_stream_1."
685 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
686 "a=ssrc:4 mslabel:local_stream_1\r\n"
687 "a=ssrc:4 label:audio_track_id_2\r\n"
688 // Audio track 3, with no stream ids.
689 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
690 "c=IN IP4 0.0.0.0\r\n"
691 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
692 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
693 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36694 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28695 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36696 "a=rtcp-mux\r\n"
697 "a=rtcp-rsize\r\n"
698 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
699 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
700 "dummy_session_params\r\n"
701 "a=rtpmap:111 opus/48000/2\r\n"
702 "a=rtpmap:103 ISAC/16000\r\n"
703 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28704 "a=ssrc:7 cname:stream_2_cname\r\n"
705 "a=ssrc:7 msid:- audio_track_id_3\r\n"
706 "a=ssrc:7 mslabel:-\r\n"
707 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 23:31:36708
Amit Hilbuchc57d5732018-12-11 23:30:11709// SDP string for unified plan without SSRCs
710static const char kUnifiedPlanSdpFullStringNoSsrc[] =
711 "v=0\r\n"
712 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
713 "s=-\r\n"
714 "t=0 0\r\n"
715 "a=msid-semantic: WMS local_stream_1\r\n"
716 // Audio track 1, stream 1 (with candidates).
717 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
718 "c=IN IP4 74.125.127.126\r\n"
719 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
720 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
721 "generation 2\r\n"
722 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
723 "generation 2\r\n"
724 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
725 "generation 2\r\n"
726 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
727 "generation 2\r\n"
728 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
729 "raddr 192.168.1.5 rport 2346 "
730 "generation 2\r\n"
731 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
732 "raddr 192.168.1.5 rport 2348 "
733 "generation 2\r\n"
734 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
735 "a=mid:audio_content_name\r\n"
736 "a=msid:local_stream_1 audio_track_id_1\r\n"
737 "a=sendrecv\r\n"
738 "a=rtcp-mux\r\n"
739 "a=rtcp-rsize\r\n"
740 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
741 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
742 "dummy_session_params\r\n"
743 "a=rtpmap:111 opus/48000/2\r\n"
744 "a=rtpmap:103 ISAC/16000\r\n"
745 "a=rtpmap:104 ISAC/32000\r\n"
746 // Video track 1, stream 1 (with candidates).
747 "m=video 3457 RTP/SAVPF 120\r\n"
748 "c=IN IP4 74.125.224.39\r\n"
749 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
750 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
751 "generation 2\r\n"
752 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
753 "generation 2\r\n"
754 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
755 "generation 2\r\n"
756 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
757 "generation 2\r\n"
758 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
759 "generation 2\r\n"
760 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
761 "generation 2\r\n"
762 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
763 "a=mid:video_content_name\r\n"
764 "a=msid:local_stream_1 video_track_id_1\r\n"
765 "a=sendrecv\r\n"
766 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
767 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
768 "a=rtpmap:120 VP8/90000\r\n"
769 // Audio track 2, stream 2.
770 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
771 "c=IN IP4 0.0.0.0\r\n"
772 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
773 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
774 "a=mid:audio_content_name_2\r\n"
775 "a=msid:local_stream_2 audio_track_id_2\r\n"
776 "a=sendrecv\r\n"
777 "a=rtcp-mux\r\n"
778 "a=rtcp-rsize\r\n"
779 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
780 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
781 "dummy_session_params\r\n"
782 "a=rtpmap:111 opus/48000/2\r\n"
783 "a=rtpmap:103 ISAC/16000\r\n"
784 "a=rtpmap:104 ISAC/32000\r\n"
785 // Video track 2, stream 2.
786 "m=video 9 RTP/SAVPF 120\r\n"
787 "c=IN IP4 0.0.0.0\r\n"
788 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
789 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
790 "a=mid:video_content_name_2\r\n"
791 "a=msid:local_stream_2 video_track_id_2\r\n"
792 "a=sendrecv\r\n"
793 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
794 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
795 "a=rtpmap:120 VP8/90000\r\n"
796 // Video track 3, stream 2.
797 "m=video 9 RTP/SAVPF 120\r\n"
798 "c=IN IP4 0.0.0.0\r\n"
799 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
800 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
801 "a=mid:video_content_name_3\r\n"
802 "a=msid:local_stream_2 video_track_id_3\r\n"
803 "a=sendrecv\r\n"
804 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
805 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
806 "a=rtpmap:120 VP8/90000\r\n";
807
henrike@webrtc.org28e20752013-07-10 00:45:36808// One candidate reference string as per W3c spec.
809// candidate:<blah> not a=candidate:<blah>CRLF
810static const char kRawCandidate[] =
811 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
812// One candidate reference string.
813static const char kSdpOneCandidate[] =
814 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
815 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15816
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20817static const char kSdpTcpActiveCandidate[] =
818 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
819 "tcptype active generation 2";
820static const char kSdpTcpPassiveCandidate[] =
821 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
822 "tcptype passive generation 2";
823static const char kSdpTcpSOCandidate[] =
824 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
825 "tcptype so generation 2";
826static const char kSdpTcpInvalidCandidate[] =
827 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
828 "tcptype invalid generation 2";
829
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15830// One candidate reference string with IPV6 address.
831static const char kRawIPV6Candidate[] =
832 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 19:04:36833 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36834
835// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23836static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36837 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23838 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36839
Zach Steinb336c272018-08-09 08:16:13840static const char kRawHostnameCandidate[] =
841 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
842
henrike@webrtc.org28e20752013-07-10 00:45:36843// Session id and version
844static const char kSessionId[] = "18446744069414584320";
845static const char kSessionVersion[] = "18446462598732840960";
846
deadbeef9d3584c2016-02-17 01:54:10847// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36848static const char kIceOption1[] = "iceoption1";
849static const char kIceOption2[] = "iceoption2";
850static const char kIceOption3[] = "iceoption3";
851
deadbeef9d3584c2016-02-17 01:54:10852// ICE ufrags/passwords.
853static const char kUfragVoice[] = "ufrag_voice";
854static const char kPwdVoice[] = "pwd_voice";
855static const char kUfragVideo[] = "ufrag_video";
856static const char kPwdVideo[] = "pwd_video";
857static const char kUfragData[] = "ufrag_data";
858static const char kPwdData[] = "pwd_data";
859
860// Extra ufrags/passwords for extra unified plan m= sections.
861static const char kUfragVoice2[] = "ufrag_voice_2";
862static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 23:31:36863static const char kUfragVoice3[] = "ufrag_voice_3";
864static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-17 01:54:10865static const char kUfragVideo2[] = "ufrag_video_2";
866static const char kPwdVideo2[] = "pwd_video_2";
867static const char kUfragVideo3[] = "ufrag_video_3";
868static const char kPwdVideo3[] = "pwd_video_3";
869
henrike@webrtc.org28e20752013-07-10 00:45:36870// Content name
871static const char kAudioContentName[] = "audio_content_name";
872static const char kVideoContentName[] = "video_content_name";
873static const char kDataContentName[] = "data_content_name";
874
deadbeef9d3584c2016-02-17 01:54:10875// Extra content names for extra unified plan m= sections.
876static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 23:31:36877static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-17 01:54:10878static const char kVideoContentName2[] = "video_content_name_2";
879static const char kVideoContentName3[] = "video_content_name_3";
880
henrike@webrtc.org28e20752013-07-10 00:45:36881// MediaStream 1
Seth Hampson845e8782018-03-02 19:34:10882static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36883static const char kStream1Cname[] = "stream_1_cname";
884static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21885static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36886static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10887static const uint32_t kVideoTrack1Ssrc1 = 2;
888static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36889
890// MediaStream 2
Seth Hampson845e8782018-03-02 19:34:10891static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36892static const char kStream2Cname[] = "stream_2_cname";
893static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21894static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10895static const char kVideoTrackId2[] = "video_track_id_2";
896static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36897static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10898static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 23:31:36899static const char kAudioTrackId3[] = "audio_track_id_3";
900static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36901
902// DataChannel
903static const char kDataChannelLabel[] = "data_channel";
904static const char kDataChannelMsid[] = "data_channeld0";
905static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 10:23:21906static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36907
908// Candidate
909static const char kDummyMid[] = "dummy_mid";
910static const int kDummyIndex = 123;
911
912// Misc
Steve Antona3a92c22017-12-07 18:27:41913static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36914
915// Helper functions
916
917static bool SdpDeserialize(const std::string& message,
918 JsepSessionDescription* jdesc) {
919 return webrtc::SdpDeserialize(message, jdesc, NULL);
920}
921
922static bool SdpDeserializeCandidate(const std::string& message,
923 JsepIceCandidate* candidate) {
924 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
925}
926
927// Add some extra |newlines| to the |message| after |line|.
928static void InjectAfter(const std::string& line,
929 const std::string& newlines,
930 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09931 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36932}
933
934static void Replace(const std::string& line,
935 const std::string& newlines,
936 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09937 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36938}
939
wu@webrtc.org5e760e72014-04-02 23:19:09940// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
941// message.
942static void ExpectParseFailure(const std::string& bad_sdp,
943 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 18:27:41944 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36945 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09946 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36947 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09948 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
949}
950
951// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
952static void ExpectParseFailure(const char* good_part, const char* bad_part) {
953 std::string bad_sdp = kSdpFullString;
954 Replace(good_part, bad_part, &bad_sdp);
955 ExpectParseFailure(bad_sdp, bad_part);
956}
957
958// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
959static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
960 const std::string& newlines,
961 const std::string& bad_part) {
962 std::string bad_sdp = kSdpFullString;
963 InjectAfter(injectpoint, newlines, &bad_sdp);
964 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36965}
966
Steve Anton4e70a722017-11-28 22:57:10967static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36968 std::string* message) {
969 std::string new_direction;
970 switch (direction) {
Steve Anton4e70a722017-11-28 22:57:10971 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36972 new_direction = "a=inactive";
973 break;
Steve Anton4e70a722017-11-28 22:57:10974 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36975 new_direction = "a=sendonly";
976 break;
Steve Anton4e70a722017-11-28 22:57:10977 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36978 new_direction = "a=recvonly";
979 break;
Steve Anton4e70a722017-11-28 22:57:10980 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36981 default:
982 new_direction = "a=sendrecv";
983 break;
984 }
985 Replace("a=sendrecv", new_direction, message);
986}
987
Yves Gerey665174f2018-06-19 13:03:05988static void ReplaceRejected(bool audio_rejected,
989 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36990 std::string* message) {
991 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14992 Replace("m=audio 9", "m=audio 0", message);
993 Replace(kAttributeIceUfragVoice, "", message);
994 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36995 }
996 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14997 Replace("m=video 9", "m=video 0", message);
998 Replace(kAttributeIceUfragVideo, "", message);
999 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:361000 }
1001}
1002
1003// WebRtcSdpTest
1004
Mirko Bonadei6a489f22019-04-09 13:11:121005class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:361006 public:
Steve Antona3a92c22017-12-07 18:27:411007 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 13:04:571008#ifdef WEBRTC_ANDROID
1009 webrtc::InitializeAndroidObjects();
1010#endif
henrike@webrtc.org28e20752013-07-10 00:45:361011 // AudioContentDescription
1012 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:101013 StreamParams audio_stream;
1014 audio_stream.id = kAudioTrackId1;
1015 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101016 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101017 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1018 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 18:04:531019 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1020 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 18:35:451021 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1022 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361023
1024 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:101025 video_desc_ = CreateVideoContentDescription();
1026 StreamParams video_stream;
1027 video_stream.id = kVideoTrackId1;
1028 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101029 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101030 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1031 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1032 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1033 video_stream.ssrc_groups.push_back(ssrc_group);
1034 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 18:04:531035 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1036 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 18:35:451037 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1038 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361039
1040 // TransportInfo
Steve Anton06817cd2018-12-18 23:55:301041 desc_.AddTransportInfo(TransportInfo(
1042 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1043 desc_.AddTransportInfo(TransportInfo(
1044 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:361045
1046 // v4 host
1047 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521048 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071049 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311050 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1051 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361052 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071053 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311054 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1055 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361056 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071057 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311058 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1059 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361060 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071061 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311062 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1063 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361064
1065 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521066 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071067 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1068 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311069 cricket::LOCAL_PORT_TYPE,
1070 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361071 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071072 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1073 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311074 cricket::LOCAL_PORT_TYPE,
1075 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361076 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071077 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1078 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311079 cricket::LOCAL_PORT_TYPE,
1080 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361081 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071082 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1083 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311084 cricket::LOCAL_PORT_TYPE,
1085 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361086
1087 // stun
1088 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521089 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1090 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071091 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1092 address_stun, kCandidatePriority, "", "",
1093 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311094 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361095 candidate9.set_related_address(rel_address_stun);
1096
1097 address_stun.SetPort(port_stun++);
1098 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071099 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1100 address_stun, kCandidatePriority, "", "",
1101 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311102 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361103 candidate10.set_related_address(rel_address_stun);
1104
1105 // relay
1106 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521107 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071108 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1109 address_relay, kCandidatePriority, "", "",
1110 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:311111 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361112 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071113 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1114 address_relay, kCandidatePriority, "", "",
1115 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311116 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361117
1118 // voice
1119 candidates_.push_back(candidate1);
1120 candidates_.push_back(candidate2);
1121 candidates_.push_back(candidate5);
1122 candidates_.push_back(candidate6);
1123 candidates_.push_back(candidate9);
1124 candidates_.push_back(candidate10);
1125
1126 // video
1127 candidates_.push_back(candidate3);
1128 candidates_.push_back(candidate4);
1129 candidates_.push_back(candidate7);
1130 candidates_.push_back(candidate8);
1131 candidates_.push_back(candidate11);
1132 candidates_.push_back(candidate12);
1133
Yves Gerey665174f2018-06-19 13:03:051134 jcandidate_.reset(
1135 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:361136
1137 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 05:01:291138 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:361139 std::string mline_id;
1140 int mline_index = 0;
Yves Gerey665174f2018-06-19 13:03:051141 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361142 // In this test, the audio m line index will be 0, and the video m line
1143 // will be 1.
1144 bool is_video = (i > 5);
1145 mline_id = is_video ? "video_content_name" : "audio_content_name";
1146 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 13:03:051147 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:361148 jdesc_.AddCandidate(&jice);
1149 }
1150 }
1151
Seth Hampson5b4f0752018-04-02 23:31:361152 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-13 02:37:361153 const IceCandidateCollection* video_candidates_collection =
1154 jdesc_.candidates(1);
1155 ASSERT_NE(nullptr, video_candidates_collection);
1156 std::vector<cricket::Candidate> video_candidates;
1157 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1158 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1159 c.set_transport_name("video_content_name");
1160 video_candidates.push_back(c);
1161 }
1162 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 23:31:361163 }
1164
1165 // Turns the existing reference description into a description using
1166 // a=bundle-only. This means no transport attributes and a 0 port value on
1167 // the m= sections not associated with the BUNDLE-tag.
1168 void MakeBundleOnlyDescription() {
1169 RemoveVideoCandidates();
deadbeef25ed4352016-12-13 02:37:361170
1171 // And the rest of the transport attributes.
1172 desc_.transport_infos()[1].description.ice_ufrag.clear();
1173 desc_.transport_infos()[1].description.ice_pwd.clear();
1174 desc_.transport_infos()[1].description.connection_role =
1175 cricket::CONNECTIONROLE_NONE;
1176
1177 // Set bundle-only flag.
1178 desc_.contents()[1].bundle_only = true;
1179
1180 // Add BUNDLE group.
1181 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1182 group.AddContentName(kAudioContentName);
1183 group.AddContentName(kVideoContentName);
1184 desc_.AddGroup(group);
1185
Harald Alvestrand4d7160e2019-04-12 05:01:291186 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-13 02:37:361187 jdesc_.session_version()));
1188 }
1189
deadbeef9d3584c2016-02-17 01:54:101190 // Turns the existing reference description into a plan B description,
1191 // with 2 audio tracks and 3 video tracks.
1192 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 23:14:301193 audio_desc_ = audio_desc_->Copy();
1194 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-17 01:54:101195
1196 StreamParams audio_track_2;
1197 audio_track_2.id = kAudioTrackId2;
1198 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101199 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101200 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1201 audio_desc_->AddStream(audio_track_2);
1202
1203 StreamParams video_track_2;
1204 video_track_2.id = kVideoTrackId2;
1205 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101206 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101207 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1208 video_desc_->AddStream(video_track_2);
1209
1210 StreamParams video_track_3;
1211 video_track_3.id = kVideoTrackId3;
1212 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101213 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101214 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1215 video_desc_->AddStream(video_track_3);
1216
1217 desc_.RemoveContentByName(kAudioContentName);
1218 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451219 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1220 absl::WrapUnique(audio_desc_));
1221 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1222 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101223
Harald Alvestrand4d7160e2019-04-12 05:01:291224 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101225 jdesc_.session_version()));
1226 }
1227
1228 // Turns the existing reference description into a unified plan description,
1229 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 23:30:111230 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-17 01:54:101231 // Audio track 2.
1232 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1233 StreamParams audio_track_2;
1234 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 19:34:101235 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111236 if (use_ssrcs) {
1237 audio_track_2.cname = kStream2Cname;
1238 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1239 }
deadbeef9d3584c2016-02-17 01:54:101240 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451241 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1242 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301243 desc_.AddTransportInfo(TransportInfo(
1244 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-17 01:54:101245 // Video track 2, in stream 2.
1246 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1247 StreamParams video_track_2;
1248 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 19:34:101249 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111250 if (use_ssrcs) {
1251 video_track_2.cname = kStream2Cname;
1252 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1253 }
deadbeef9d3584c2016-02-17 01:54:101254 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451255 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1256 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 23:55:301257 desc_.AddTransportInfo(TransportInfo(
1258 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-17 01:54:101259
1260 // Video track 3, in stream 2.
1261 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1262 StreamParams video_track_3;
1263 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 19:34:101264 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111265 if (use_ssrcs) {
1266 video_track_3.cname = kStream2Cname;
1267 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1268 }
deadbeef9d3584c2016-02-17 01:54:101269 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451270 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1271 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 23:55:301272 desc_.AddTransportInfo(TransportInfo(
1273 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 20:22:161274 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-17 01:54:101275
Harald Alvestrand4d7160e2019-04-12 05:01:291276 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101277 jdesc_.session_version()));
1278 }
1279
1280 // Creates an audio content description with no streams, and some default
1281 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361282 AudioContentDescription* CreateAudioContentDescription() {
1283 AudioContentDescription* audio = new AudioContentDescription();
1284 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511285 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 13:03:051286 audio->AddCrypto(CryptoParams(
1287 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:361288 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1289 "dummy_session_params"));
1290 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 17:07:161291 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-17 01:54:101292 audio->AddCodec(opus);
ossue1405ad2017-01-23 16:55:481293 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1294 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361295 return audio;
1296 }
1297
Seth Hampson5b4f0752018-04-02 23:31:361298 // Turns the existing reference description into a unified plan description,
1299 // with 3 audio MediaContentDescriptions with special StreamParams that
1300 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1301 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 17:25:281302 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 23:31:361303 desc_.RemoveContentByName(kVideoContentName);
1304 desc_.RemoveTransportInfoByName(kVideoContentName);
1305 RemoveVideoCandidates();
1306
1307 // Audio track 2 has 2 media stream ids.
1308 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1309 StreamParams audio_track_2;
1310 audio_track_2.id = kAudioTrackId2;
1311 audio_track_2.cname = kStream1Cname;
1312 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1313 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1314 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451315 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1316 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301317 desc_.AddTransportInfo(TransportInfo(
1318 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 23:31:361319
1320 // Audio track 3 has no stream ids.
1321 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1322 StreamParams audio_track_3;
1323 audio_track_3.id = kAudioTrackId3;
1324 audio_track_3.cname = kStream2Cname;
1325 audio_track_3.set_stream_ids({});
1326 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1327 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451328 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1329 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 23:55:301330 desc_.AddTransportInfo(TransportInfo(
1331 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 17:25:281332 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 05:01:291333 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 23:31:361334 jdesc_.session_version()));
1335 }
1336
Seth Hampson5897a6e2018-04-03 18:16:331337 // Turns the existing reference description into a unified plan description
1338 // with one audio MediaContentDescription that contains one StreamParams with
1339 // 0 ssrcs.
1340 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1341 desc_.RemoveContentByName(kVideoContentName);
1342 desc_.RemoveContentByName(kAudioContentName);
1343 desc_.RemoveTransportInfoByName(kVideoContentName);
1344 RemoveVideoCandidates();
1345
1346 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1347 StreamParams audio_track;
1348 audio_track.id = kAudioTrackId1;
1349 audio_track.set_stream_ids({kStreamId1});
1350 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 18:35:451351 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1352 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 18:16:331353
1354 // Enable signaling a=msid lines.
1355 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 05:01:291356 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 18:16:331357 jdesc_.session_version()));
1358 }
1359
deadbeef9d3584c2016-02-17 01:54:101360 // Creates a video content description with no streams, and some default
1361 // configuration.
1362 VideoContentDescription* CreateVideoContentDescription() {
1363 VideoContentDescription* video = new VideoContentDescription();
1364 video->AddCrypto(CryptoParams(
1365 1, "AES_CM_128_HMAC_SHA1_80",
1366 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1367 video->set_protocol(cricket::kMediaProtocolSavpf);
1368 video->AddCodec(
perkj26752742016-10-24 08:21:161369 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-17 01:54:101370 return video;
1371 }
1372
henrike@webrtc.org28e20752013-07-10 00:45:361373 template <class MCD>
Yves Gerey665174f2018-06-19 13:03:051374 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:361375 // type
Harald Alvestrand1716d392019-06-03 18:35:451376 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:361377
1378 // content direction
1379 EXPECT_EQ(cd1->direction(), cd2->direction());
1380
1381 // rtcp_mux
1382 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1383
deadbeef13871492015-12-09 20:37:511384 // rtcp_reduced_size
1385 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1386
henrike@webrtc.org28e20752013-07-10 00:45:361387 // cryptos
1388 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1389 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1390 ADD_FAILURE();
1391 return;
1392 }
Yves Gerey665174f2018-06-19 13:03:051393 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361394 const CryptoParams c1 = cd1->cryptos().at(i);
1395 const CryptoParams c2 = cd2->cryptos().at(i);
1396 EXPECT_TRUE(c1.Matches(c2));
1397 EXPECT_EQ(c1.key_params, c2.key_params);
1398 EXPECT_EQ(c1.session_params, c2.session_params);
1399 }
lally@webrtc.orgd7b61652015-02-24 20:18:551400
henrike@webrtc.org28e20752013-07-10 00:45:361401 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551402 // Use an equivalence class here, for old and new versions of the
1403 // protocol description.
Yves Gerey665174f2018-06-19 13:03:051404 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1405 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1406 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:351407 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 13:03:051408 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1409 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1410 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:351411 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551412 } else {
1413 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1414 }
henrike@webrtc.org28e20752013-07-10 00:45:361415
1416 // codecs
1417 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1418
1419 // bandwidth
1420 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1421
1422 // streams
1423 EXPECT_EQ(cd1->streams(), cd2->streams());
1424
Johannes Kron0854eb62018-10-10 20:33:201425 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 08:17:391426 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 20:33:201427
henrike@webrtc.org28e20752013-07-10 00:45:361428 // extmap
1429 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1430 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 13:03:051431 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 18:24:551432 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1433 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:361434 EXPECT_EQ(ext1.uri, ext2.uri);
1435 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 19:31:361436 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:361437 }
henrike@webrtc.org28e20752013-07-10 00:45:361438 }
1439
Amit Hilbuchc57d5732018-12-11 23:30:111440 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1441 const std::vector<std::string>& ids) {
1442 // Order of elements does not matter, only equivalence of sets.
1443 EXPECT_EQ(rids.size(), ids.size());
1444 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-29 01:25:261445 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1446 return rid.rid == id;
1447 }));
Amit Hilbuchc57d5732018-12-11 23:30:111448 }
1449 }
1450
Amit Hilbucha2012042018-12-03 19:35:051451 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1452 const SimulcastDescription& simulcast2) {
1453 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1454 EXPECT_EQ(simulcast1.receive_layers().size(),
1455 simulcast2.receive_layers().size());
1456 }
1457
Harald Alvestrand5fc28b12019-05-13 11:36:161458 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1459 const RtpDataContentDescription* dcd2) {
1460 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1461 }
1462
1463 void CompareSctpDataContentDescription(
1464 const SctpDataContentDescription* dcd1,
1465 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:171466 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 11:36:161467 EXPECT_EQ(dcd1->port(), dcd2->port());
1468 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:171469 }
1470
henrike@webrtc.org28e20752013-07-10 00:45:361471 void CompareSessionDescription(const SessionDescription& desc1,
1472 const SessionDescription& desc2) {
1473 // Compare content descriptions.
1474 if (desc1.contents().size() != desc2.contents().size()) {
1475 ADD_FAILURE();
1476 return;
1477 }
Yves Gerey665174f2018-06-19 13:03:051478 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361479 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1480 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-13 02:37:361481 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:361482 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-13 02:37:361483 EXPECT_EQ(c1.type, c2.type);
1484 EXPECT_EQ(c1.rejected, c2.rejected);
1485 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:361486
1487 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1488 if (IsAudioContent(&c1)) {
1489 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 23:14:301490 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361491 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 23:14:301492 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361493 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1494 }
1495
1496 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1497 if (IsVideoContent(&c1)) {
1498 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 23:14:301499 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361500 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 23:14:301501 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361502 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1503 }
1504
1505 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 11:36:161506 if (c1.media_description()->as_sctp()) {
1507 ASSERT_TRUE(c2.media_description()->as_sctp());
1508 const SctpDataContentDescription* scd1 =
1509 c1.media_description()->as_sctp();
1510 const SctpDataContentDescription* scd2 =
1511 c2.media_description()->as_sctp();
1512 CompareSctpDataContentDescription(scd1, scd2);
1513 } else {
1514 if (IsDataContent(&c1)) {
1515 const RtpDataContentDescription* dcd1 =
1516 c1.media_description()->as_rtp_data();
1517 const RtpDataContentDescription* dcd2 =
1518 c2.media_description()->as_rtp_data();
1519 CompareRtpDataContentDescription(dcd1, dcd2);
1520 }
henrike@webrtc.org28e20752013-07-10 00:45:361521 }
Amit Hilbucha2012042018-12-03 19:35:051522
1523 CompareSimulcastDescription(
1524 c1.media_description()->simulcast_description(),
1525 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:361526 }
1527
1528 // group
1529 const cricket::ContentGroups groups1 = desc1.groups();
1530 const cricket::ContentGroups groups2 = desc2.groups();
1531 EXPECT_EQ(groups1.size(), groups1.size());
1532 if (groups1.size() != groups2.size()) {
1533 ADD_FAILURE();
1534 return;
1535 }
1536 for (size_t i = 0; i < groups1.size(); ++i) {
1537 const cricket::ContentGroup group1 = groups1.at(i);
1538 const cricket::ContentGroup group2 = groups2.at(i);
1539 EXPECT_EQ(group1.semantics(), group2.semantics());
1540 const cricket::ContentNames names1 = group1.content_names();
1541 const cricket::ContentNames names2 = group2.content_names();
1542 EXPECT_EQ(names1.size(), names2.size());
1543 if (names1.size() != names2.size()) {
1544 ADD_FAILURE();
1545 return;
1546 }
1547 cricket::ContentNames::const_iterator iter1 = names1.begin();
1548 cricket::ContentNames::const_iterator iter2 = names2.begin();
1549 while (iter1 != names1.end()) {
1550 EXPECT_EQ(*iter1++, *iter2++);
1551 }
1552 }
1553
1554 // transport info
1555 const cricket::TransportInfos transports1 = desc1.transport_infos();
1556 const cricket::TransportInfos transports2 = desc2.transport_infos();
1557 EXPECT_EQ(transports1.size(), transports2.size());
1558 if (transports1.size() != transports2.size()) {
1559 ADD_FAILURE();
1560 return;
1561 }
1562 for (size_t i = 0; i < transports1.size(); ++i) {
1563 const cricket::TransportInfo transport1 = transports1.at(i);
1564 const cricket::TransportInfo transport2 = transports2.at(i);
1565 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361566 EXPECT_EQ(transport1.description.ice_ufrag,
1567 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 13:03:051568 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 18:37:281569 EXPECT_EQ(transport1.description.ice_mode,
1570 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:361571 if (transport1.description.identity_fingerprint) {
1572 EXPECT_EQ(*transport1.description.identity_fingerprint,
1573 *transport2.description.identity_fingerprint);
1574 } else {
1575 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1576 transport2.description.identity_fingerprint.get());
1577 }
1578 EXPECT_EQ(transport1.description.transport_options,
1579 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:361580 }
deadbeefc80741f2015-10-22 20:14:451581
1582 // global attributes
1583 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 08:17:391584 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:361585 }
1586
Yves Gerey665174f2018-06-19 13:03:051587 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1588 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:361589 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1590 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1591 CompareSessionDescription(*desc1.description(), *desc2.description());
1592 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1593 return false;
1594 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1595 const IceCandidateCollection* cc1 = desc1.candidates(i);
1596 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-13 02:37:361597 if (cc1->count() != cc2->count()) {
1598 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:361599 return false;
deadbeef25ed4352016-12-13 02:37:361600 }
henrike@webrtc.org28e20752013-07-10 00:45:361601 for (size_t j = 0; j < cc1->count(); ++j) {
1602 const IceCandidateInterface* c1 = cc1->at(j);
1603 const IceCandidateInterface* c2 = cc2->at(j);
1604 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1605 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1606 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1607 }
1608 }
1609 return true;
1610 }
1611
1612 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1613 // them with invalid keywords so that the parser will just ignore them.
1614 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 23:13:091615 absl::StrReplaceAll(
1616 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:361617 return true;
1618 }
1619
1620 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 13:03:051621 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1622 int mline_index,
1623 const std::string& ufrag,
1624 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:361625 std::string content_name;
1626 if (mline_index == 0) {
1627 content_name = kAudioContentName;
1628 } else if (mline_index == 1) {
1629 content_name = kVideoContentName;
1630 } else {
nissec80e7412017-01-11 13:56:461631 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:361632 }
Yves Gerey665174f2018-06-19 13:03:051633 TransportInfo transport_info(content_name,
1634 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361635 SessionDescription* desc =
1636 const_cast<SessionDescription*>(jdesc->description());
1637 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 23:55:301638 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:361639 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1640 const IceCandidateCollection* cc = jdesc_.candidates(i);
1641 for (size_t j = 0; j < cc->count(); ++j) {
1642 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 13:03:051643 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1644 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:361645 }
1646 }
1647 }
1648 return true;
1649 }
1650
1651 void AddIceOptions(const std::string& content_name,
1652 const std::vector<std::string>& transport_options) {
1653 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1654 cricket::TransportInfo transport_info =
1655 *(desc_.GetTransportInfoByName(content_name));
1656 desc_.RemoveTransportInfoByName(content_name);
1657 transport_info.description.transport_options = transport_options;
1658 desc_.AddTransportInfo(transport_info);
1659 }
1660
deadbeef3f7219b2015-12-28 23:17:141661 void SetIceUfragPwd(const std::string& content_name,
1662 const std::string& ice_ufrag,
1663 const std::string& ice_pwd) {
1664 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1665 cricket::TransportInfo transport_info =
1666 *(desc_.GetTransportInfoByName(content_name));
1667 desc_.RemoveTransportInfoByName(content_name);
1668 transport_info.description.ice_ufrag = ice_ufrag;
1669 transport_info.description.ice_pwd = ice_pwd;
1670 desc_.AddTransportInfo(transport_info);
1671 }
1672
henrike@webrtc.org28e20752013-07-10 00:45:361673 void AddFingerprint() {
1674 desc_.RemoveTransportInfoByName(kAudioContentName);
1675 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-16 02:27:441676 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 23:55:301677 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371678 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101679 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1680 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301681 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1682 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371683 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101684 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1685 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301686 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:361687 }
1688
jbauch5869f502017-06-29 19:31:361689 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 23:14:301690 audio_desc_ = audio_desc_->Copy();
1691 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 19:31:361692 audio_desc_->AddRtpHeaderExtension(
1693 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1694 video_desc_->AddRtpHeaderExtension(
1695 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:361696 desc_.RemoveContentByName(kAudioContentName);
1697 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451698 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1699 absl::WrapUnique(audio_desc_));
1700 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1701 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361702 }
1703
1704 void RemoveCryptos() {
1705 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1706 video_desc_->set_cryptos(std::vector<CryptoParams>());
1707 }
1708
Seth Hampson5897a6e2018-04-03 18:16:331709 // Removes everything in StreamParams from the session description that is
1710 // used for a=ssrc lines.
1711 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 18:35:451712 for (cricket::ContentInfo& content_info :
1713 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 18:16:331714 // With Unified Plan there should be one StreamParams per m= section.
1715 StreamParams& stream =
1716 content_info.media_description()->mutable_streams()[0];
1717 stream.ssrcs.clear();
1718 stream.ssrc_groups.clear();
1719 stream.cname.clear();
1720 }
1721 }
1722
Seth Hampson7fa6ee62018-10-17 17:25:281723 // Removes all a=ssrc lines from the SDP string, except for the
1724 // "a=ssrc:... cname:..." lines.
1725 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1726 const char kAttributeSsrc[] = "a=ssrc";
1727 const char kAttributeCname[] = "cname";
1728 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1729 while (ssrc_line_pos != std::string::npos) {
1730 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1731 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1732 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1733 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1734 // Only erase a=ssrc lines that don't contain "cname".
1735 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1736 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1737 } else {
1738 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1739 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1740 }
1741 }
1742 }
1743
Seth Hampson5897a6e2018-04-03 18:16:331744 // Removes all a=ssrc lines from the SDP string.
1745 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1746 const char kAttributeSsrc[] = "a=ssrc";
1747 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1748 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1749 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1750 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1751 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1752 }
1753 }
1754
Steve Anton4e70a722017-11-28 22:57:101755 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361756 audio_desc_->set_direction(direction);
1757 video_desc_->set_direction(direction);
1758 std::string new_sdp = kSdpFullString;
1759 ReplaceDirection(direction, &new_sdp);
1760
Harald Alvestrand4d7160e2019-04-12 05:01:291761 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361762 jdesc_.session_version())) {
1763 return false;
1764 }
Steve Antone831b8c2018-02-01 20:22:161765 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:361766 EXPECT_EQ(new_sdp, message);
1767 return true;
1768 }
1769
1770 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 23:14:301771 audio_desc_ = audio_desc_->Copy();
1772 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 18:04:531773
henrike@webrtc.org28e20752013-07-10 00:45:361774 desc_.RemoveContentByName(kAudioContentName);
1775 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001776 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451777 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001778 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451779 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101780 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1781 audio_rejected ? "" : kPwdVoice);
1782 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1783 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141784
1785 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361786 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1787
Steve Antona3a92c22017-12-07 18:27:411788 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:531789 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:161790 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:361791 EXPECT_EQ(new_sdp, message);
1792 return true;
1793 }
1794
zstein4b2e0822017-02-18 03:48:381795 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 11:36:161796 std::unique_ptr<SctpDataContentDescription> data(
1797 new SctpDataContentDescription());
1798 sctp_desc_ = data.get();
1799 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:381800 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 11:36:161801 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-21 00:34:001802 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 18:35:451803 std::move(data));
Steve Anton06817cd2018-12-18 23:55:301804 desc_.AddTransportInfo(TransportInfo(
1805 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:361806 }
1807
1808 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 11:36:161809 std::unique_ptr<RtpDataContentDescription> data(
1810 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361811 data_desc_ = data.get();
1812
deadbeef67cf2c12016-04-13 17:07:161813 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:361814 StreamParams data_stream;
1815 data_stream.id = kDataChannelMsid;
1816 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 19:34:101817 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:361818 data_stream.ssrcs.push_back(kDataChannelSsrc);
1819 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 13:03:051820 data_desc_->AddCrypto(
1821 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1822 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:361823 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 18:35:451824 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1825 std::move(data));
Steve Anton06817cd2018-12-18 23:55:301826 desc_.AddTransportInfo(TransportInfo(
1827 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:361828 }
1829
Steve Anton4e70a722017-11-28 22:57:101830 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361831 std::string new_sdp = kSdpFullString;
1832 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411833 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361834
1835 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1836
1837 audio_desc_->set_direction(direction);
1838 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 05:01:291839 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361840 jdesc_.session_version())) {
1841 return false;
1842 }
1843 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1844 return true;
1845 }
1846
1847 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 23:17:141848 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361849 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411850 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361851 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141852
Steve Antonb1c1de12017-12-21 23:14:301853 audio_desc_ = audio_desc_->Copy();
1854 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:361855 desc_.RemoveContentByName(kAudioContentName);
1856 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001857 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451858 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001859 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451860 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101861 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1862 audio_rejected ? "" : kPwdVoice);
1863 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1864 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 18:27:411865 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:291866 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 23:17:141867 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361868 return false;
1869 }
deadbeef3f7219b2015-12-28 23:17:141870 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361871 return true;
1872 }
1873
Yves Gerey665174f2018-06-19 13:03:051874 void TestDeserializeExtmap(bool session_level,
1875 bool media_level,
1876 bool encrypted) {
jbauch5869f502017-06-29 19:31:361877 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:411878 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 05:01:291879 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361880 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 18:27:411881 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361882 std::string sdp_with_extmap = kSdpString;
1883 if (session_level) {
jbauch5869f502017-06-29 19:31:361884 InjectAfter(kSessionTime,
1885 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1886 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361887 &sdp_with_extmap);
1888 }
1889 if (media_level) {
jbauch5869f502017-06-29 19:31:361890 InjectAfter(kAttributeIcePwdVoice,
1891 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1892 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361893 &sdp_with_extmap);
jbauch5869f502017-06-29 19:31:361894 InjectAfter(kAttributeIcePwdVideo,
1895 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1896 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361897 &sdp_with_extmap);
1898 }
1899 // The extmap can't be present at the same time in both session level and
1900 // media level.
1901 if (session_level && media_level) {
1902 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:051903 EXPECT_FALSE(
1904 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:361905 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1906 } else {
1907 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1908 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1909 }
1910 }
1911
1912 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 13:03:051913 const std::string& name,
1914 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:361915 cricket::CodecParameterMap::const_iterator found = params.find(name);
1916 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 09:59:481917 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361918 }
1919
1920 void TestDeserializeCodecParams(const CodecParams& params,
1921 JsepSessionDescription* jdesc_output) {
1922 std::string sdp =
1923 "v=0\r\n"
1924 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1925 "s=-\r\n"
1926 "t=0 0\r\n"
1927 // Include semantics for WebRTC Media Streams since it is supported by
1928 // this parser, and will be added to the SDP when serializing a session
1929 // description.
1930 "a=msid-semantic: WMS\r\n"
1931 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411932 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361933 // Pltype 111 listed before 103 and 104 in the map.
1934 "a=rtpmap:111 opus/48000/2\r\n"
1935 // Pltype 103 listed before 104.
1936 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411937 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151938 "a=fmtp:111 0-15,66,70\r\n"
1939 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361940 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241941 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151942 << "; sprop-stereo=" << params.sprop_stereo
1943 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 16:21:231944 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361945 << "a=ptime:" << params.ptime << "\r\n"
1946 << "a=maxptime:" << params.max_ptime << "\r\n";
1947 sdp += os.str();
1948
stefan@webrtc.org85d27942014-06-09 12:51:391949 os.clear();
1950 os.str("");
1951 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221952 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:391953 << "a=rtpmap:99 VP8/90000\r\n"
1954 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:231955 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391956 sdp += os.str();
1957
henrike@webrtc.org28e20752013-07-10 00:45:361958 // Deserialize
1959 SdpParseError error;
1960 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1961
henrike@webrtc.org28e20752013-07-10 00:45:361962 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301963 GetFirstAudioContentDescription(jdesc_output->description());
1964 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361965 ASSERT_FALSE(acd->codecs().empty());
1966 cricket::AudioCodec opus = acd->codecs()[0];
1967 EXPECT_EQ("opus", opus.name);
1968 EXPECT_EQ(111, opus.id);
1969 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1970 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1971 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1972 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591973 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1974 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:361975 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1976 cricket::AudioCodec codec = acd->codecs()[i];
1977 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1978 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:361979 }
stefan@webrtc.org85d27942014-06-09 12:51:391980
stefan@webrtc.org85d27942014-06-09 12:51:391981 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:301982 GetFirstVideoContentDescription(jdesc_output->description());
1983 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:391984 ASSERT_FALSE(vcd->codecs().empty());
1985 cricket::VideoCodec vp8 = vcd->codecs()[0];
1986 EXPECT_EQ("VP8", vp8.name);
1987 EXPECT_EQ(99, vp8.id);
1988 cricket::VideoCodec rtx = vcd->codecs()[1];
1989 EXPECT_EQ("RTX", rtx.name);
1990 EXPECT_EQ(95, rtx.id);
1991 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:361992 }
1993
1994 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1995 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:461996 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:361997 "v=0\r\n"
1998 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1999 "s=-\r\n"
2000 "t=0 0\r\n"
2001 // Include semantics for WebRTC Media Streams since it is supported by
2002 // this parser, and will be added to the SDP when serializing a session
2003 // description.
2004 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:222005 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:462006 "a=rtpmap:111 opus/48000/2\r\n";
2007 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:362008 "m=video 3457 RTP/SAVPF 101\r\n"
2009 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 11:40:022010 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362011 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582012 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:462013 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362014 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:462015 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 13:03:052016 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:462017 os << sdp_video;
Yves Gerey665174f2018-06-19 13:03:052018 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:462019 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:362020 // Deserialize
2021 SdpParseError error;
2022 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:362023 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:302024 GetFirstAudioContentDescription(jdesc_output->description());
2025 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:362026 ASSERT_FALSE(acd->codecs().empty());
2027 cricket::AudioCodec opus = acd->codecs()[0];
2028 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 13:03:052029 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2030 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:362031
henrike@webrtc.org28e20752013-07-10 00:45:362032 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302033 GetFirstVideoContentDescription(jdesc_output->description());
2034 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:362035 ASSERT_FALSE(vcd->codecs().empty());
2036 cricket::VideoCodec vp8 = vcd->codecs()[0];
2037 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2038 vp8.name.c_str());
2039 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 13:03:052040 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 11:40:022041 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2042 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 13:03:052043 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2044 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2045 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2046 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2047 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2048 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2049 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:362050 }
2051
2052 // Two SDP messages can mean the same thing but be different strings, e.g.
2053 // some of the lines can be serialized in different order.
2054 // However, a deserialized description can be compared field by field and has
2055 // no order. If deserializer has already been tested, serializing then
2056 // deserializing and comparing JsepSessionDescription will test
2057 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 20:22:162058 void TestSerialize(const JsepSessionDescription& jdesc) {
2059 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 18:27:412060 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362061 SdpParseError error;
2062 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2063 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2064 }
2065
zhihuang38989e52017-03-21 18:04:532066 // Calling 'Initialize' with a copy of the inner SessionDescription will
2067 // create a copy of the JsepSessionDescription without candidates. The
2068 // 'connection address' field, previously set from the candidates, must also
2069 // be reset.
2070 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2071 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2072 rtc::SocketAddress video_addr("0.0.0.0", 9);
2073 audio_desc_->set_connection_address(audio_addr);
2074 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 05:01:292075 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 18:04:532076 }
2077
henrike@webrtc.org28e20752013-07-10 00:45:362078 protected:
2079 SessionDescription desc_;
2080 AudioContentDescription* audio_desc_;
2081 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 11:36:162082 RtpDataContentDescription* data_desc_;
2083 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:362084 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:292085 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:362086 JsepSessionDescription jdesc_;
2087};
2088
2089void TestMismatch(const std::string& string1, const std::string& string2) {
2090 int position = 0;
2091 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2092 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:492093 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:362094 break;
2095 }
2096 }
2097 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2098 << " character\n"
2099 << " 1: " << string1.substr(position, 20) << "\n"
2100 << " 2: " << string2.substr(position, 20) << "\n";
2101}
2102
henrike@webrtc.org28e20752013-07-10 00:45:362103TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2104 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 20:22:162105 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362106 TestMismatch(std::string(kSdpFullString), message);
2107}
2108
2109TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 18:27:412110 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 20:22:162111 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:362112}
2113
2114// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2115// the case in a DTLS offer.
2116TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2117 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412118 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532119 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162120 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362121
2122 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052123 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2124 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362125
2126 EXPECT_EQ(sdp_with_fingerprint, message);
2127}
2128
2129// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2130// be the case in a DTLS answer.
2131TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2132 AddFingerprint();
2133 RemoveCryptos();
Steve Antona3a92c22017-12-07 18:27:412134 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532135 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162136 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362137
2138 std::string sdp_with_fingerprint = kSdpString;
2139 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2140 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 13:03:052141 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2142 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362143
2144 EXPECT_EQ(sdp_with_fingerprint, message);
2145}
2146
2147TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2148 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412149 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:532150 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:162151 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:362152 EXPECT_EQ(std::string(kSdpString), message);
2153}
2154
2155TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2156 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2157 group.AddContentName(kAudioContentName);
2158 group.AddContentName(kVideoContentName);
2159 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 05:01:292160 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362161 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162162 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362163 std::string sdp_with_bundle = kSdpFullString;
2164 InjectAfter(kSessionTime,
2165 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2166 &sdp_with_bundle);
2167 EXPECT_EQ(sdp_with_bundle, message);
2168}
2169
2170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 23:14:302171 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362172 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302173 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362174 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:292175 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362176 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162177 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362178 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052179 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362180 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052181 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362182 &sdp_with_bandwidth);
2183 EXPECT_EQ(sdp_with_bandwidth, message);
2184}
2185
2186TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2187 std::vector<std::string> transport_options;
2188 transport_options.push_back(kIceOption1);
2189 transport_options.push_back(kIceOption3);
2190 AddIceOptions(kAudioContentName, transport_options);
2191 transport_options.clear();
2192 transport_options.push_back(kIceOption2);
2193 transport_options.push_back(kIceOption3);
2194 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292195 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362196 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162197 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362198 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052199 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362200 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052201 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362202 &sdp_with_ice_options);
2203 EXPECT_EQ(sdp_with_ice_options, message);
2204}
2205
2206TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102207 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362208}
2209
2210TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102211 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362212}
2213
2214TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102215 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362216}
2217
2218TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2219 EXPECT_TRUE(TestSerializeRejected(true, false));
2220}
2221
2222TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2223 EXPECT_TRUE(TestSerializeRejected(false, true));
2224}
2225
2226TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2227 EXPECT_TRUE(TestSerializeRejected(true, true));
2228}
2229
2230TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2231 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:412232 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362233
zhihuang38989e52017-03-21 18:04:532234 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162235 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:362236
2237 std::string expected_sdp = kSdpString;
2238 expected_sdp.append(kSdpRtpDataChannelString);
2239 EXPECT_EQ(expected_sdp, message);
2240}
2241
2242TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-18 03:48:382243 bool use_sctpmap = true;
2244 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412245 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362246
zhihuang38989e52017-03-21 18:04:532247 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162248 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:362249
2250 std::string expected_sdp = kSdpString;
2251 expected_sdp.append(kSdpSctpDataChannelString);
2252 EXPECT_EQ(message, expected_sdp);
2253}
2254
Harald Alvestrand5fc28b12019-05-13 11:36:162255void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2256 const SessionDescription& desc,
2257 int port) {
2258 // Take our pre-built session description and change the SCTP port.
2259 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2260 SctpDataContentDescription* dcdesc =
2261 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2262 dcdesc->set_port(port);
2263 ASSERT_TRUE(
2264 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2265}
2266
jiayl@webrtc.org9c16c392014-05-01 18:30:302267TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-18 03:48:382268 bool use_sctpmap = true;
2269 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412270 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:532271 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302272
2273 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 11:36:162274 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302275
Steve Antone831b8c2018-02-01 20:22:162276 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302277
2278 std::string expected_sdp = kSdpString;
2279 expected_sdp.append(kSdpSctpDataChannelString);
2280
Steve Anton1c9c9fc2019-02-14 23:13:092281 absl::StrReplaceAll(
2282 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2283 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:302284
2285 EXPECT_EQ(expected_sdp, message);
2286}
2287
wu@webrtc.orgcadf9042013-08-30 21:24:162288TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412289 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:162290 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 13:03:052291 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 18:04:532292 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162293 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:162294
2295 std::string expected_sdp = kSdpString;
2296 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 22:31:252297 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:062298 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 13:03:052299 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:582300 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:162301}
2302
Johannes Kron0854eb62018-10-10 20:33:202303TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392304 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202305 TestSerialize(jdesc_);
2306}
2307
2308TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2309 cricket::MediaContentDescription* video_desc =
2310 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2311 ASSERT_TRUE(video_desc);
2312 cricket::MediaContentDescription* audio_desc =
2313 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2314 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392315 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202316 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392317 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202318 cricket::MediaContentDescription::kMedia);
2319 TestSerialize(jdesc_);
2320}
2321
henrike@webrtc.org28e20752013-07-10 00:45:362322TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 19:31:362323 bool encrypted = false;
2324 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412325 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 18:04:532326 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 20:22:162327 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362328
2329 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052330 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2331 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362332
2333 EXPECT_EQ(sdp_with_extmap, message);
2334}
2335
jbauch5869f502017-06-29 19:31:362336TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2337 bool encrypted = true;
2338 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412339 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 13:03:052340 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 05:01:292341 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 20:22:162342 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 19:31:362343}
2344
henrike@webrtc.org28e20752013-07-10 00:45:362345TEST_F(WebRtcSdpTest, SerializeCandidates) {
2346 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102347 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232348
2349 Candidate candidate_with_ufrag(candidates_.front());
2350 candidate_with_ufrag.set_username("ABC");
2351 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2352 candidate_with_ufrag));
2353 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2354 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482355
2356 Candidate candidate_with_network_info(candidates_.front());
2357 candidate_with_network_info.set_network_id(1);
2358 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2359 candidate_with_network_info));
2360 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2361 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2362 candidate_with_network_info.set_network_cost(999);
2363 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2364 candidate_with_network_info));
2365 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2366 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2367 message);
henrike@webrtc.org28e20752013-07-10 00:45:362368}
2369
Zach Steinb336c272018-08-09 08:16:132370TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2371 rtc::SocketAddress address("a.test", 1234);
2372 cricket::Candidate candidate(
2373 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2374 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2375 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2376 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2377 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2378}
2379
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202380// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2381// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:552382TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072383 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312384 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2385 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2386 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202387 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292388 std::unique_ptr<IceCandidateInterface> jcandidate(
2389 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202390
2391 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2392 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2393}
2394
htaa6b99442016-04-12 17:29:172395TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 09:34:112396 cricket::VideoCodec h264_codec("H264");
2397 h264_codec.SetParam("profile-level-id", "42e01f");
2398 h264_codec.SetParam("level-asymmetry-allowed", "1");
2399 h264_codec.SetParam("packetization-mode", "1");
2400 video_desc_->AddCodec(h264_codec);
2401
Harald Alvestrand4d7160e2019-04-12 05:01:292402 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 17:29:172403
Steve Antone831b8c2018-02-01 20:22:162404 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 17:29:172405 size_t after_pt = message.find(" H264/90000");
2406 ASSERT_NE(after_pt, std::string::npos);
2407 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2408 ASSERT_NE(before_pt, std::string::npos);
2409 before_pt += strlen("a=rtpmap:");
2410 std::string pt = message.substr(before_pt, after_pt - before_pt);
2411 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2412 std::string to_find = "a=fmtp:" + pt + " ";
2413 size_t fmtp_pos = message.find(to_find);
2414 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 10:43:522415 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 17:29:172416 ASSERT_NE(std::string::npos, fmtp_endpos);
2417 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2418 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2419 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2420 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142421 // Check that there are no spaces after semicolons.
2422 // https://bugs.webrtc.org/5793
2423 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172424}
2425
henrike@webrtc.org28e20752013-07-10 00:45:362426TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 18:27:412427 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362428 // Deserialize
2429 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2430 // Verify
2431 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2432}
2433
wu@webrtc.orgcecfd182013-10-30 05:18:122434TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 18:27:412435 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:122436 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 13:03:052437 "v=0\r\n"
2438 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2439 "s=-\r\n"
2440 "t=0 0\r\n"
2441 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:122442 // Deserialize
2443 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2444 EXPECT_EQ(0u, jdesc.description()->contents().size());
2445}
2446
henrike@webrtc.org28e20752013-07-10 00:45:362447TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 18:27:412448 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362449 std::string sdp_without_carriage_return = kSdpFullString;
2450 Replace("\r\n", "\n", &sdp_without_carriage_return);
2451 // Deserialize
2452 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2453 // Verify
2454 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2455}
2456
2457TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2458 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412459 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292460 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 13:03:052461 kSessionVersion));
Steve Antona3a92c22017-12-07 18:27:412462 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362463 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2464 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2465}
2466
2467TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2468 static const char kSdpNoRtpmapString[] =
2469 "v=0\r\n"
2470 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2471 "s=-\r\n"
2472 "t=0 0\r\n"
2473 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2474 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412475 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362476 // The rtpmap line for static payload codec is optional.
2477 "a=rtpmap:18 G729/16000\r\n"
2478 "a=rtpmap:103 ISAC/16000\r\n";
2479
Steve Antona3a92c22017-12-07 18:27:412480 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362481 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2482 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302483 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:362484 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162485 // The codecs in the AudioContentDescription should be in the same order as
2486 // the payload types (<fmt>s) on the m= line.
2487 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2488 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 16:55:482489 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362490 EXPECT_EQ(ref_codecs, audio->codecs());
2491}
2492
henrike@webrtc.org704bf9e2014-02-27 17:52:042493TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2494 static const char kSdpNoRtpmapString[] =
2495 "v=0\r\n"
2496 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2497 "s=-\r\n"
2498 "t=0 0\r\n"
2499 "m=audio 49232 RTP/AVP 18 103\r\n"
2500 "a=fmtp:18 annexb=yes\r\n"
2501 "a=rtpmap:103 ISAC/16000\r\n";
2502
Steve Antona3a92c22017-12-07 18:27:412503 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:042504 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2505 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302506 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:042507
2508 cricket::AudioCodec g729 = audio->codecs()[0];
2509 EXPECT_EQ("G729", g729.name);
2510 EXPECT_EQ(8000, g729.clockrate);
2511 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 13:03:052512 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:042513 ASSERT_TRUE(found != g729.params.end());
2514 EXPECT_EQ(found->second, "yes");
2515
2516 cricket::AudioCodec isac = audio->codecs()[1];
2517 EXPECT_EQ("ISAC", isac.name);
2518 EXPECT_EQ(103, isac.id);
2519 EXPECT_EQ(16000, isac.clockrate);
2520}
2521
henrike@webrtc.org28e20752013-07-10 00:45:362522// Ensure that we can deserialize SDP with a=fingerprint properly.
2523TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2524 // Add a DTLS a=fingerprint attribute to our session description.
2525 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412526 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292527 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362528 jdesc_.session_version()));
2529
Steve Antona3a92c22017-12-07 18:27:412530 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362531 std::string sdp_with_fingerprint = kSdpString;
2532 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2533 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2534 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2535 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2536}
2537
2538TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 18:27:412539 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362540 std::string sdp_with_bundle = kSdpFullString;
2541 InjectAfter(kSessionTime,
2542 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2543 &sdp_with_bundle);
2544 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2545 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2546 group.AddContentName(kAudioContentName);
2547 group.AddContentName(kVideoContentName);
2548 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 05:01:292549 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362550 jdesc_.session_version()));
2551 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2552}
2553
2554TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412555 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362556 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052557 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362558 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052559 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362560 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052561 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 23:14:302562 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362563 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302564 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362565 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:292566 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362567 jdesc_.session_version()));
2568 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2569}
2570
2571TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 18:27:412572 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362573 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052574 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362575 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052576 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362577 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052578 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362579 &sdp_with_ice_options);
2580 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2581 std::vector<std::string> transport_options;
2582 transport_options.push_back(kIceOption3);
2583 transport_options.push_back(kIceOption1);
2584 AddIceOptions(kAudioContentName, transport_options);
2585 transport_options.clear();
2586 transport_options.push_back(kIceOption3);
2587 transport_options.push_back(kIceOption2);
2588 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292589 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362590 jdesc_.session_version()));
2591 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2592}
2593
2594TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2595 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 18:27:412596 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362597 std::string sdp_with_ufrag_pwd = kSdpFullString;
2598 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2599 // Add session level ufrag and pwd
2600 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 13:03:052601 "a=ice-pwd:session+level+icepwd\r\n"
2602 "a=ice-ufrag:session+level+iceufrag\r\n",
2603 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:362604 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 13:03:052605 InjectAfter(
2606 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362607 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2608 &sdp_with_ufrag_pwd);
2609 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 13:03:052610 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2611 "media+level+icepwd"));
2612 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2613 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:362614 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2615 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2616}
2617
henrike@webrtc.org28e20752013-07-10 00:45:362618TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102619 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362620}
2621
2622TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102623 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362624}
2625
2626TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102627 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362628}
2629
2630TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2631 EXPECT_TRUE(TestDeserializeRejected(true, false));
2632}
2633
2634TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2635 EXPECT_TRUE(TestDeserializeRejected(false, true));
2636}
2637
2638TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2639 EXPECT_TRUE(TestDeserializeRejected(true, true));
2640}
2641
2642// Tests that we can still handle the sdp uses mslabel and label instead of
2643// msid for backward compatibility.
2644TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 20:14:452645 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 18:27:412646 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362647 std::string sdp_without_msid = kSdpFullString;
2648 Replace("msid", "xmsid", &sdp_without_msid);
2649 // Deserialize
2650 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2651 // Verify
2652 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 10:25:052653 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2654 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:362655}
2656
Johannes Kron0854eb62018-10-10 20:33:202657TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392658 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202659 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2660 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2661 // Deserialize
2662 JsepSessionDescription jdesc_deserialized(kDummyType);
2663 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2664 // Verify
2665 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2666}
2667
2668TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392669 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 20:33:202670 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2671 // Deserialize
2672 JsepSessionDescription jdesc_deserialized(kDummyType);
2673 EXPECT_TRUE(
2674 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2675 // Verify
2676 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2677}
2678
2679TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2680 cricket::MediaContentDescription* video_desc =
2681 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2682 ASSERT_TRUE(video_desc);
2683 cricket::MediaContentDescription* audio_desc =
2684 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2685 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392686 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202687 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392688 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202689 cricket::MediaContentDescription::kMedia);
2690
2691 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2692 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2693 &sdp_with_extmap_allow_mixed);
2694 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2695 &sdp_with_extmap_allow_mixed);
2696
2697 // Deserialize
2698 JsepSessionDescription jdesc_deserialized(kDummyType);
2699 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2700 // Verify
2701 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2702}
2703
henrike@webrtc.org28e20752013-07-10 00:45:362704TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2705 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2706
2707 std::string sdp = kSdpOneCandidate;
2708 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2709 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2710 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2711 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482712 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362713
2714 // Candidate line without generation extension.
2715 sdp = kSdpOneCandidate;
2716 Replace(" generation 2", "", &sdp);
2717 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2718 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2719 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2720 Candidate expected = jcandidate_->candidate();
2721 expected.set_generation(0);
2722 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2723
honghaiza0c44ea2016-03-23 23:07:482724 // Candidate with network id and/or cost.
2725 sdp = kSdpOneCandidate;
2726 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2727 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2728 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2729 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2730 expected = jcandidate_->candidate();
2731 expected.set_network_id(2);
2732 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2733 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2734 // Add network cost
2735 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2736 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2737 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2738 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2739
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202740 sdp = kSdpTcpActiveCandidate;
2741 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2742 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072743 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312744 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2745 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2746 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292747 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2748 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 13:03:052749 EXPECT_TRUE(
2750 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202751 sdp = kSdpTcpPassiveCandidate;
2752 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2753 sdp = kSdpTcpSOCandidate;
2754 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362755}
2756
2757// This test verifies the deserialization of candidate-attribute
2758// as per RFC 5245. Candiate-attribute will be of the format
2759// candidate:<blah>. This format will be used when candidates
2760// are trickled.
2761TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2762 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2763
2764 std::string candidate_attribute = kRawCandidate;
2765 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2766 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2767 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2768 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2769 EXPECT_EQ(2u, jcandidate.candidate().generation());
2770
2771 // Candidate line without generation extension.
2772 candidate_attribute = kRawCandidate;
2773 Replace(" generation 2", "", &candidate_attribute);
2774 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2775 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2776 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2777 Candidate expected = jcandidate_->candidate();
2778 expected.set_generation(0);
2779 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2780
2781 // Candidate line without candidate:
2782 candidate_attribute = kRawCandidate;
2783 Replace("candidate:", "", &candidate_attribute);
2784 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2785
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152786 // Candidate line with IPV6 address.
2787 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 08:16:132788
2789 // Candidate line with hostname address.
2790 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152791}
2792
2793// This test verifies that the deserialization of an invalid candidate string
2794// fails.
2795TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 13:03:052796 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152797
2798 std::string candidate_attribute = kRawCandidate;
2799 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362800 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152801
2802 candidate_attribute = kSdpOneCandidate;
2803 candidate_attribute.replace(0, 1, "x");
2804 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2805
2806 candidate_attribute = kRawCandidate;
2807 candidate_attribute.append("\r\n");
2808 candidate_attribute.append(kRawCandidate);
2809 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2810
2811 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362812}
2813
2814TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2815 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:412816 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292817 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:362818
2819 std::string sdp_with_data = kSdpString;
2820 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412821 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362822
2823 // Deserialize
2824 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2825 // Verify
2826 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2827}
2828
2829TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-18 03:48:382830 bool use_sctpmap = true;
2831 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412832 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292833 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:362834
2835 std::string sdp_with_data = kSdpString;
2836 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412837 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362838
Guido Urdanetacecf87f2019-05-31 10:17:382839 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:352840 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2841 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2842
Guido Urdanetacecf87f2019-05-31 10:17:382843 // Verify with DTLS/SCTP.
2844 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2845 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:352846 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2847 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2848
2849 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:382850 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 13:03:052851 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362852 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2853 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2854}
2855
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562856TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-18 03:48:382857 bool use_sctpmap = false;
2858 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412859 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292860 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562861
2862 std::string sdp_with_data = kSdpString;
2863 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 18:27:412864 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562865
lally@webrtc.orgc7848b72015-02-24 20:19:262866 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2867 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2868}
2869
lally69f57602015-10-08 17:15:042870TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-18 03:48:382871 bool use_sctpmap = false;
2872 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412873 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292874 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 17:15:042875
2876 std::string sdp_with_data = kSdpString;
2877 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 18:27:412878 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 17:15:042879
lally69f57602015-10-08 17:15:042880 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2881 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2882}
2883
Harald Alvestrand48cce4d2019-04-11 08:41:242884// Helper function to set the max-message-size parameter in the
2885// SCTP data codec.
2886void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 11:36:162887 int new_value,
Harald Alvestrand48cce4d2019-04-11 08:41:242888 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 07:31:042889 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 11:36:162890 SctpDataContentDescription* dcdesc =
2891 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2892 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 07:31:042893 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 08:41:242894}
2895
2896TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2897 bool use_sctpmap = false;
2898 AddSctpDataChannel(use_sctpmap);
2899 JsepSessionDescription jdesc(kDummyType);
2900 std::string sdp_with_data = kSdpString;
2901
2902 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2903 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 11:36:162904 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 08:41:242905 JsepSessionDescription jdesc_output(kDummyType);
2906
Harald Alvestrand48cce4d2019-04-11 08:41:242907 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2908 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2909}
2910
Harald Alvestrandfbb45bd2019-05-15 06:07:472911TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2912 bool use_sctpmap = false;
2913 AddSctpDataChannel(use_sctpmap);
2914 JsepSessionDescription jdesc(kDummyType);
2915 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2916 std::string message = webrtc::SdpSerialize(jdesc);
2917 EXPECT_NE(std::string::npos,
2918 message.find("\r\na=max-message-size:12345\r\n"));
2919 JsepSessionDescription jdesc_output(kDummyType);
2920 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2921 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2922}
2923
2924TEST_F(WebRtcSdpTest,
2925 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2926 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2927 // The default max message size is 64K.
2928 bool use_sctpmap = false;
2929 AddSctpDataChannel(use_sctpmap);
2930 JsepSessionDescription jdesc(kDummyType);
2931 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2932 std::string message = webrtc::SdpSerialize(jdesc);
2933 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2934 JsepSessionDescription jdesc_output(kDummyType);
2935 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2936 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2937}
2938
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562939// Test to check the behaviour if sctp-port is specified
2940// on the m= line and in a=sctp-port.
2941TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-18 03:48:382942 bool use_sctpmap = true;
2943 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412944 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292945 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562946
2947 std::string sdp_with_data = kSdpString;
2948 // Append m= attributes
2949 sdp_with_data.append(kSdpSctpDataChannelString);
2950 // Append a=sctp-port attribute
2951 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 18:27:412952 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562953
2954 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2955}
2956
Harald Alvestrand5fc28b12019-05-13 11:36:162957// Test behavior if a=rtpmap occurs in an SCTP section.
2958TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2959 std::string sdp_with_data = kSdpString;
2960 // Append m= attributes
2961 sdp_with_data.append(kSdpSctpDataChannelString);
2962 // Append a=rtpmap attribute
2963 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2964 JsepSessionDescription jdesc_output(kDummyType);
2965 // Correct behavior is to ignore the extra attribute.
2966 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2967}
2968
2969TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
2970 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
2971 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
2972 for (auto proto : bad_strings) {
2973 std::string sdp_with_data = kSdpString;
2974 sdp_with_data.append("m=application 9 ");
2975 sdp_with_data.append(proto);
2976 sdp_with_data.append(" 47\r\n");
2977 JsepSessionDescription jdesc_output(kDummyType);
2978 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
2979 << "Parsing should have failed on " << proto;
2980 }
2981 // The following strings are strange, but acceptable as RTP.
2982 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
2983 "obviously-bogus/RTP/"};
2984 for (auto proto : weird_strings) {
2985 std::string sdp_with_data = kSdpString;
2986 sdp_with_data.append("m=application 9 ");
2987 sdp_with_data.append(proto);
2988 sdp_with_data.append(" 47\r\n");
2989 JsepSessionDescription jdesc_output(kDummyType);
2990 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
2991 << "Parsing should have succeeded on " << proto;
2992 }
2993}
2994
henrike@webrtc.org571df2d2014-02-19 23:04:262995// For crbug/344475.
2996TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2997 std::string sdp_with_data = kSdpString;
2998 sdp_with_data.append(kSdpSctpDataChannelString);
2999 // Remove the "\n" at the end.
3000 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 18:27:413001 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:263002
3003 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3004 // No crash is a pass.
3005}
3006
zstein4b2e0822017-02-18 03:48:383007TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3008 bool use_sctpmap = true;
3009 AddSctpDataChannel(use_sctpmap);
3010
3011 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 18:27:413012 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163013 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:023014
jiayl@webrtc.org9c16c392014-05-01 18:30:303015 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:023016 std::string sdp_with_data = kSdpString;
3017 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 23:13:093018 absl::StrReplaceAll(
3019 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3020 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413021 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:023022
3023 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3024 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-18 03:48:383025}
3026
3027TEST_F(WebRtcSdpTest,
3028 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3029 bool use_sctpmap = false;
3030 AddSctpDataChannel(use_sctpmap);
3031
Steve Antona3a92c22017-12-07 18:27:413032 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163033 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563034
3035 // We need to test the deserialized JsepSessionDescription from
3036 // kSdpSctpDataChannelStringWithSctpPort for
3037 // draft-ietf-mmusic-sctp-sdp-07
3038 // a=sctp-port
zstein4b2e0822017-02-18 03:48:383039 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563040 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 23:13:093041 absl::StrReplaceAll(
3042 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3043 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413044 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563045
3046 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3047 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:023048}
3049
wu@webrtc.orgcadf9042013-08-30 21:24:163050TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 22:31:253051 // We want to test that deserializing data content limits bandwidth
3052 // settings (it should never be greater than the default).
3053 // This should prevent someone from using unlimited data bandwidth through
3054 // JS and "breaking the Internet".
3055 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:163056 std::string sdp_with_bandwidth = kSdpString;
3057 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 13:03:053058 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:163059 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:413060 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:163061
Peter Thatcherc0c3a862015-06-24 22:31:253062 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3063}
3064
3065TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-18 03:48:383066 bool use_sctpmap = true;
3067 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:413068 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163069 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 22:31:253070 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:293071 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 22:31:253072
3073 std::string sdp_with_bandwidth = kSdpString;
3074 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 13:03:053075 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 22:31:253076 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:413077 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 22:31:253078
3079 // SCTP has congestion control, so we shouldn't limit the bandwidth
3080 // as we do for RTP.
3081 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:163082 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3083}
3084
Yves Gerey665174f2018-06-19 13:03:053085class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 13:11:123086 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 19:31:363087
3088TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 13:03:053089 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 19:31:363090 bool encrypted = GetParam();
3091 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363092}
3093
Yves Gerey665174f2018-06-19 13:03:053094TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 19:31:363095 bool encrypted = GetParam();
3096 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363097}
3098
Yves Gerey665174f2018-06-19 13:03:053099TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 19:31:363100 bool encrypted = GetParam();
3101 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363102}
3103
Mirko Bonadeic84f6612019-01-31 11:20:573104INSTANTIATE_TEST_SUITE_P(Encrypted,
3105 WebRtcSdpExtmapTest,
3106 ::testing::Values(false, true));
jbauch5869f502017-06-29 19:31:363107
sergeyu@chromium.org5bc25c42013-12-05 00:24:063108TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 18:27:413109 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:063110 std::string sdp = kSdpFullString;
3111 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3112 // Deserialize
3113 SdpParseError error;
3114 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-17 01:54:103115 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:063116 EXPECT_EQ(lastline, error.line);
3117 EXPECT_EQ("Invalid SDP line.", error.description);
3118}
3119
henrike@webrtc.org28e20752013-07-10 00:45:363120TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3121 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3122 std::string new_sdp = kSdpOneCandidate;
3123 Replace("udp", "unsupported_transport", &new_sdp);
3124 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3125 new_sdp = kSdpOneCandidate;
3126 Replace("udp", "uDP", &new_sdp);
3127 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3128 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3129 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3130 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3131}
3132
honghaiza54a0802015-12-17 02:37:233133TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:363134 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:233135 EXPECT_TRUE(
3136 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:363137 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3138 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3139 Candidate ref_candidate = jcandidate_->candidate();
3140 ref_candidate.set_username("user_rtp");
3141 ref_candidate.set_password("password_rtp");
3142 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3143}
3144
henrike@webrtc.org704bf9e2014-02-27 17:52:043145TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413146 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:043147
3148 // Deserialize
3149 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3150
3151 // Verify
3152 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303153 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043154 EXPECT_TRUE(audio->conference_mode());
3155
3156 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303157 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043158 EXPECT_TRUE(video->conference_mode());
3159}
3160
deadbeefd45aea82017-09-16 08:24:293161TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413162 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 08:24:293163
3164 // We tested deserialization already above, so just test that if we serialize
3165 // and deserialize the flag doesn't disappear.
3166 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 20:22:163167 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 08:24:293168 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3169
3170 // Verify.
3171 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303172 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293173 EXPECT_TRUE(audio->conference_mode());
3174
3175 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303176 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293177 EXPECT_TRUE(video->conference_mode());
3178}
3179
henrike@webrtc.org28e20752013-07-10 00:45:363180TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3181 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:513182 const char kSdpEmptyType[] = " =candidate";
3183 const char kSdpEqualAsPlus[] = "a+candidate";
3184 const char kSdpSpaceAfterEqual[] = "a= candidate";
3185 const char kSdpUpperType[] = "A=candidate";
3186 const char kSdpEmptyLine[] = "";
3187 const char kSdpMissingValue[] = "a=";
3188
Yves Gerey665174f2018-06-19 13:03:053189 const char kSdpBrokenFingerprint[] =
3190 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363191 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 13:03:053192 const char kSdpExtraField[] =
3193 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363194 "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 13:03:053195 const char kSdpMissingSpace[] =
3196 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:363197 "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:583198 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 13:03:053199 const char kSdpMd5[] =
3200 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:583201 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:363202
3203 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:093204 ExpectParseFailure("v=", kSdpDestroyer);
3205 ExpectParseFailure("o=", kSdpDestroyer);
3206 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363207 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:093208 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363209
3210 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:093211 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3212 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363213
3214 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:513215 ExpectParseFailure("a=candidate", kSdpEmptyType);
3216 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3217 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3218 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:363219
3220 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3221 // because it's orthogonal to what we are replacing and hence
3222 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:513223 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3224 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3225 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3226 ExpectParseFailure("a=sendrecv", kSdpMd5);
3227
3228 // Empty Line
3229 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3230 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:093231}
3232
3233TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3234 // ssrc
3235 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:103236 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:093237 // crypto
3238 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3239 // rtpmap
3240 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3241 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3242 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3243 // candidate
3244 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3245 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3246 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3247 ExpectParseFailure("rport 2346", "rport badvalue");
3248 ExpectParseFailure("rport 2346 generation 2",
3249 "rport 2346 generation badvalue");
3250 // m line
3251 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3252 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3253
3254 // bandwidth
3255 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 13:03:053256 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:093257 // rtcp-fb
3258 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3259 "a=rtcp-fb:badvalue nack\r\n",
3260 "a=rtcp-fb:badvalue nack");
3261 // extmap
3262 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3263 "a=extmap:badvalue http://example.com\r\n",
3264 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:363265}
3266
3267TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 18:27:413268 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363269
3270 const char kSdpWithReorderedPlTypesString[] =
3271 "v=0\r\n"
3272 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3273 "s=-\r\n"
3274 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:223275 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 13:03:053276 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3277 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:363278 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413279 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363280
3281 // Deserialize
3282 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3283
henrike@webrtc.org28e20752013-07-10 00:45:363284 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:303285 GetFirstAudioContentDescription(jdesc_output.description());
3286 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:363287 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413288 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3289 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:363290 EXPECT_EQ(104, acd->codecs()[0].id);
3291}
3292
3293TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 18:27:413294 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363295 CodecParams params;
3296 params.max_ptime = 40;
3297 params.ptime = 30;
3298 params.min_ptime = 10;
3299 params.sprop_stereo = 1;
3300 params.stereo = 1;
3301 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:593302 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:363303 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 20:22:163304 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363305}
3306
3307TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3308 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 18:27:413309 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363310 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163311 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363312}
3313
3314TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3315 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 18:27:413316 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363317 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163318 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363319}
3320
3321TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 18:27:413322 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363323
3324 const char kSdpWithFmtpString[] =
3325 "v=0\r\n"
3326 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3327 "s=-\r\n"
3328 "t=0 0\r\n"
3329 "m=video 3457 RTP/SAVPF 120\r\n"
3330 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:233331 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3332
3333 // Deserialize
3334 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:243335 EXPECT_TRUE(
3336 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:233337
Donald Curtis0e07f922015-05-15 16:21:233338 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303339 GetFirstVideoContentDescription(jdesc_output.description());
3340 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 16:21:233341 ASSERT_FALSE(vcd->codecs().empty());
3342 cricket::VideoCodec vp8 = vcd->codecs()[0];
3343 EXPECT_EQ("VP8", vp8.name);
3344 EXPECT_EQ(120, vp8.id);
3345 cricket::CodecParameterMap::iterator found =
3346 vp8.params.find("x-google-min-bitrate");
3347 ASSERT_TRUE(found != vp8.params.end());
3348 EXPECT_EQ(found->second, "10");
3349 found = vp8.params.find("x-google-max-quantization");
3350 ASSERT_TRUE(found != vp8.params.end());
3351 EXPECT_EQ(found->second, "40");
3352}
3353
johan2d8d23e2016-06-03 08:22:423354TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 18:27:413355 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 08:22:423356
3357 const char kSdpWithFmtpString[] =
3358 "v=0\r\n"
3359 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3360 "s=-\r\n"
3361 "t=0 0\r\n"
3362 "m=video 49170 RTP/AVP 98\r\n"
3363 "a=rtpmap:98 H264/90000\r\n"
3364 "a=fmtp:98 profile-level-id=42A01E; "
3365 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3366
3367 // Deserialize.
3368 SdpParseError error;
3369 EXPECT_TRUE(
3370 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3371
johan2d8d23e2016-06-03 08:22:423372 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303373 GetFirstVideoContentDescription(jdesc_output.description());
3374 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 08:22:423375 ASSERT_FALSE(vcd->codecs().empty());
3376 cricket::VideoCodec h264 = vcd->codecs()[0];
3377 EXPECT_EQ("H264", h264.name);
3378 EXPECT_EQ(98, h264.id);
3379 cricket::CodecParameterMap::const_iterator found =
3380 h264.params.find("profile-level-id");
3381 ASSERT_TRUE(found != h264.params.end());
3382 EXPECT_EQ(found->second, "42A01E");
3383 found = h264.params.find("sprop-parameter-sets");
3384 ASSERT_TRUE(found != h264.params.end());
3385 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3386}
3387
Donald Curtis0e07f922015-05-15 16:21:233388TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 18:27:413389 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 16:21:233390
3391 const char kSdpWithFmtpString[] =
3392 "v=0\r\n"
3393 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3394 "s=-\r\n"
3395 "t=0 0\r\n"
3396 "m=video 3457 RTP/SAVPF 120\r\n"
3397 "a=rtpmap:120 VP8/90000\r\n"
3398 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363399
3400 // Deserialize
3401 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:053402 EXPECT_TRUE(
3403 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:363404
henrike@webrtc.org28e20752013-07-10 00:45:363405 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303406 GetFirstVideoContentDescription(jdesc_output.description());
3407 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:363408 ASSERT_FALSE(vcd->codecs().empty());
3409 cricket::VideoCodec vp8 = vcd->codecs()[0];
3410 EXPECT_EQ("VP8", vp8.name);
3411 EXPECT_EQ(120, vp8.id);
3412 cricket::CodecParameterMap::iterator found =
3413 vp8.params.find("x-google-min-bitrate");
3414 ASSERT_TRUE(found != vp8.params.end());
3415 EXPECT_EQ(found->second, "10");
3416 found = vp8.params.find("x-google-max-quantization");
3417 ASSERT_TRUE(found != vp8.params.end());
3418 EXPECT_EQ(found->second, "40");
3419}
3420
Mirta Dvornicic479a3c02019-06-04 13:38:503421TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3422 JsepSessionDescription jdesc_output(kDummyType);
3423
3424 const char kSdpWithPacketizationString[] =
3425 "v=0\r\n"
3426 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3427 "s=-\r\n"
3428 "t=0 0\r\n"
3429 "m=audio 9 RTP/SAVPF 111\r\n"
3430 "a=rtpmap:111 opus/48000/2\r\n"
3431 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3432 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3433 "a=rtpmap:120 VP8/90000\r\n"
3434 "a=packetization:120 raw\r\n"
3435 "a=rtpmap:121 VP9/90000\r\n"
3436 "a=rtpmap:122 H264/90000\r\n"
3437 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3438
3439 SdpParseError error;
3440 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3441 &error));
3442
3443 AudioContentDescription* acd =
3444 GetFirstAudioContentDescription(jdesc_output.description());
3445 ASSERT_TRUE(acd);
3446 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3447 cricket::AudioCodec opus = acd->codecs()[0];
3448 EXPECT_EQ(opus.name, "opus");
3449 EXPECT_EQ(opus.id, 111);
3450
3451 const VideoContentDescription* vcd =
3452 GetFirstVideoContentDescription(jdesc_output.description());
3453 ASSERT_TRUE(vcd);
3454 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3455 cricket::VideoCodec vp8 = vcd->codecs()[0];
3456 EXPECT_EQ(vp8.name, "VP8");
3457 EXPECT_EQ(vp8.id, 120);
3458 EXPECT_EQ(vp8.packetization, "raw");
3459 cricket::VideoCodec vp9 = vcd->codecs()[1];
3460 EXPECT_EQ(vp9.name, "VP9");
3461 EXPECT_EQ(vp9.id, 121);
3462 EXPECT_EQ(vp9.packetization, absl::nullopt);
3463 cricket::VideoCodec h264 = vcd->codecs()[2];
3464 EXPECT_EQ(h264.name, "H264");
3465 EXPECT_EQ(h264.id, 122);
3466 EXPECT_EQ(h264.packetization, absl::nullopt);
3467}
3468
ossuaa4b0772017-01-30 15:41:183469TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 23:14:303470 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183471
3472 cricket::AudioCodecs codecs = acd->codecs();
3473 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3474 acd->set_codecs(codecs);
3475
Harald Alvestrand4d7160e2019-04-12 05:01:293476 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183477 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163478 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183479 std::string sdp_with_fmtp = kSdpFullString;
3480 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3481 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3482 &sdp_with_fmtp);
3483 EXPECT_EQ(sdp_with_fmtp, message);
3484}
3485
3486TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 23:14:303487 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183488
3489 cricket::AudioCodecs codecs = acd->codecs();
3490 codecs[0].params["stereo"] = "1";
3491 acd->set_codecs(codecs);
3492
Harald Alvestrand4d7160e2019-04-12 05:01:293493 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183494 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163495 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183496 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053497 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 15:41:183498 &sdp_with_fmtp);
3499 EXPECT_EQ(sdp_with_fmtp, message);
3500}
3501
3502TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 23:14:303503 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183504
3505 cricket::AudioCodecs codecs = acd->codecs();
3506 codecs[0].params["ptime"] = "20";
3507 codecs[0].params["maxptime"] = "120";
3508 acd->set_codecs(codecs);
3509
Harald Alvestrand4d7160e2019-04-12 05:01:293510 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183511 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163512 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183513 std::string sdp_with_fmtp = kSdpFullString;
3514 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3515 "a=maxptime:120\r\n" // No comma here. String merging!
3516 "a=ptime:20\r\n",
3517 &sdp_with_fmtp);
3518 EXPECT_EQ(sdp_with_fmtp, message);
3519}
3520
henrike@webrtc.org28e20752013-07-10 00:45:363521TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 23:14:303522 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:363523
3524 cricket::VideoCodecs codecs = vcd->codecs();
3525 codecs[0].params["x-google-min-bitrate"] = "10";
3526 vcd->set_codecs(codecs);
3527
Harald Alvestrand4d7160e2019-04-12 05:01:293528 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:363529 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163530 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:363531 std::string sdp_with_fmtp = kSdpFullString;
3532 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 13:03:053533 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:363534 EXPECT_EQ(sdp_with_fmtp, message);
3535}
3536
Mirta Dvornicic479a3c02019-06-04 13:38:503537TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3538 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3539
3540 cricket::VideoCodecs codecs = vcd->codecs();
3541 codecs[0].packetization = "raw";
3542 vcd->set_codecs(codecs);
3543
3544 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3545 jdesc_.session_version()));
3546 std::string message = webrtc::SdpSerialize(jdesc_);
3547 std::string sdp_with_packetization = kSdpFullString;
3548 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3549 &sdp_with_packetization);
3550 EXPECT_EQ(sdp_with_packetization, message);
3551}
3552
Taylor Brandstetter2f65ec52018-05-24 18:37:283553TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3554 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 18:27:413555 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363556 std::string sdp_with_icelite = kSdpFullString;
3557 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3558 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3559 const cricket::TransportInfo* tinfo1 =
3560 desc->GetTransportInfoByName("audio_content_name");
3561 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3562 const cricket::TransportInfo* tinfo2 =
3563 desc->GetTransportInfoByName("video_content_name");
3564 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283565
3566 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 13:03:053567 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363568 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3569 desc = jdesc_with_icelite.description();
3570 const cricket::TransportInfo* atinfo =
3571 desc->GetTransportInfoByName("audio_content_name");
3572 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3573 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053574 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:363575 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283576
3577 // Now that we know deserialization works, we can use TestSerialize to test
3578 // serialization.
3579 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363580}
3581
3582// Verifies that the candidates in the input SDP are parsed and serialized
3583// correctly in the output SDP.
3584TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3585 std::string sdp_with_data = kSdpString;
3586 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 18:27:413587 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363588
3589 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 20:22:163590 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:363591}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253592
3593TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3594 AddFingerprint();
3595 TransportInfo audio_transport_info =
3596 *(desc_.GetTransportInfoByName(kAudioContentName));
3597 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3598 audio_transport_info.description.connection_role);
3599 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053600 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253601
3602 TransportInfo video_transport_info =
3603 *(desc_.GetTransportInfoByName(kVideoContentName));
3604 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3605 video_transport_info.description.connection_role);
3606 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053607 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253608
3609 desc_.RemoveTransportInfoByName(kAudioContentName);
3610 desc_.RemoveTransportInfoByName(kVideoContentName);
3611
3612 desc_.AddTransportInfo(audio_transport_info);
3613 desc_.AddTransportInfo(video_transport_info);
3614
Harald Alvestrand4d7160e2019-04-12 05:01:293615 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:253616 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163617 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253618 std::string sdp_with_dtlssetup = kSdpFullString;
3619
3620 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 13:03:053621 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3622 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253623 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 13:03:053624 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253625 EXPECT_EQ(sdp_with_dtlssetup, message);
3626}
3627
3628TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 18:27:413629 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253630 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053631 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253632 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3633 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3634 const cricket::TransportInfo* atinfo =
3635 desc->GetTransportInfoByName("audio_content_name");
3636 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3637 atinfo->description.connection_role);
3638 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053639 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:253640 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3641 vtinfo->description.connection_role);
3642}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053643
3644// Verifies that the order of the serialized m-lines follows the order of the
3645// ContentInfo in SessionDescription, and vise versa for deserialization.
3646TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 18:27:413647 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 13:03:053648 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3649 kSdpSctpDataChannelString};
3650 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3651 cricket::MEDIA_TYPE_VIDEO,
3652 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:053653
3654 // Verifies all 6 permutations.
3655 for (size_t i = 0; i < 6; ++i) {
3656 size_t media_content_in_sdp[3];
3657 // The index of the first media content.
3658 media_content_in_sdp[0] = i / 2;
3659 // The index of the second media content.
3660 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3661 // The index of the third media content.
3662 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3663
3664 std::string sdp_string = kSdpSessionString;
3665 for (size_t i = 0; i < 3; ++i)
3666 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3667
3668 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3669 cricket::SessionDescription* desc = jdesc.description();
3670 EXPECT_EQ(3u, desc->contents().size());
3671
3672 for (size_t i = 0; i < 3; ++i) {
3673 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 23:14:303674 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:053675 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3676 }
3677
Steve Antone831b8c2018-02-01 20:22:163678 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053679 EXPECT_EQ(sdp_string, serialized_sdp);
3680 }
3681}
deadbeef9d3584c2016-02-17 01:54:103682
deadbeef25ed4352016-12-13 02:37:363683TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3684 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 18:27:413685 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473686 ASSERT_TRUE(
deadbeef25ed4352016-12-13 02:37:363687 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3688 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3689}
3690
deadbeef12771a12017-01-03 21:53:473691// The semantics of "a=bundle-only" are only defined when it's used in
3692// combination with a 0 port on the m= line. We should ignore it if used with a
3693// nonzero port.
3694TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3695 // Make the base bundle-only description but unset the bundle-only flag.
3696 MakeBundleOnlyDescription();
3697 jdesc_.description()->contents()[1].bundle_only = false;
3698
3699 std::string modified_sdp = kBundleOnlySdpFullString;
3700 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 18:27:413701 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473702 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3703 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-13 02:37:363704}
3705
3706TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3707 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 20:22:163708 TestSerialize(jdesc_);
deadbeef25ed4352016-12-13 02:37:363709}
3710
deadbeef9d3584c2016-02-17 01:54:103711TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3712 MakePlanBDescription();
3713
Steve Antona3a92c22017-12-07 18:27:413714 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103715 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3716
3717 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3718}
3719
3720TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3721 MakePlanBDescription();
Steve Antone831b8c2018-02-01 20:22:163722 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-17 01:54:103723}
3724
3725TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3726 MakeUnifiedPlanDescription();
3727
Steve Antona3a92c22017-12-07 18:27:413728 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103729 EXPECT_TRUE(
3730 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3731
3732 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3733}
3734
3735TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3736 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 20:22:163737 TestSerialize(jdesc_);
3738}
3739
Seth Hampson5b4f0752018-04-02 23:31:363740// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 17:25:283741// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3742// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 23:31:363743// with no stream ids and multiple stream ids. For parsing this, the Unified
3744// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3745// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 17:25:283746TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3747 // Create both msid lines for Plan B and Unified Plan support.
3748 MakeUnifiedPlanDescriptionMultipleStreamIds(
3749 cricket::kMsidSignalingMediaSection |
3750 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 23:31:363751
3752 JsepSessionDescription deserialized_description(kDummyType);
3753 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3754 &deserialized_description));
3755
3756 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 10:25:053757 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3758 cricket::kMsidSignalingSsrcAttribute,
3759 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 23:31:363760}
3761
Seth Hampson7fa6ee62018-10-17 17:25:283762// Tests the serialization of a Unified Plan SDP that is compatible for both
3763// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3764// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3765// multiple stream ids.
3766TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3767 // Create both msid lines for Plan B and Unified Plan support.
3768 MakeUnifiedPlanDescriptionMultipleStreamIds(
3769 cricket::kMsidSignalingMediaSection |
3770 cricket::kMsidSignalingSsrcAttribute);
3771 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3772 // We explicitly test that the serialized SDP string is equal to the hard
3773 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3774 // take priority over "a=ssrc msid" lines. This means if we just used
3775 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3776 // and still pass, because the deserialized version would be the same.
3777 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3778}
3779
3780// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3781// that signal stream IDs) is deserialized appropriately. It tests the case for
3782// no stream ids and multiple stream ids.
3783TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3784 // Only create a=msid lines for strictly Unified Plan stream ID support.
3785 MakeUnifiedPlanDescriptionMultipleStreamIds(
3786 cricket::kMsidSignalingMediaSection);
3787
3788 JsepSessionDescription deserialized_description(kDummyType);
3789 std::string unified_plan_sdp_string =
3790 kUnifiedPlanSdpFullStringWithSpecialMsid;
3791 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3792 EXPECT_TRUE(
3793 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3794
3795 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3796}
3797
3798// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3799// that signal stream IDs) is serialized appropriately. It tests the case for no
3800// stream ids and multiple stream ids.
3801TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3802 // Only create a=msid lines for strictly Unified Plan stream ID support.
3803 MakeUnifiedPlanDescriptionMultipleStreamIds(
3804 cricket::kMsidSignalingMediaSection);
3805
Seth Hampson5b4f0752018-04-02 23:31:363806 TestSerialize(jdesc_);
3807}
3808
Seth Hampson5897a6e2018-04-03 18:16:333809// This tests that a Unified Plan SDP with no a=ssrc lines is
3810// serialized/deserialized appropriately. In this case the
3811// MediaContentDescription will contain a StreamParams object that doesn't have
3812// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3813// SSRC lines.
3814TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3815 MakeUnifiedPlanDescription();
3816 RemoveSsrcSignalingFromStreamParams();
3817 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3818 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3819
3820 JsepSessionDescription deserialized_description(kDummyType);
3821 EXPECT_TRUE(
3822 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3823 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3824}
3825
3826TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3827 MakeUnifiedPlanDescription();
3828 RemoveSsrcSignalingFromStreamParams();
3829
3830 TestSerialize(jdesc_);
3831}
3832
Steve Antone831b8c2018-02-01 20:22:163833TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3834 JsepSessionDescription jsep_desc(kDummyType);
3835 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3836 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3837}
3838
3839TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3840 JsepSessionDescription jsep_desc(kDummyType);
3841 std::string sdp = kSdpSessionString;
3842 sdp += kSdpSctpDataChannelString;
3843 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3844 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3845}
3846
3847TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3848 JsepSessionDescription jsep_desc(kDummyType);
3849 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3850 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3851 jsep_desc.description()->msid_signaling());
3852}
3853
3854TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3855 JsepSessionDescription jsep_desc(kDummyType);
3856 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3857 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3858 jsep_desc.description()->msid_signaling());
3859}
3860
3861const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3862const char kSsrcAttributeMsidLine[] =
3863 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3864
3865TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3866 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3867 std::string sdp = webrtc::SdpSerialize(jdesc_);
3868
3869 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3870 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3871}
3872
3873TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3874 jdesc_.description()->set_msid_signaling(
3875 cricket::kMsidSignalingSsrcAttribute);
3876 std::string sdp = webrtc::SdpSerialize(jdesc_);
3877
3878 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3879 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3880}
3881
3882TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3883 jdesc_.description()->set_msid_signaling(
3884 cricket::kMsidSignalingMediaSection |
3885 cricket::kMsidSignalingSsrcAttribute);
3886 std::string sdp = webrtc::SdpSerialize(jdesc_);
3887
3888 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3889 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-17 01:54:103890}
deadbeef7e146cb2016-09-28 17:04:343891
3892// Regression test for heap overflow bug:
3893// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3894TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 17:04:343895 // The issue occurs when the sctp-port attribute is found in a video
3896 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 20:43:583897 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 17:04:343898 "v=0\r\n"
3899 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3900 "s=-\r\n"
3901 "t=0 0\r\n"
3902 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3903 "a=sctp-port 5000\r\n"
3904 "a=fmtp:108 foo=10\r\n";
3905
3906 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3907 "sctp-port");
3908}
deadbeefb2362572016-12-14 00:37:063909
3910// Regression test for integer overflow bug:
3911// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3912TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-14 00:37:063913 // Bandwidth attribute is the max signed 32-bit int, which will get
3914 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 20:43:583915 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-14 00:37:063916 "v=0\r\n"
3917 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3918 "s=-\r\n"
3919 "t=0 0\r\n"
3920 "m=video 3457 RTP/SAVPF 120\r\n"
3921 "b=AS:2147483647\r\n"
3922 "foo=fail\r\n";
3923
3924 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3925}
deadbeef7bcdb692017-01-20 20:43:583926
deadbeefbc88c6b2017-08-02 18:26:343927// Similar to the above, except that negative values are illegal, not just
3928// error-prone as large values are.
3929// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3930TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3931 static const char kSdpWithNegativeBandwidth[] =
3932 "v=0\r\n"
3933 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3934 "s=-\r\n"
3935 "t=0 0\r\n"
3936 "m=video 3457 RTP/SAVPF 120\r\n"
3937 "b=AS:-1000\r\n";
3938
3939 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3940}
3941
deadbeef3e8016e2017-08-04 00:49:303942// An exception to the above rule: a value of -1 for b=AS should just be
3943// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3944// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3945// limit", but this is now what ommitting the attribute entirely will do, so
3946// ignoring it will have the intended effect.
3947TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3948 static const char kSdpWithBandwidthOfNegativeOne[] =
3949 "v=0\r\n"
3950 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3951 "s=-\r\n"
3952 "t=0 0\r\n"
3953 "m=video 3457 RTP/SAVPF 120\r\n"
3954 "b=AS:-1\r\n";
3955
Steve Antona3a92c22017-12-07 18:27:413956 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-04 00:49:303957 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-04 00:49:303958 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303959 GetFirstVideoContentDescription(jdesc_output.description());
3960 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-04 00:49:303961 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3962}
3963
deadbeef7bcdb692017-01-20 20:43:583964// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3965// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3966// Regression test for:
3967// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3968TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3969 // Important piece is "ufrag foo pwd bar".
3970 static const char kSdpWithIceCredentialsInCandidateString[] =
3971 "v=0\r\n"
3972 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3973 "s=-\r\n"
3974 "t=0 0\r\n"
3975 "m=audio 9 RTP/SAVPF 111\r\n"
3976 "c=IN IP4 0.0.0.0\r\n"
3977 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3978 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3979 "a=rtpmap:111 opus/48000/2\r\n"
3980 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3981 "generation 2 ufrag foo pwd bar\r\n";
3982
Steve Antona3a92c22017-12-07 18:27:413983 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 20:43:583984 EXPECT_TRUE(
3985 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3986 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3987 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 10:53:233988 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 20:43:583989 cricket::Candidate c = candidates->at(0)->candidate();
3990 EXPECT_EQ("ufrag_voice", c.username());
3991 EXPECT_EQ("pwd_voice", c.password());
3992}
deadbeef90f1e1e2017-02-10 20:35:053993
Johannes Kron211856b2018-09-06 10:12:283994// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3995// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3996// Regression test for:
3997// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3998TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3999 static const char kSdpWithFooIceCredentials[] =
4000 "v=0\r\n"
4001 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4002 "s=-\r\n"
4003 "t=0 0\r\n"
4004 "m=audio 9 RTP/SAVPF 111\r\n"
4005 "c=IN IP4 0.0.0.0\r\n"
4006 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4007 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4008 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4009 "a=rtpmap:111 opus/48000/2\r\n"
4010 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4011 "generation 2\r\n";
4012
4013 JsepSessionDescription jdesc_output(kDummyType);
4014 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4015 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4016 ASSERT_NE(nullptr, candidates);
4017 ASSERT_EQ(1U, candidates->count());
4018 cricket::Candidate c = candidates->at(0)->candidate();
4019 EXPECT_EQ("ufrag_voice", c.username());
4020 EXPECT_EQ("pwd_voice", c.password());
4021}
4022
deadbeef90f1e1e2017-02-10 20:35:054023// Test that SDP with an invalid port number in "a=candidate" lines is
4024// rejected, without crashing.
4025// Regression test for:
4026// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4027TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4028 static const char kSdpWithInvalidCandidatePort[] =
4029 "v=0\r\n"
4030 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4031 "s=-\r\n"
4032 "t=0 0\r\n"
4033 "m=audio 9 RTP/SAVPF 111\r\n"
4034 "c=IN IP4 0.0.0.0\r\n"
4035 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4036 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4037 "a=rtpmap:111 opus/48000/2\r\n"
4038 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4039 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4040
Steve Antona3a92c22017-12-07 18:27:414041 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 20:35:054042 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4043}
deadbeefa4549d62017-02-11 01:26:224044
4045// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4046// Regression test for:
4047// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4048TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4049 static const char kSdpWithMissingTrackId[] =
4050 "v=0\r\n"
4051 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4052 "s=-\r\n"
4053 "t=0 0\r\n"
4054 "m=audio 9 RTP/SAVPF 111\r\n"
4055 "c=IN IP4 0.0.0.0\r\n"
4056 "a=rtpmap:111 opus/48000/2\r\n"
4057 "a=msid:stream_id \r\n";
4058
Steve Antona3a92c22017-12-07 18:27:414059 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224060 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4061}
4062
4063TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4064 static const char kSdpWithMissingStreamId[] =
4065 "v=0\r\n"
4066 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4067 "s=-\r\n"
4068 "t=0 0\r\n"
4069 "m=audio 9 RTP/SAVPF 111\r\n"
4070 "c=IN IP4 0.0.0.0\r\n"
4071 "a=rtpmap:111 opus/48000/2\r\n"
4072 "a=msid: track_id\r\n";
4073
Steve Antona3a92c22017-12-07 18:27:414074 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224075 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4076}
zhihuang38989e52017-03-21 18:04:534077
4078// Tests that if both session-level address and media-level address exist, use
4079// the media-level address.
4080TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 18:27:414081 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534082
4083 // Sesssion-level address.
4084 std::string sdp = kSdpFullString;
4085 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4086 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4087
4088 const auto& content1 = jsep_desc.description()->contents()[0];
4089 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 23:14:304090 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534091 const auto& content2 = jsep_desc.description()->contents()[1];
4092 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 23:14:304093 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534094}
4095
4096// Tests that the session-level connection address will be used if the media
4097// level-addresses are not specified.
4098TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 18:27:414099 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534100
4101 // Sesssion-level address.
4102 std::string sdp = kSdpString;
4103 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4104 // Remove the media level addresses.
4105 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4106 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4107 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4108
4109 const auto& content1 = jsep_desc.description()->contents()[0];
4110 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304111 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534112 const auto& content2 = jsep_desc.description()->contents()[1];
4113 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304114 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534115}
4116
4117TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 18:27:414118 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534119
4120 std::string sdp = kSdpString;
4121 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4122 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4123 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4124 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4125 &sdp);
4126 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4127 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4128 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4129 &sdp);
4130 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4131 const auto& content1 = jsep_desc.description()->contents()[0];
4132 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 23:14:304133 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534134 const auto& content2 = jsep_desc.description()->contents()[1];
4135 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 23:14:304136 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534137}
4138
Qingsi Wang56991422019-02-08 20:53:064139// Test that a c= line that contains a hostname connection address can be
4140// parsed.
4141TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4142 JsepSessionDescription jsep_desc(kDummyType);
4143 std::string sdp = kSdpString;
4144 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4145
4146 sdp = kSdpString;
4147 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4148 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4149 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4150
4151 ASSERT_NE(nullptr, jsep_desc.description());
4152 const auto& content1 = jsep_desc.description()->contents()[0];
4153 EXPECT_EQ("example.local:9",
4154 content1.media_description()->connection_address().ToString());
4155 const auto& content2 = jsep_desc.description()->contents()[1];
4156 EXPECT_EQ("example.local:9",
4157 content2.media_description()->connection_address().ToString());
4158}
4159
4160// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 18:04:534161TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 18:27:414162 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534163 std::string sdp = kSdpString;
4164 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4165
4166 // Unsupported multicast IPv4 address.
4167 sdp = kSdpFullString;
4168 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4169 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4170
4171 // Unsupported multicast IPv6 address.
4172 sdp = kSdpFullString;
4173 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4174 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4175
4176 // Mismatched address type.
4177 sdp = kSdpFullString;
4178 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4179 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4180
4181 sdp = kSdpFullString;
4182 Replace("c=IN IP4 74.125.224.39\r\n",
4183 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4184 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4185}
4186
4187TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 18:27:414188 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 18:04:534189 MakeDescriptionWithoutCandidates(&expected_jsep);
4190 // Serialization.
Steve Antone831b8c2018-02-01 20:22:164191 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 18:04:534192 // Deserialization.
Steve Antona3a92c22017-12-07 18:27:414193 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 18:04:534194 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 23:14:304195 auto audio_desc = jdesc.description()
4196 ->GetContentByName(kAudioContentName)
4197 ->media_description();
4198 auto video_desc = jdesc.description()
4199 ->GetContentByName(kVideoContentName)
4200 ->media_description();
zhihuang38989e52017-03-21 18:04:534201 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4202 audio_desc->connection_address().ToString());
4203 EXPECT_EQ(video_desc_->connection_address().ToString(),
4204 video_desc->connection_address().ToString());
4205}
Taylor Brandstetter93a7b242018-04-16 17:45:244206
Qingsi Wang56991422019-02-08 20:53:064207// Test that a media description that contains a hostname connection address can
4208// be correctly serialized.
4209TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4210 JsepSessionDescription expected_jsep(kDummyType);
4211 cricket::Candidate c;
4212 const rtc::SocketAddress hostname_addr("example.local", 1234);
4213 audio_desc_->set_connection_address(hostname_addr);
4214 video_desc_->set_connection_address(hostname_addr);
4215 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 05:01:294216 expected_jsep.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Qingsi Wang56991422019-02-08 20:53:064217 // Serialization.
4218 std::string message = webrtc::SdpSerialize(expected_jsep);
4219 // Deserialization.
4220 JsepSessionDescription jdesc(kDummyType);
4221 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4222 auto audio_desc = jdesc.description()
4223 ->GetContentByName(kAudioContentName)
4224 ->media_description();
4225 auto video_desc = jdesc.description()
4226 ->GetContentByName(kVideoContentName)
4227 ->media_description();
4228 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4229 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4230}
4231
Taylor Brandstetter93a7b242018-04-16 17:45:244232// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4233// used (i.e., a single space as the session name)." So we should accept that.
4234TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4235 JsepSessionDescription jsep_desc(kDummyType);
4236 std::string sdp = kSdpString;
4237 Replace("s=-\r\n", "s= \r\n", &sdp);
4238 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4239}
Amit Hilbucha2012042018-12-03 19:35:054240
4241// Simulcast malformed input test for invalid format.
4242TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4243 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4244 "a=simulcast:\r\n", "a=simulcast:");
4245}
4246
4247// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4248TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4249 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4250 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4251 "a=simulcast:");
4252}
4253
4254// Validates that deserialization uses the a=simulcast: attribute
4255TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 23:30:114256 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4257 sdp += "a=rid:1 send\r\n";
4258 sdp += "a=rid:2 send\r\n";
4259 sdp += "a=rid:3 send\r\n";
4260 sdp += "a=rid:4 recv\r\n";
4261 sdp += "a=rid:5 recv\r\n";
4262 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 19:35:054263 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4264 JsepSessionDescription output(kDummyType);
4265 SdpParseError error;
4266 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4267 const cricket::ContentInfos& contents = output.description()->contents();
4268 const cricket::MediaContentDescription* media =
4269 contents.back().media_description();
4270 EXPECT_TRUE(media->HasSimulcast());
4271 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4272 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 23:30:114273 EXPECT_FALSE(media->streams().empty());
4274 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4275 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114276}
4277
4278// Validates that deserialization removes rids that do not appear in SDP
4279TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4280 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4281 sdp += "a=rid:1 send\r\n";
4282 sdp += "a=rid:3 send\r\n";
4283 sdp += "a=rid:4 recv\r\n";
4284 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4285 JsepSessionDescription output(kDummyType);
4286 SdpParseError error;
4287 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4288 const cricket::ContentInfos& contents = output.description()->contents();
4289 const cricket::MediaContentDescription* media =
4290 contents.back().media_description();
4291 EXPECT_TRUE(media->HasSimulcast());
4292 const SimulcastDescription& simulcast = media->simulcast_description();
4293 EXPECT_EQ(2ul, simulcast.send_layers().size());
4294 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4295
4296 std::vector<SimulcastLayer> all_send_layers =
4297 simulcast.send_layers().GetAllLayers();
4298 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-29 01:25:264299 EXPECT_EQ(0,
4300 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4301 return layer.rid == "2";
4302 }));
Amit Hilbuchc57d5732018-12-11 23:30:114303
4304 std::vector<SimulcastLayer> all_receive_layers =
4305 simulcast.receive_layers().GetAllLayers();
4306 ASSERT_EQ(1ul, all_receive_layers.size());
4307 EXPECT_EQ("4", all_receive_layers[0].rid);
4308
4309 EXPECT_FALSE(media->streams().empty());
4310 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4311 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114312}
4313
4314// Validates that Simulcast removes rids that appear in both send and receive.
4315TEST_F(WebRtcSdpTest,
4316 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4317 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4318 sdp += "a=rid:1 send\r\n";
4319 sdp += "a=rid:2 send\r\n";
4320 sdp += "a=rid:3 send\r\n";
4321 sdp += "a=rid:4 recv\r\n";
4322 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4323 JsepSessionDescription output(kDummyType);
4324 SdpParseError error;
4325 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4326 const cricket::ContentInfos& contents = output.description()->contents();
4327 const cricket::MediaContentDescription* media =
4328 contents.back().media_description();
4329 EXPECT_TRUE(media->HasSimulcast());
4330 const SimulcastDescription& simulcast = media->simulcast_description();
4331 EXPECT_EQ(2ul, simulcast.send_layers().size());
4332 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4333 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4334 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4335
4336 EXPECT_FALSE(media->streams().empty());
4337 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4338 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114339}
4340
4341// Ignores empty rid line.
4342TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4343 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4344 sdp += "a=rid:1 send\r\n";
4345 sdp += "a=rid:2 send\r\n";
4346 sdp += "a=rid\r\n"; // Should ignore this line.
4347 sdp += "a=rid:\r\n"; // Should ignore this line.
4348 sdp += "a=simulcast:send 1;2\r\n";
4349 JsepSessionDescription output(kDummyType);
4350 SdpParseError error;
4351 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4352 const cricket::ContentInfos& contents = output.description()->contents();
4353 const cricket::MediaContentDescription* media =
4354 contents.back().media_description();
4355 EXPECT_TRUE(media->HasSimulcast());
4356 const SimulcastDescription& simulcast = media->simulcast_description();
4357 EXPECT_TRUE(simulcast.receive_layers().empty());
4358 EXPECT_EQ(2ul, simulcast.send_layers().size());
4359 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4360
4361 EXPECT_FALSE(media->streams().empty());
4362 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4363 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 23:30:114364}
4365
4366// Ignores malformed rid lines.
4367TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4368 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4369 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4370 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4371 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4372 sdp += "a=rid:4\r\n"; // Should ignore this line.
4373 sdp += "a=rid:5 send\r\n";
4374 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4375 JsepSessionDescription output(kDummyType);
4376 SdpParseError error;
4377 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4378 const cricket::ContentInfos& contents = output.description()->contents();
4379 const cricket::MediaContentDescription* media =
4380 contents.back().media_description();
4381 EXPECT_TRUE(media->HasSimulcast());
4382 const SimulcastDescription& simulcast = media->simulcast_description();
4383 EXPECT_TRUE(simulcast.receive_layers().empty());
4384 EXPECT_EQ(1ul, simulcast.send_layers().size());
4385 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4386
4387 EXPECT_FALSE(media->streams().empty());
4388 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4389 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 23:30:114390}
4391
4392// Removes RIDs that specify a different format than the m= section.
4393TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4394 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4395 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4396 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4397 sdp += "a=simulcast:send 1;2\r\n";
4398 JsepSessionDescription output(kDummyType);
4399 SdpParseError error;
4400 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4401 const cricket::ContentInfos& contents = output.description()->contents();
4402 const cricket::MediaContentDescription* media =
4403 contents.back().media_description();
4404 EXPECT_TRUE(media->HasSimulcast());
4405 const SimulcastDescription& simulcast = media->simulcast_description();
4406 EXPECT_TRUE(simulcast.receive_layers().empty());
4407 EXPECT_EQ(1ul, simulcast.send_layers().size());
4408 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4409 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4410 EXPECT_EQ(1ul, media->streams().size());
4411 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4412 EXPECT_EQ(1ul, rids.size());
4413 EXPECT_EQ("1", rids[0].rid);
4414 EXPECT_EQ(1ul, rids[0].payload_types.size());
4415 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 23:30:114416}
4417
4418// Ignores duplicate rid lines
4419TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4420 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4421 sdp += "a=rid:1 send\r\n";
4422 sdp += "a=rid:2 send\r\n";
4423 sdp += "a=rid:2 send\r\n";
4424 sdp += "a=rid:3 send\r\n";
4425 sdp += "a=rid:4 recv\r\n";
4426 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4427 JsepSessionDescription output(kDummyType);
4428 SdpParseError error;
4429 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4430 const cricket::ContentInfos& contents = output.description()->contents();
4431 const cricket::MediaContentDescription* media =
4432 contents.back().media_description();
4433 EXPECT_TRUE(media->HasSimulcast());
4434 const SimulcastDescription& simulcast = media->simulcast_description();
4435 EXPECT_EQ(2ul, simulcast.send_layers().size());
4436 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4437 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4438 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4439
4440 EXPECT_FALSE(media->streams().empty());
4441 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4442 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 19:35:054443}
4444
4445// Simulcast serialization integration test.
4446// This test will serialize and deserialize the description and compare.
4447// More detailed tests for parsing simulcast can be found in
4448// unit tests for SdpSerializer.
4449TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 23:30:114450 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 19:35:054451 auto description = jdesc_.description();
4452 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 23:30:114453 ASSERT_EQ(media->streams().size(), 1ul);
4454 StreamParams& send_stream = media->mutable_streams()[0];
4455 std::vector<RidDescription> send_rids;
4456 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4457 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4458 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4459 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4460 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 23:30:114461
Amit Hilbucha2012042018-12-03 19:35:054462 SimulcastDescription& simulcast = media->simulcast_description();
4463 simulcast.send_layers().AddLayerWithAlternatives(
4464 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4465 simulcast.send_layers().AddLayerWithAlternatives(
4466 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4467
Amit Hilbucha2012042018-12-03 19:35:054468 TestSerialize(jdesc_);
4469}
Steve Anton06817cd2018-12-18 23:55:304470
4471// Test that the content name is empty if the media section does not have an
4472// a=mid line.
4473TEST_F(WebRtcSdpTest, ParseNoMid) {
4474 std::string sdp = kSdpString;
4475 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4476 Replace("a=mid:video_content_name\r\n", "", &sdp);
4477
4478 JsepSessionDescription output(kDummyType);
4479 SdpParseError error;
4480 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4481
4482 EXPECT_THAT(output.description()->contents(),
4483 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4484 Field("name", &cricket::ContentInfo::name, "")));
4485}
Piotr (Peter) Slatala13e570f2019-02-27 19:34:264486
4487// Test that the media transport name and base64-decoded setting is parsed from
4488// an a=x-mt line.
4489TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4490 JsepSessionDescription output(kDummyType);
4491 std::string sdp = kSdpSessionString;
4492 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4493 SdpParseError error;
4494
4495 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4496 << error.description;
4497 const auto& settings = output.description()->MediaTransportSettings();
4498 ASSERT_EQ(1u, settings.size());
4499 EXPECT_EQ("rtp", settings[0].transport_name);
4500 EXPECT_EQ("test64", settings[0].transport_setting);
4501}
4502
4503// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4504TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4505 JsepSessionDescription output(kDummyType);
4506 std::string sdp = kSdpSessionString;
4507 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4508 SdpParseError error;
4509
4510 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4511}
4512
4513// Test that multiple a=x-mt lines are parsed in the order of preference (the
4514// order of the lines in the SDP).
4515TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4516 JsepSessionDescription output(kDummyType);
4517 std::string sdp = kSdpSessionString;
4518 sdp +=
4519 "a=x-mt:rtp:dGVzdDY0\r\n"
4520 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4521 SdpParseError error;
4522
4523 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4524 << error.description;
4525 const auto& settings = output.description()->MediaTransportSettings();
4526 ASSERT_EQ(2u, settings.size());
4527 EXPECT_EQ("rtp", settings[0].transport_name);
4528 EXPECT_EQ("test64", settings[0].transport_setting);
4529 EXPECT_EQ("generic", settings[1].transport_name);
4530 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4531}
4532
4533// Test that only the first a=x-mt line associated with a transport name is
4534// parsed and the rest ignored.
4535TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4536 JsepSessionDescription output(kDummyType);
4537 std::string sdp = kSdpSessionString;
4538 sdp +=
4539 "a=x-mt:rtp:dGVzdDY0\r\n"
4540 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4541 SdpParseError error;
4542
4543 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4544 // but ignore the repeated transport.
4545 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4546 const auto& settings = output.description()->MediaTransportSettings();
4547 EXPECT_EQ("test64", settings[0].transport_setting);
4548}
4549
4550// Test that an a=x-mt line fails to parse if it is missing a setting.
4551TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4552 JsepSessionDescription output(kDummyType);
4553 std::string sdp = kSdpSessionString;
4554 sdp += "a=x-mt:rtp\r\n";
4555 SdpParseError error;
4556
4557 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4558}
4559
4560// Test that an a=x-mt line fails to parse if its missing a name and setting.
4561TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4562 JsepSessionDescription output(kDummyType);
4563 std::string sdp = kSdpSessionString;
4564 sdp += "a=x-mt\r\n";
4565 SdpParseError error;
4566
4567 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4568}
4569
4570TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4571 JsepSessionDescription output(kDummyType);
4572 std::string sdp = kSdpSessionString;
4573 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4574 SdpParseError error;
4575
4576 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4577 << error.description;
4578 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4579}
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:054580
4581TEST_F(WebRtcSdpTest, SerializeMediaTransportSettings) {
Harald Alvestrand4d7160e2019-04-12 05:01:294582 auto description = absl::make_unique<cricket::SessionDescription>();
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:054583
4584 JsepSessionDescription output(SdpType::kOffer);
4585 // JsepSessionDescription takes ownership of the description.
Harald Alvestrand4d7160e2019-04-12 05:01:294586 output.Initialize(std::move(description), "session_id", "session_version");
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:054587 output.description()->AddMediaTransportSetting("foo", "bar");
4588 std::string serialized_out;
4589 output.ToString(&serialized_out);
4590 ASSERT_THAT(serialized_out, ::testing::HasSubstr("\r\na=x-mt:foo:YmFy\r\n"));
4591}
4592
4593TEST_F(WebRtcSdpTest, SerializeMediaTransportSettingsTestCopy) {
4594 cricket::SessionDescription description;
4595 description.AddMediaTransportSetting("name", "setting");
Harald Alvestrand4d7160e2019-04-12 05:01:294596 std::unique_ptr<cricket::SessionDescription> copy = description.Clone();
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:054597 ASSERT_EQ(1u, copy->MediaTransportSettings().size());
4598 EXPECT_EQ("name", copy->MediaTransportSettings()[0].transport_name);
4599 EXPECT_EQ("setting", copy->MediaTransportSettings()[0].transport_setting);
4600}
Guido Urdanetacecf87f2019-05-31 10:17:384601
4602TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4603 AddSctpDataChannel(false); // Don't use sctpmap
4604 JsepSessionDescription jsep_desc(kDummyType);
4605 MakeDescriptionWithoutCandidates(&jsep_desc);
4606 std::string message = webrtc::SdpSerialize(jsep_desc);
4607 EXPECT_NE(std::string::npos,
4608 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4609}
4610
4611TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4612 AddSctpDataChannel(false);
4613 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4614 cricket::kMediaProtocolUdpDtlsSctp,
4615 cricket::kMediaProtocolTcpDtlsSctp};
4616 for (const auto& protocol : protocols) {
4617 sctp_desc_->set_protocol(protocol);
4618 JsepSessionDescription jsep_desc(kDummyType);
4619 MakeDescriptionWithoutCandidates(&jsep_desc);
4620 std::string message = webrtc::SdpSerialize(jsep_desc);
4621 EXPECT_NE(std::string::npos, message.find(protocol));
4622 JsepSessionDescription jsep_output(kDummyType);
4623 SdpParseError error;
4624 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4625 }
4626}