blob: 1d3e6a3ce226b37e153541168dec77ff963183cb [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020013#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
15#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070016#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010018#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019#include <vector>
20
Steve Anton64b626b2019-01-28 17:25:26 -080021#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080022#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080023#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#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 16:47:49 +010030#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "media/base/media_constants.h"
32#include "media/base/stream_params.h"
33#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020034#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080035#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 06:47:31 +020039#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#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 15:55:30 -080044#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010045#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020046
ossu7bb87ee2017-01-23 04:56:25 -080047#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080048#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080049#endif
Steve Anton10542f22019-01-11 09:11:00 -080050#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52using cricket::AudioCodec;
53using cricket::AudioContentDescription;
54using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080055using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::ContentInfo;
57using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
60using cricket::ICE_CANDIDATE_COMPONENT_RTP;
61using cricket::kFecSsrcGroupSemantics;
62using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080063using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080064using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080065using cricket::RidDescription;
66using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020067using cricket::RtpDataContentDescription;
68using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080069using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080070using cricket::SimulcastDescription;
71using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using cricket::StreamParams;
73using cricket::STUN_PORT_TYPE;
74using cricket::TransportDescription;
75using cricket::TransportInfo;
76using cricket::VideoCodec;
77using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080078using ::testing::ElementsAre;
79using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::IceCandidateCollection;
81using webrtc::IceCandidateInterface;
82using webrtc::JsepIceCandidate;
83using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070084using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080085using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080087using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::SessionDescriptionInterface;
89
90typedef std::vector<AudioCodec> AudioCodecs;
91typedef std::vector<Candidate> Candidates;
92
Peter Boström0c4e06b2015-10-07 12:23:21 +020093static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080094static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020096static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080097static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080099static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200101static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static 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 15:03:05 +0200113static const char kFingerprint[] =
114 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +0200116static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117static 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 12:31:36 -0700123static 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:36 +0000126
Peter Boström0c4e06b2015-10-07 12:23:21 +0200127static 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:36 +0000130
lally@webrtc.org34807282015-02-24 20:19:39 +0000131static 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:35 +0000134
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135struct 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:59 +0000142 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143};
144
deadbeef9d3584c2016-02-16 17:54:10 -0800145// 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:36 +0000149// 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-16 17:54:10 -0800155 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
157 "c=IN IP4 74.125.127.126\r\n"
158 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
159 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
168 "raddr 192.168.1.5 rport 2346 "
169 "generation 2\r\n"
170 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
171 "raddr 192.168.1.5 rport 2348 "
172 "generation 2\r\n"
173 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
174 "a=mid:audio_content_name\r\n"
175 "a=sendrecv\r\n"
176 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800177 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
179 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
180 "dummy_session_params\r\n"
181 "a=rtpmap:111 opus/48000/2\r\n"
182 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000183 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 "a=ssrc:1 cname:stream_1_cname\r\n"
185 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
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:36 +0000188 "m=video 3457 RTP/SAVPF 120\r\n"
189 "c=IN IP4 74.125.224.39\r\n"
190 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
191 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
200 "generation 2\r\n"
201 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
202 "generation 2\r\n"
203 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
204 "a=mid:video_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
207 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
208 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800209 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 "a=ssrc:2 cname:stream_1_cname\r\n"
211 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
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-16 17:54:10 -0800215 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800217 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
219// SDP reference string without the candidates.
220static const char kSdpString[] =
221 "v=0\r\n"
222 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
223 "s=-\r\n"
224 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800225 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000226 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000227 "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:36 +0000229 "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 12:37:51 -0800233 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 "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:41 +0000239 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 "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:22 +0000244 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000245 "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:36 +0000247 "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-16 17:54:10 -0800253 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 "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-16 17:54:10 -0800259 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800261 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262
263static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000264 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000265 "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:36 +0000267 "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 13:36:16 +0200279// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280static const char kSdpSctpDataChannelString[] =
Harald Alvestrandc3f48202019-05-14 17:27:11 +0200281 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000282 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 "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:33 +0000286 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000288// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200289// 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:56 +0000291static const char kSdpSctpDataChannelStringWithSctpPort[] =
Harald Alvestrandc3f48202019-05-14 17:27:11 +0200292 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000293 "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 10:41:24 +0200299// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700300static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Harald Alvestrandc3f48202019-05-14 17:27:11 +0200301 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700302 "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:36 +0000308static const char kSdpSctpDataChannelWithCandidatesString[] =
Harald Alvestrandc3f48202019-05-14 17:27:11 +0200309 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 "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:33 +0000321 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000323static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000324 "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:22 +0000329 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000331 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000334 "a=x-google-flag:conference\r\n";
335
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336static 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:22 +0000344 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000345 "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:05 +0000347 "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:22 +0000357 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000358 "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:05 +0000360 "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-12 18:37:36 -0800369// 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-16 17:54:10 -0800428// 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:36 +0000617
Seth Hampson5b4f0752018-04-02 16:31:36 -0700618// 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 16:31:36 -0700651 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700652 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700653 "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 10:25:28 -0700671 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700672 "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 16:31:36 -0700674 "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 16:31:36 -0700694 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700695 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700696 "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 10:25:28 -0700704 "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 16:31:36 -0700708
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800709// 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:36 +0000808// 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:15 +0000816
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000817static 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:15 +0000830// One candidate reference string with IPV6 address.
831static const char kRawIPV6Candidate[] =
832 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700833 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834
835// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800836static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800838 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839
Zach Steinb336c272018-08-09 01:16:13 -0700840static 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:36 +0000843// Session id and version
844static const char kSessionId[] = "18446744069414584320";
845static const char kSessionVersion[] = "18446462598732840960";
846
deadbeef9d3584c2016-02-16 17:54:10 -0800847// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848static const char kIceOption1[] = "iceoption1";
849static const char kIceOption2[] = "iceoption2";
850static const char kIceOption3[] = "iceoption3";
851
deadbeef9d3584c2016-02-16 17:54:10 -0800852// 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 16:31:36 -0700863static const char kUfragVoice3[] = "ufrag_voice_3";
864static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800865static 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:36 +0000870// 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-16 17:54:10 -0800875// Extra content names for extra unified plan m= sections.
876static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700877static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800878static const char kVideoContentName2[] = "video_content_name_2";
879static const char kVideoContentName3[] = "video_content_name_3";
880
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800882static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883static const char kStream1Cname[] = "stream_1_cname";
884static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200885static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800887static const uint32_t kVideoTrack1Ssrc1 = 2;
888static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889
890// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800891static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892static const char kStream2Cname[] = "stream_2_cname";
893static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200894static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800895static const char kVideoTrackId2[] = "video_track_id_2";
896static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800898static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700899static const char kAudioTrackId3[] = "audio_track_id_3";
900static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
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 12:23:21 +0200906static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907
908// Candidate
909static const char kDummyMid[] = "dummy_mid";
910static const int kDummyIndex = 123;
911
912// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800913static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914
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 15:13:09 -0800931 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932}
933
934static void Replace(const std::string& line,
935 const std::string& newlines,
936 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800937 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938}
939
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000940// 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 10:27:41 -0800944 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000946 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000948 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:36 +0000965}
966
Steve Anton4e70a722017-11-28 14:57:10 -0800967static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 std::string* message) {
969 std::string new_direction;
970 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800971 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 new_direction = "a=inactive";
973 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800974 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 new_direction = "a=sendonly";
976 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800977 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 new_direction = "a=recvonly";
979 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800980 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 default:
982 new_direction = "a=sendrecv";
983 break;
984 }
985 Replace("a=sendrecv", new_direction, message);
986}
987
Yves Gerey665174f2018-06-19 15:03:05 +0200988static void ReplaceRejected(bool audio_rejected,
989 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 std::string* message) {
991 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800992 Replace("m=audio 9", "m=audio 0", message);
993 Replace(kAttributeIceUfragVoice, "", message);
994 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 }
996 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800997 Replace("m=video 9", "m=video 0", message);
998 Replace(kAttributeIceUfragVideo, "", message);
999 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 }
1001}
1002
1003// WebRtcSdpTest
1004
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001005class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001007 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001008#ifdef WEBRTC_ANDROID
1009 webrtc::InitializeAndroidObjects();
1010#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 // AudioContentDescription
1012 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001013 StreamParams audio_stream;
1014 audio_stream.id = kAudioTrackId1;
1015 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001016 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001017 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1018 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001019 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1020 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001021 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022
1023 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001024 video_desc_ = CreateVideoContentDescription();
1025 StreamParams video_stream;
1026 video_stream.id = kVideoTrackId1;
1027 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001028 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001029 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1030 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1031 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1032 video_stream.ssrc_groups.push_back(ssrc_group);
1033 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001034 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1035 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001036 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037
1038 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001039 desc_.AddTransportInfo(TransportInfo(
1040 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1041 desc_.AddTransportInfo(TransportInfo(
1042 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043
1044 // v4 host
1045 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001046 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001047 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001048 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1049 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001051 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001052 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1053 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001055 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001056 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1057 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001059 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001060 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1061 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062
1063 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001064 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001065 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1066 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001067 cricket::LOCAL_PORT_TYPE,
1068 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001070 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1071 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001072 cricket::LOCAL_PORT_TYPE,
1073 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001075 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1076 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001077 cricket::LOCAL_PORT_TYPE,
1078 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001080 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1081 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001082 cricket::LOCAL_PORT_TYPE,
1083 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084
1085 // stun
1086 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1088 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001089 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1090 address_stun, kCandidatePriority, "", "",
1091 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001092 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 candidate9.set_related_address(rel_address_stun);
1094
1095 address_stun.SetPort(port_stun++);
1096 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001097 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1098 address_stun, kCandidatePriority, "", "",
1099 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001100 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 candidate10.set_related_address(rel_address_stun);
1102
1103 // relay
1104 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001105 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001106 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1107 address_relay, kCandidatePriority, "", "",
1108 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001109 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001111 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1112 address_relay, kCandidatePriority, "", "",
1113 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001114 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115
1116 // voice
1117 candidates_.push_back(candidate1);
1118 candidates_.push_back(candidate2);
1119 candidates_.push_back(candidate5);
1120 candidates_.push_back(candidate6);
1121 candidates_.push_back(candidate9);
1122 candidates_.push_back(candidate10);
1123
1124 // video
1125 candidates_.push_back(candidate3);
1126 candidates_.push_back(candidate4);
1127 candidates_.push_back(candidate7);
1128 candidates_.push_back(candidate8);
1129 candidates_.push_back(candidate11);
1130 candidates_.push_back(candidate12);
1131
Yves Gerey665174f2018-06-19 15:03:05 +02001132 jcandidate_.reset(
1133 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134
1135 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001136 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 std::string mline_id;
1138 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001139 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 // In this test, the audio m line index will be 0, and the video m line
1141 // will be 1.
1142 bool is_video = (i > 5);
1143 mline_id = is_video ? "video_content_name" : "audio_content_name";
1144 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001145 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 jdesc_.AddCandidate(&jice);
1147 }
1148 }
1149
Seth Hampson5b4f0752018-04-02 16:31:36 -07001150 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001151 const IceCandidateCollection* video_candidates_collection =
1152 jdesc_.candidates(1);
1153 ASSERT_NE(nullptr, video_candidates_collection);
1154 std::vector<cricket::Candidate> video_candidates;
1155 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1156 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1157 c.set_transport_name("video_content_name");
1158 video_candidates.push_back(c);
1159 }
1160 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001161 }
1162
1163 // Turns the existing reference description into a description using
1164 // a=bundle-only. This means no transport attributes and a 0 port value on
1165 // the m= sections not associated with the BUNDLE-tag.
1166 void MakeBundleOnlyDescription() {
1167 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001168
1169 // And the rest of the transport attributes.
1170 desc_.transport_infos()[1].description.ice_ufrag.clear();
1171 desc_.transport_infos()[1].description.ice_pwd.clear();
1172 desc_.transport_infos()[1].description.connection_role =
1173 cricket::CONNECTIONROLE_NONE;
1174
1175 // Set bundle-only flag.
1176 desc_.contents()[1].bundle_only = true;
1177
1178 // Add BUNDLE group.
1179 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1180 group.AddContentName(kAudioContentName);
1181 group.AddContentName(kVideoContentName);
1182 desc_.AddGroup(group);
1183
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001184 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001185 jdesc_.session_version()));
1186 }
1187
deadbeef9d3584c2016-02-16 17:54:10 -08001188 // Turns the existing reference description into a plan B description,
1189 // with 2 audio tracks and 3 video tracks.
1190 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001191 audio_desc_ = audio_desc_->Copy();
1192 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001193
1194 StreamParams audio_track_2;
1195 audio_track_2.id = kAudioTrackId2;
1196 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001197 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001198 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1199 audio_desc_->AddStream(audio_track_2);
1200
1201 StreamParams video_track_2;
1202 video_track_2.id = kVideoTrackId2;
1203 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001204 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001205 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1206 video_desc_->AddStream(video_track_2);
1207
1208 StreamParams video_track_3;
1209 video_track_3.id = kVideoTrackId3;
1210 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001211 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001212 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1213 video_desc_->AddStream(video_track_3);
1214
1215 desc_.RemoveContentByName(kAudioContentName);
1216 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001217 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1218 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001219
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001220 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001221 jdesc_.session_version()));
1222 }
1223
1224 // Turns the existing reference description into a unified plan description,
1225 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001226 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001227 // Audio track 2.
1228 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1229 StreamParams audio_track_2;
1230 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001231 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001232 if (use_ssrcs) {
1233 audio_track_2.cname = kStream2Cname;
1234 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1235 }
deadbeef9d3584c2016-02-16 17:54:10 -08001236 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001237 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001238 desc_.AddTransportInfo(TransportInfo(
1239 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001240 // Video track 2, in stream 2.
1241 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1242 StreamParams video_track_2;
1243 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001244 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001245 if (use_ssrcs) {
1246 video_track_2.cname = kStream2Cname;
1247 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1248 }
deadbeef9d3584c2016-02-16 17:54:10 -08001249 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001250 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001251 desc_.AddTransportInfo(TransportInfo(
1252 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001253
1254 // Video track 3, in stream 2.
1255 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1256 StreamParams video_track_3;
1257 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001258 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001259 if (use_ssrcs) {
1260 video_track_3.cname = kStream2Cname;
1261 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1262 }
deadbeef9d3584c2016-02-16 17:54:10 -08001263 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001264 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001265 desc_.AddTransportInfo(TransportInfo(
1266 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001267 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001268
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001269 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001270 jdesc_.session_version()));
1271 }
1272
1273 // Creates an audio content description with no streams, and some default
1274 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 AudioContentDescription* CreateAudioContentDescription() {
1276 AudioContentDescription* audio = new AudioContentDescription();
1277 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001278 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001279 audio->AddCrypto(CryptoParams(
1280 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1282 "dummy_session_params"));
1283 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001284 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001285 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001286 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1287 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 return audio;
1289 }
1290
Seth Hampson5b4f0752018-04-02 16:31:36 -07001291 // Turns the existing reference description into a unified plan description,
1292 // with 3 audio MediaContentDescriptions with special StreamParams that
1293 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1294 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001295 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001296 desc_.RemoveContentByName(kVideoContentName);
1297 desc_.RemoveTransportInfoByName(kVideoContentName);
1298 RemoveVideoCandidates();
1299
1300 // Audio track 2 has 2 media stream ids.
1301 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1302 StreamParams audio_track_2;
1303 audio_track_2.id = kAudioTrackId2;
1304 audio_track_2.cname = kStream1Cname;
1305 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1306 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1307 audio_desc_2->AddStream(audio_track_2);
1308 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001309 desc_.AddTransportInfo(TransportInfo(
1310 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001311
1312 // Audio track 3 has no stream ids.
1313 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1314 StreamParams audio_track_3;
1315 audio_track_3.id = kAudioTrackId3;
1316 audio_track_3.cname = kStream2Cname;
1317 audio_track_3.set_stream_ids({});
1318 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1319 audio_desc_3->AddStream(audio_track_3);
1320 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001321 desc_.AddTransportInfo(TransportInfo(
1322 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001323 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001324 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001325 jdesc_.session_version()));
1326 }
1327
Seth Hampson5897a6e2018-04-03 11:16:33 -07001328 // Turns the existing reference description into a unified plan description
1329 // with one audio MediaContentDescription that contains one StreamParams with
1330 // 0 ssrcs.
1331 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1332 desc_.RemoveContentByName(kVideoContentName);
1333 desc_.RemoveContentByName(kAudioContentName);
1334 desc_.RemoveTransportInfoByName(kVideoContentName);
1335 RemoveVideoCandidates();
1336
1337 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1338 StreamParams audio_track;
1339 audio_track.id = kAudioTrackId1;
1340 audio_track.set_stream_ids({kStreamId1});
1341 audio_desc->AddStream(audio_track);
1342 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1343
1344 // Enable signaling a=msid lines.
1345 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001346 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001347 jdesc_.session_version()));
1348 }
1349
deadbeef9d3584c2016-02-16 17:54:10 -08001350 // Creates a video content description with no streams, and some default
1351 // configuration.
1352 VideoContentDescription* CreateVideoContentDescription() {
1353 VideoContentDescription* video = new VideoContentDescription();
1354 video->AddCrypto(CryptoParams(
1355 1, "AES_CM_128_HMAC_SHA1_80",
1356 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1357 video->set_protocol(cricket::kMediaProtocolSavpf);
1358 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001359 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001360 return video;
1361 }
1362
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001364 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 // type
1366 EXPECT_EQ(cd1->type(), cd1->type());
1367
1368 // content direction
1369 EXPECT_EQ(cd1->direction(), cd2->direction());
1370
1371 // rtcp_mux
1372 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1373
deadbeef13871492015-12-09 12:37:51 -08001374 // rtcp_reduced_size
1375 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 // cryptos
1378 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1379 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1380 ADD_FAILURE();
1381 return;
1382 }
Yves Gerey665174f2018-06-19 15:03:05 +02001383 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 const CryptoParams c1 = cd1->cryptos().at(i);
1385 const CryptoParams c2 = cd2->cryptos().at(i);
1386 EXPECT_TRUE(c1.Matches(c2));
1387 EXPECT_EQ(c1.key_params, c2.key_params);
1388 EXPECT_EQ(c1.session_params, c2.session_params);
1389 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001392 // Use an equivalence class here, for old and new versions of the
1393 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001394 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1395 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1396 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001397 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001398 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1399 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1400 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001401 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001402 } else {
1403 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1404 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405
1406 // codecs
1407 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1408
1409 // bandwidth
1410 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1411
1412 // streams
1413 EXPECT_EQ(cd1->streams(), cd2->streams());
1414
Johannes Kron0854eb62018-10-10 22:33:20 +02001415 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001416 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 // extmap
1419 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1420 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001421 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001422 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1423 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_EQ(ext1.uri, ext2.uri);
1425 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001426 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 }
1429
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001430 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1431 const std::vector<std::string>& ids) {
1432 // Order of elements does not matter, only equivalence of sets.
1433 EXPECT_EQ(rids.size(), ids.size());
1434 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001435 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1436 return rid.rid == id;
1437 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001438 }
1439 }
1440
Amit Hilbucha2012042018-12-03 11:35:05 -08001441 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1442 const SimulcastDescription& simulcast2) {
1443 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1444 EXPECT_EQ(simulcast1.receive_layers().size(),
1445 simulcast2.receive_layers().size());
1446 }
1447
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001448 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1449 const RtpDataContentDescription* dcd2) {
1450 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1451 }
1452
1453 void CompareSctpDataContentDescription(
1454 const SctpDataContentDescription* dcd1,
1455 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001456 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001457 EXPECT_EQ(dcd1->port(), dcd2->port());
1458 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001459 }
1460
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 void CompareSessionDescription(const SessionDescription& desc1,
1462 const SessionDescription& desc2) {
1463 // Compare content descriptions.
1464 if (desc1.contents().size() != desc2.contents().size()) {
1465 ADD_FAILURE();
1466 return;
1467 }
Yves Gerey665174f2018-06-19 15:03:05 +02001468 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1470 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001471 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001473 EXPECT_EQ(c1.type, c2.type);
1474 EXPECT_EQ(c1.rejected, c2.rejected);
1475 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476
1477 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1478 if (IsAudioContent(&c1)) {
1479 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001480 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001482 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1484 }
1485
1486 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1487 if (IsVideoContent(&c1)) {
1488 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001489 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001491 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1493 }
1494
1495 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001496 if (c1.media_description()->as_sctp()) {
1497 ASSERT_TRUE(c2.media_description()->as_sctp());
1498 const SctpDataContentDescription* scd1 =
1499 c1.media_description()->as_sctp();
1500 const SctpDataContentDescription* scd2 =
1501 c2.media_description()->as_sctp();
1502 CompareSctpDataContentDescription(scd1, scd2);
1503 } else {
1504 if (IsDataContent(&c1)) {
1505 const RtpDataContentDescription* dcd1 =
1506 c1.media_description()->as_rtp_data();
1507 const RtpDataContentDescription* dcd2 =
1508 c2.media_description()->as_rtp_data();
1509 CompareRtpDataContentDescription(dcd1, dcd2);
1510 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001512
1513 CompareSimulcastDescription(
1514 c1.media_description()->simulcast_description(),
1515 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 }
1517
1518 // group
1519 const cricket::ContentGroups groups1 = desc1.groups();
1520 const cricket::ContentGroups groups2 = desc2.groups();
1521 EXPECT_EQ(groups1.size(), groups1.size());
1522 if (groups1.size() != groups2.size()) {
1523 ADD_FAILURE();
1524 return;
1525 }
1526 for (size_t i = 0; i < groups1.size(); ++i) {
1527 const cricket::ContentGroup group1 = groups1.at(i);
1528 const cricket::ContentGroup group2 = groups2.at(i);
1529 EXPECT_EQ(group1.semantics(), group2.semantics());
1530 const cricket::ContentNames names1 = group1.content_names();
1531 const cricket::ContentNames names2 = group2.content_names();
1532 EXPECT_EQ(names1.size(), names2.size());
1533 if (names1.size() != names2.size()) {
1534 ADD_FAILURE();
1535 return;
1536 }
1537 cricket::ContentNames::const_iterator iter1 = names1.begin();
1538 cricket::ContentNames::const_iterator iter2 = names2.begin();
1539 while (iter1 != names1.end()) {
1540 EXPECT_EQ(*iter1++, *iter2++);
1541 }
1542 }
1543
1544 // transport info
1545 const cricket::TransportInfos transports1 = desc1.transport_infos();
1546 const cricket::TransportInfos transports2 = desc2.transport_infos();
1547 EXPECT_EQ(transports1.size(), transports2.size());
1548 if (transports1.size() != transports2.size()) {
1549 ADD_FAILURE();
1550 return;
1551 }
1552 for (size_t i = 0; i < transports1.size(); ++i) {
1553 const cricket::TransportInfo transport1 = transports1.at(i);
1554 const cricket::TransportInfo transport2 = transports2.at(i);
1555 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 EXPECT_EQ(transport1.description.ice_ufrag,
1557 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001558 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001559 EXPECT_EQ(transport1.description.ice_mode,
1560 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 if (transport1.description.identity_fingerprint) {
1562 EXPECT_EQ(*transport1.description.identity_fingerprint,
1563 *transport2.description.identity_fingerprint);
1564 } else {
1565 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1566 transport2.description.identity_fingerprint.get());
1567 }
1568 EXPECT_EQ(transport1.description.transport_options,
1569 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 }
deadbeefc80741f2015-10-22 13:14:45 -07001571
1572 // global attributes
1573 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001574 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 }
1576
Yves Gerey665174f2018-06-19 15:03:05 +02001577 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1578 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1580 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1581 CompareSessionDescription(*desc1.description(), *desc2.description());
1582 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1583 return false;
1584 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1585 const IceCandidateCollection* cc1 = desc1.candidates(i);
1586 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001587 if (cc1->count() != cc2->count()) {
1588 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001590 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 for (size_t j = 0; j < cc1->count(); ++j) {
1592 const IceCandidateInterface* c1 = cc1->at(j);
1593 const IceCandidateInterface* c2 = cc2->at(j);
1594 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1595 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1596 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1597 }
1598 }
1599 return true;
1600 }
1601
1602 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1603 // them with invalid keywords so that the parser will just ignore them.
1604 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001605 absl::StrReplaceAll(
1606 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 return true;
1608 }
1609
1610 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001611 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1612 int mline_index,
1613 const std::string& ufrag,
1614 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 std::string content_name;
1616 if (mline_index == 0) {
1617 content_name = kAudioContentName;
1618 } else if (mline_index == 1) {
1619 content_name = kVideoContentName;
1620 } else {
nissec80e7412017-01-11 05:56:46 -08001621 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 }
Yves Gerey665174f2018-06-19 15:03:05 +02001623 TransportInfo transport_info(content_name,
1624 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 SessionDescription* desc =
1626 const_cast<SessionDescription*>(jdesc->description());
1627 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001628 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1630 const IceCandidateCollection* cc = jdesc_.candidates(i);
1631 for (size_t j = 0; j < cc->count(); ++j) {
1632 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001633 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1634 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 }
1636 }
1637 }
1638 return true;
1639 }
1640
1641 void AddIceOptions(const std::string& content_name,
1642 const std::vector<std::string>& transport_options) {
1643 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1644 cricket::TransportInfo transport_info =
1645 *(desc_.GetTransportInfoByName(content_name));
1646 desc_.RemoveTransportInfoByName(content_name);
1647 transport_info.description.transport_options = transport_options;
1648 desc_.AddTransportInfo(transport_info);
1649 }
1650
deadbeef3f7219b2015-12-28 15:17:14 -08001651 void SetIceUfragPwd(const std::string& content_name,
1652 const std::string& ice_ufrag,
1653 const std::string& ice_pwd) {
1654 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1655 cricket::TransportInfo transport_info =
1656 *(desc_.GetTransportInfoByName(content_name));
1657 desc_.RemoveTransportInfoByName(content_name);
1658 transport_info.description.ice_ufrag = ice_ufrag;
1659 transport_info.description.ice_pwd = ice_pwd;
1660 desc_.AddTransportInfo(transport_info);
1661 }
1662
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 void AddFingerprint() {
1664 desc_.RemoveTransportInfoByName(kAudioContentName);
1665 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001666 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001667 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001668 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001669 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1670 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001671 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1672 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001673 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001674 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1675 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001676 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 }
1678
jbauch5869f502017-06-29 12:31:36 -07001679 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001680 audio_desc_ = audio_desc_->Copy();
1681 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001682 audio_desc_->AddRtpHeaderExtension(
1683 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1684 video_desc_->AddRtpHeaderExtension(
1685 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 desc_.RemoveContentByName(kAudioContentName);
1687 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001688 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1689 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 }
1691
1692 void RemoveCryptos() {
1693 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1694 video_desc_->set_cryptos(std::vector<CryptoParams>());
1695 }
1696
Seth Hampson5897a6e2018-04-03 11:16:33 -07001697 // Removes everything in StreamParams from the session description that is
1698 // used for a=ssrc lines.
1699 void RemoveSsrcSignalingFromStreamParams() {
1700 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1701 // With Unified Plan there should be one StreamParams per m= section.
1702 StreamParams& stream =
1703 content_info.media_description()->mutable_streams()[0];
1704 stream.ssrcs.clear();
1705 stream.ssrc_groups.clear();
1706 stream.cname.clear();
1707 }
1708 }
1709
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001710 // Removes all a=ssrc lines from the SDP string, except for the
1711 // "a=ssrc:... cname:..." lines.
1712 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1713 const char kAttributeSsrc[] = "a=ssrc";
1714 const char kAttributeCname[] = "cname";
1715 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1716 while (ssrc_line_pos != std::string::npos) {
1717 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1718 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1719 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1720 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1721 // Only erase a=ssrc lines that don't contain "cname".
1722 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1723 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1724 } else {
1725 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1726 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1727 }
1728 }
1729 }
1730
Seth Hampson5897a6e2018-04-03 11:16:33 -07001731 // Removes all a=ssrc lines from the SDP string.
1732 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1733 const char kAttributeSsrc[] = "a=ssrc";
1734 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1735 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1736 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1737 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1738 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1739 }
1740 }
1741
Steve Anton4e70a722017-11-28 14:57:10 -08001742 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 audio_desc_->set_direction(direction);
1744 video_desc_->set_direction(direction);
1745 std::string new_sdp = kSdpFullString;
1746 ReplaceDirection(direction, &new_sdp);
1747
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001748 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 jdesc_.session_version())) {
1750 return false;
1751 }
Steve Antone831b8c2018-02-01 12:22:16 -08001752 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 EXPECT_EQ(new_sdp, message);
1754 return true;
1755 }
1756
1757 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001758 audio_desc_ = audio_desc_->Copy();
1759 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001760
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 desc_.RemoveContentByName(kAudioContentName);
1762 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001763 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001765 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001767 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1768 audio_rejected ? "" : kPwdVoice);
1769 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1770 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001771
1772 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1774
Steve Antona3a92c22017-12-07 10:27:41 -08001775 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001776 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001777 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 EXPECT_EQ(new_sdp, message);
1779 return true;
1780 }
1781
zstein4b2e0822017-02-17 19:48:38 -08001782 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001783 std::unique_ptr<SctpDataContentDescription> data(
1784 new SctpDataContentDescription());
1785 sctp_desc_ = data.get();
1786 sctp_desc_->set_use_sctpmap(use_sctpmap);
Harald Alvestrandc3f48202019-05-14 17:27:11 +02001787 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001788 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001789 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1790 data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001791 desc_.AddTransportInfo(TransportInfo(
1792 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 }
1794
1795 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001796 std::unique_ptr<RtpDataContentDescription> data(
1797 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 data_desc_ = data.get();
1799
deadbeef67cf2c12016-04-13 10:07:16 -07001800 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 StreamParams data_stream;
1802 data_stream.id = kDataChannelMsid;
1803 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001804 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 data_stream.ssrcs.push_back(kDataChannelSsrc);
1806 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001807 data_desc_->AddCrypto(
1808 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1809 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001811 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001812 desc_.AddTransportInfo(TransportInfo(
1813 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 }
1815
Steve Anton4e70a722017-11-28 14:57:10 -08001816 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 std::string new_sdp = kSdpFullString;
1818 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001819 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820
1821 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1822
1823 audio_desc_->set_direction(direction);
1824 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001825 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 jdesc_.session_version())) {
1827 return false;
1828 }
1829 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1830 return true;
1831 }
1832
1833 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001834 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001836 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001838
Steve Antonb1c1de12017-12-21 15:14:30 -08001839 audio_desc_ = audio_desc_->Copy();
1840 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 desc_.RemoveContentByName(kAudioContentName);
1842 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001843 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001845 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001847 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1848 audio_rejected ? "" : kPwdVoice);
1849 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1850 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001851 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001852 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001853 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 return false;
1855 }
deadbeef3f7219b2015-12-28 15:17:14 -08001856 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 return true;
1858 }
1859
Yves Gerey665174f2018-06-19 15:03:05 +02001860 void TestDeserializeExtmap(bool session_level,
1861 bool media_level,
1862 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001863 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001864 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001865 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001867 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 std::string sdp_with_extmap = kSdpString;
1869 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001870 InjectAfter(kSessionTime,
1871 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1872 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 &sdp_with_extmap);
1874 }
1875 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001876 InjectAfter(kAttributeIcePwdVoice,
1877 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1878 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001880 InjectAfter(kAttributeIcePwdVideo,
1881 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1882 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 &sdp_with_extmap);
1884 }
1885 // The extmap can't be present at the same time in both session level and
1886 // media level.
1887 if (session_level && media_level) {
1888 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001889 EXPECT_FALSE(
1890 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1892 } else {
1893 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1894 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1895 }
1896 }
1897
1898 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001899 const std::string& name,
1900 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 cricket::CodecParameterMap::const_iterator found = params.find(name);
1902 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001903 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 }
1905
1906 void TestDeserializeCodecParams(const CodecParams& params,
1907 JsepSessionDescription* jdesc_output) {
1908 std::string sdp =
1909 "v=0\r\n"
1910 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1911 "s=-\r\n"
1912 "t=0 0\r\n"
1913 // Include semantics for WebRTC Media Streams since it is supported by
1914 // this parser, and will be added to the SDP when serializing a session
1915 // description.
1916 "a=msid-semantic: WMS\r\n"
1917 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001918 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 // Pltype 111 listed before 103 and 104 in the map.
1920 "a=rtpmap:111 opus/48000/2\r\n"
1921 // Pltype 103 listed before 104.
1922 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001923 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001924 "a=fmtp:111 0-15,66,70\r\n"
1925 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001927 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001928 << "; sprop-stereo=" << params.sprop_stereo
1929 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001930 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 << "a=ptime:" << params.ptime << "\r\n"
1932 << "a=maxptime:" << params.max_ptime << "\r\n";
1933 sdp += os.str();
1934
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001935 os.clear();
1936 os.str("");
1937 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001938 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001939 << "a=rtpmap:99 VP8/90000\r\n"
1940 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001941 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001942 sdp += os.str();
1943
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 // Deserialize
1945 SdpParseError error;
1946 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1947
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001949 GetFirstAudioContentDescription(jdesc_output->description());
1950 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 ASSERT_FALSE(acd->codecs().empty());
1952 cricket::AudioCodec opus = acd->codecs()[0];
1953 EXPECT_EQ("opus", opus.name);
1954 EXPECT_EQ(111, opus.id);
1955 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1956 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1957 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1958 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001959 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1960 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1962 cricket::AudioCodec codec = acd->codecs()[i];
1963 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1964 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001966
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001967 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001968 GetFirstVideoContentDescription(jdesc_output->description());
1969 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001970 ASSERT_FALSE(vcd->codecs().empty());
1971 cricket::VideoCodec vp8 = vcd->codecs()[0];
1972 EXPECT_EQ("VP8", vp8.name);
1973 EXPECT_EQ(99, vp8.id);
1974 cricket::VideoCodec rtx = vcd->codecs()[1];
1975 EXPECT_EQ("RTX", rtx.name);
1976 EXPECT_EQ(95, rtx.id);
1977 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 }
1979
1980 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1981 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001982 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 "v=0\r\n"
1984 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1985 "s=-\r\n"
1986 "t=0 0\r\n"
1987 // Include semantics for WebRTC Media Streams since it is supported by
1988 // this parser, and will be added to the SDP when serializing a session
1989 // description.
1990 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001991 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001992 "a=rtpmap:111 opus/48000/2\r\n";
1993 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 "m=video 3457 RTP/SAVPF 101\r\n"
1995 "a=rtpmap:101 VP8/90000\r\n"
1996 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001997 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001998 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002000 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02002001 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002002 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002003 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002004 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 // Deserialize
2006 SdpParseError error;
2007 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002009 GetFirstAudioContentDescription(jdesc_output->description());
2010 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 ASSERT_FALSE(acd->codecs().empty());
2012 cricket::AudioCodec opus = acd->codecs()[0];
2013 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002014 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2015 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002018 GetFirstVideoContentDescription(jdesc_output->description());
2019 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 ASSERT_FALSE(vcd->codecs().empty());
2021 cricket::VideoCodec vp8 = vcd->codecs()[0];
2022 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2023 vp8.name.c_str());
2024 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002025 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2026 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2027 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2028 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2029 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2030 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2031 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2032 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 }
2034
2035 // Two SDP messages can mean the same thing but be different strings, e.g.
2036 // some of the lines can be serialized in different order.
2037 // However, a deserialized description can be compared field by field and has
2038 // no order. If deserializer has already been tested, serializing then
2039 // deserializing and comparing JsepSessionDescription will test
2040 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002041 void TestSerialize(const JsepSessionDescription& jdesc) {
2042 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002043 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 SdpParseError error;
2045 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2046 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2047 }
2048
zhihuang38989e52017-03-21 11:04:53 -07002049 // Calling 'Initialize' with a copy of the inner SessionDescription will
2050 // create a copy of the JsepSessionDescription without candidates. The
2051 // 'connection address' field, previously set from the candidates, must also
2052 // be reset.
2053 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2054 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2055 rtc::SocketAddress video_addr("0.0.0.0", 9);
2056 audio_desc_->set_connection_address(audio_addr);
2057 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002058 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002059 }
2060
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 protected:
2062 SessionDescription desc_;
2063 AudioContentDescription* audio_desc_;
2064 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002065 RtpDataContentDescription* data_desc_;
2066 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002068 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 JsepSessionDescription jdesc_;
2070};
2071
2072void TestMismatch(const std::string& string1, const std::string& string2) {
2073 int position = 0;
2074 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2075 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002076 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 break;
2078 }
2079 }
2080 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2081 << " character\n"
2082 << " 1: " << string1.substr(position, 20) << "\n"
2083 << " 2: " << string2.substr(position, 20) << "\n";
2084}
2085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2087 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002088 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 TestMismatch(std::string(kSdpFullString), message);
2090}
2091
2092TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002093 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002094 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2098// the case in a DTLS offer.
2099TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2100 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002101 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002102 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002103 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
2105 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002106 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2107 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 EXPECT_EQ(sdp_with_fingerprint, message);
2110}
2111
2112// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2113// be the case in a DTLS answer.
2114TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2115 AddFingerprint();
2116 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002117 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002118 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002119 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 std::string sdp_with_fingerprint = kSdpString;
2122 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2123 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002124 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2125 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
2127 EXPECT_EQ(sdp_with_fingerprint, message);
2128}
2129
2130TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2131 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002132 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002133 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002134 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 EXPECT_EQ(std::string(kSdpString), message);
2136}
2137
2138TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2139 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2140 group.AddContentName(kAudioContentName);
2141 group.AddContentName(kVideoContentName);
2142 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002143 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002145 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 std::string sdp_with_bundle = kSdpFullString;
2147 InjectAfter(kSessionTime,
2148 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2149 &sdp_with_bundle);
2150 EXPECT_EQ(sdp_with_bundle, message);
2151}
2152
2153TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002154 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002156 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002158 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002160 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002162 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002164 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 &sdp_with_bandwidth);
2166 EXPECT_EQ(sdp_with_bandwidth, message);
2167}
2168
2169TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2170 std::vector<std::string> transport_options;
2171 transport_options.push_back(kIceOption1);
2172 transport_options.push_back(kIceOption3);
2173 AddIceOptions(kAudioContentName, transport_options);
2174 transport_options.clear();
2175 transport_options.push_back(kIceOption2);
2176 transport_options.push_back(kIceOption3);
2177 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002178 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002180 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002182 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002184 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 &sdp_with_ice_options);
2186 EXPECT_EQ(sdp_with_ice_options, message);
2187}
2188
2189TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002190 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191}
2192
2193TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002194 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195}
2196
2197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002198 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199}
2200
2201TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2202 EXPECT_TRUE(TestSerializeRejected(true, false));
2203}
2204
2205TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2206 EXPECT_TRUE(TestSerializeRejected(false, true));
2207}
2208
2209TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2210 EXPECT_TRUE(TestSerializeRejected(true, true));
2211}
2212
2213TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2214 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002215 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216
zhihuang38989e52017-03-21 11:04:53 -07002217 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002218 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219
2220 std::string expected_sdp = kSdpString;
2221 expected_sdp.append(kSdpRtpDataChannelString);
2222 EXPECT_EQ(expected_sdp, message);
2223}
2224
2225TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002226 bool use_sctpmap = true;
2227 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002228 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229
zhihuang38989e52017-03-21 11:04:53 -07002230 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002231 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232
2233 std::string expected_sdp = kSdpString;
2234 expected_sdp.append(kSdpSctpDataChannelString);
2235 EXPECT_EQ(message, expected_sdp);
2236}
2237
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002238void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2239 const SessionDescription& desc,
2240 int port) {
2241 // Take our pre-built session description and change the SCTP port.
2242 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2243 SctpDataContentDescription* dcdesc =
2244 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2245 dcdesc->set_port(port);
2246 ASSERT_TRUE(
2247 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2248}
2249
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002250TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002251 bool use_sctpmap = true;
2252 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002253 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002254 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002255
2256 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002257 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002258
Steve Antone831b8c2018-02-01 12:22:16 -08002259 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002260
2261 std::string expected_sdp = kSdpString;
2262 expected_sdp.append(kSdpSctpDataChannelString);
2263
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002264 absl::StrReplaceAll(
2265 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2266 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002267
2268 EXPECT_EQ(expected_sdp, message);
2269}
2270
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002271TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002272 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002273 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002274 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002275 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002276 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002277
2278 std::string expected_sdp = kSdpString;
2279 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002280 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002281 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002282 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002283 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002284}
2285
Johannes Kron0854eb62018-10-10 22:33:20 +02002286TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002287 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002288 TestSerialize(jdesc_);
2289}
2290
2291TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2292 cricket::MediaContentDescription* video_desc =
2293 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2294 ASSERT_TRUE(video_desc);
2295 cricket::MediaContentDescription* audio_desc =
2296 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2297 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002298 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002299 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002300 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002301 cricket::MediaContentDescription::kMedia);
2302 TestSerialize(jdesc_);
2303}
2304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002306 bool encrypted = false;
2307 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002308 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002309 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002310 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002313 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2314 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315
2316 EXPECT_EQ(sdp_with_extmap, message);
2317}
2318
jbauch5869f502017-06-29 12:31:36 -07002319TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2320 bool encrypted = true;
2321 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002322 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002323 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002324 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002325 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002326}
2327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328TEST_F(WebRtcSdpTest, SerializeCandidates) {
2329 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002330 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002331
2332 Candidate candidate_with_ufrag(candidates_.front());
2333 candidate_with_ufrag.set_username("ABC");
2334 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2335 candidate_with_ufrag));
2336 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2337 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002338
2339 Candidate candidate_with_network_info(candidates_.front());
2340 candidate_with_network_info.set_network_id(1);
2341 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2342 candidate_with_network_info));
2343 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2344 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2345 candidate_with_network_info.set_network_cost(999);
2346 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2347 candidate_with_network_info));
2348 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2349 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2350 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351}
2352
Zach Steinb336c272018-08-09 01:16:13 -07002353TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2354 rtc::SocketAddress address("a.test", 1234);
2355 cricket::Candidate candidate(
2356 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2357 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2358 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2359 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2360 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2361}
2362
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002363// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2364// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002365TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002366 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002367 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2368 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2369 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002370 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002371 std::unique_ptr<IceCandidateInterface> jcandidate(
2372 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002373
2374 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2375 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2376}
2377
htaa6b99442016-04-12 10:29:17 -07002378TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002379 cricket::VideoCodec h264_codec("H264");
2380 h264_codec.SetParam("profile-level-id", "42e01f");
2381 h264_codec.SetParam("level-asymmetry-allowed", "1");
2382 h264_codec.SetParam("packetization-mode", "1");
2383 video_desc_->AddCodec(h264_codec);
2384
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002385 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002386
Steve Antone831b8c2018-02-01 12:22:16 -08002387 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002388 size_t after_pt = message.find(" H264/90000");
2389 ASSERT_NE(after_pt, std::string::npos);
2390 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2391 ASSERT_NE(before_pt, std::string::npos);
2392 before_pt += strlen("a=rtpmap:");
2393 std::string pt = message.substr(before_pt, after_pt - before_pt);
2394 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2395 std::string to_find = "a=fmtp:" + pt + " ";
2396 size_t fmtp_pos = message.find(to_find);
2397 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002398 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002399 ASSERT_NE(std::string::npos, fmtp_endpos);
2400 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2401 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2402 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2403 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002404 // Check that there are no spaces after semicolons.
2405 // https://bugs.webrtc.org/5793
2406 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002407}
2408
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002410 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 // Deserialize
2412 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2413 // Verify
2414 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2415}
2416
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002417TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002418 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002419 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002420 "v=0\r\n"
2421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2422 "s=-\r\n"
2423 "t=0 0\r\n"
2424 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002425 // Deserialize
2426 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2427 EXPECT_EQ(0u, jdesc.description()->contents().size());
2428}
2429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002431 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 std::string sdp_without_carriage_return = kSdpFullString;
2433 Replace("\r\n", "\n", &sdp_without_carriage_return);
2434 // Deserialize
2435 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2436 // Verify
2437 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2438}
2439
2440TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2441 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002442 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002443 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002444 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002445 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2447 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2448}
2449
2450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2451 static const char kSdpNoRtpmapString[] =
2452 "v=0\r\n"
2453 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2454 "s=-\r\n"
2455 "t=0 0\r\n"
2456 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2457 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002458 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 // The rtpmap line for static payload codec is optional.
2460 "a=rtpmap:18 G729/16000\r\n"
2461 "a=rtpmap:103 ISAC/16000\r\n";
2462
Steve Antona3a92c22017-12-07 10:27:41 -08002463 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2465 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002466 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002468 // The codecs in the AudioContentDescription should be in the same order as
2469 // the payload types (<fmt>s) on the m= line.
2470 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2471 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002472 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 EXPECT_EQ(ref_codecs, audio->codecs());
2474}
2475
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002476TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2477 static const char kSdpNoRtpmapString[] =
2478 "v=0\r\n"
2479 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2480 "s=-\r\n"
2481 "t=0 0\r\n"
2482 "m=audio 49232 RTP/AVP 18 103\r\n"
2483 "a=fmtp:18 annexb=yes\r\n"
2484 "a=rtpmap:103 ISAC/16000\r\n";
2485
Steve Antona3a92c22017-12-07 10:27:41 -08002486 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002487 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2488 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002489 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002490
2491 cricket::AudioCodec g729 = audio->codecs()[0];
2492 EXPECT_EQ("G729", g729.name);
2493 EXPECT_EQ(8000, g729.clockrate);
2494 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002495 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002496 ASSERT_TRUE(found != g729.params.end());
2497 EXPECT_EQ(found->second, "yes");
2498
2499 cricket::AudioCodec isac = audio->codecs()[1];
2500 EXPECT_EQ("ISAC", isac.name);
2501 EXPECT_EQ(103, isac.id);
2502 EXPECT_EQ(16000, isac.clockrate);
2503}
2504
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505// Ensure that we can deserialize SDP with a=fingerprint properly.
2506TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2507 // Add a DTLS a=fingerprint attribute to our session description.
2508 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002509 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002510 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 jdesc_.session_version()));
2512
Steve Antona3a92c22017-12-07 10:27:41 -08002513 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 std::string sdp_with_fingerprint = kSdpString;
2515 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2516 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2517 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2518 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2519}
2520
2521TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002522 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 std::string sdp_with_bundle = kSdpFullString;
2524 InjectAfter(kSessionTime,
2525 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2526 &sdp_with_bundle);
2527 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2528 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2529 group.AddContentName(kAudioContentName);
2530 group.AddContentName(kVideoContentName);
2531 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002532 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 jdesc_.session_version()));
2534 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2535}
2536
2537TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002538 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002540 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002542 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002544 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002545 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002547 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002549 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 jdesc_.session_version()));
2551 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2552}
2553
2554TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002555 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002557 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002559 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002561 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 &sdp_with_ice_options);
2563 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2564 std::vector<std::string> transport_options;
2565 transport_options.push_back(kIceOption3);
2566 transport_options.push_back(kIceOption1);
2567 AddIceOptions(kAudioContentName, transport_options);
2568 transport_options.clear();
2569 transport_options.push_back(kIceOption3);
2570 transport_options.push_back(kIceOption2);
2571 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002572 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 jdesc_.session_version()));
2574 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2575}
2576
2577TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2578 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002579 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580 std::string sdp_with_ufrag_pwd = kSdpFullString;
2581 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2582 // Add session level ufrag and pwd
2583 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002584 "a=ice-pwd:session+level+icepwd\r\n"
2585 "a=ice-ufrag:session+level+iceufrag\r\n",
2586 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002588 InjectAfter(
2589 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2591 &sdp_with_ufrag_pwd);
2592 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002593 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2594 "media+level+icepwd"));
2595 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2596 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2598 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2599}
2600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002602 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603}
2604
2605TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002606 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607}
2608
2609TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002610 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611}
2612
2613TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2614 EXPECT_TRUE(TestDeserializeRejected(true, false));
2615}
2616
2617TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2618 EXPECT_TRUE(TestDeserializeRejected(false, true));
2619}
2620
2621TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2622 EXPECT_TRUE(TestDeserializeRejected(true, true));
2623}
2624
2625// Tests that we can still handle the sdp uses mslabel and label instead of
2626// msid for backward compatibility.
2627TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002628 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002629 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 std::string sdp_without_msid = kSdpFullString;
2631 Replace("msid", "xmsid", &sdp_without_msid);
2632 // Deserialize
2633 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2634 // Verify
2635 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002636 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2637 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638}
2639
Johannes Kron0854eb62018-10-10 22:33:20 +02002640TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002641 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002642 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2643 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2644 // Deserialize
2645 JsepSessionDescription jdesc_deserialized(kDummyType);
2646 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2647 // Verify
2648 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2649}
2650
2651TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002652 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002653 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2654 // Deserialize
2655 JsepSessionDescription jdesc_deserialized(kDummyType);
2656 EXPECT_TRUE(
2657 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2658 // Verify
2659 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2660}
2661
2662TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2663 cricket::MediaContentDescription* video_desc =
2664 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2665 ASSERT_TRUE(video_desc);
2666 cricket::MediaContentDescription* audio_desc =
2667 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2668 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002669 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002670 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002671 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002672 cricket::MediaContentDescription::kMedia);
2673
2674 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2675 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2676 &sdp_with_extmap_allow_mixed);
2677 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2678 &sdp_with_extmap_allow_mixed);
2679
2680 // Deserialize
2681 JsepSessionDescription jdesc_deserialized(kDummyType);
2682 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2683 // Verify
2684 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2685}
2686
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2688 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2689
2690 std::string sdp = kSdpOneCandidate;
2691 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2692 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2693 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2694 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002695 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696
2697 // Candidate line without generation extension.
2698 sdp = kSdpOneCandidate;
2699 Replace(" generation 2", "", &sdp);
2700 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2701 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2702 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2703 Candidate expected = jcandidate_->candidate();
2704 expected.set_generation(0);
2705 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2706
honghaiza0c44ea2016-03-23 16:07:48 -07002707 // Candidate with network id and/or cost.
2708 sdp = kSdpOneCandidate;
2709 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2710 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2711 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2712 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2713 expected = jcandidate_->candidate();
2714 expected.set_network_id(2);
2715 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2716 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2717 // Add network cost
2718 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2719 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2720 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2721 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2722
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002723 sdp = kSdpTcpActiveCandidate;
2724 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2725 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002726 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002727 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2728 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2729 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002730 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2731 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002732 EXPECT_TRUE(
2733 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002734 sdp = kSdpTcpPassiveCandidate;
2735 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2736 sdp = kSdpTcpSOCandidate;
2737 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738}
2739
2740// This test verifies the deserialization of candidate-attribute
2741// as per RFC 5245. Candiate-attribute will be of the format
2742// candidate:<blah>. This format will be used when candidates
2743// are trickled.
2744TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2745 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2746
2747 std::string candidate_attribute = kRawCandidate;
2748 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2749 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2750 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2751 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2752 EXPECT_EQ(2u, jcandidate.candidate().generation());
2753
2754 // Candidate line without generation extension.
2755 candidate_attribute = kRawCandidate;
2756 Replace(" generation 2", "", &candidate_attribute);
2757 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2758 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2759 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2760 Candidate expected = jcandidate_->candidate();
2761 expected.set_generation(0);
2762 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2763
2764 // Candidate line without candidate:
2765 candidate_attribute = kRawCandidate;
2766 Replace("candidate:", "", &candidate_attribute);
2767 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2768
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002769 // Candidate line with IPV6 address.
2770 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002771
2772 // Candidate line with hostname address.
2773 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002774}
2775
2776// This test verifies that the deserialization of an invalid candidate string
2777// fails.
2778TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002779 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002780
2781 std::string candidate_attribute = kRawCandidate;
2782 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002784
2785 candidate_attribute = kSdpOneCandidate;
2786 candidate_attribute.replace(0, 1, "x");
2787 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2788
2789 candidate_attribute = kRawCandidate;
2790 candidate_attribute.append("\r\n");
2791 candidate_attribute.append(kRawCandidate);
2792 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2793
2794 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795}
2796
2797TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2798 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002799 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002800 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002801
2802 std::string sdp_with_data = kSdpString;
2803 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002804 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805
2806 // Deserialize
2807 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2808 // Verify
2809 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2810}
2811
2812TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002813 bool use_sctpmap = true;
2814 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002815 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002816 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817
2818 std::string sdp_with_data = kSdpString;
2819 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002820 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821
Harald Alvestrandc3f48202019-05-14 17:27:11 +02002822 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002823 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2824 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2825
Harald Alvestrandc3f48202019-05-14 17:27:11 +02002826 // Verify with DTLS/SCTP.
2827 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2828 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002829 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2830 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2831
2832 // Verify with TCP/DTLS/SCTP.
Harald Alvestrandc3f48202019-05-14 17:27:11 +02002833 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002834 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2836 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2837}
2838
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002839TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002840 bool use_sctpmap = false;
2841 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002842 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002843 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002844
2845 std::string sdp_with_data = kSdpString;
2846 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002847 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002848
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002849 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2850 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2851}
2852
lally69f57602015-10-08 10:15:04 -07002853TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002854 bool use_sctpmap = false;
2855 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002856 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002857 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002858
2859 std::string sdp_with_data = kSdpString;
2860 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002861 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002862
lally69f57602015-10-08 10:15:04 -07002863 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2864 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2865}
2866
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002867// Helper function to set the max-message-size parameter in the
2868// SCTP data codec.
2869void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002870 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002871 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002872 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002873 SctpDataContentDescription* dcdesc =
2874 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2875 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002876 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002877}
2878
2879TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2880 bool use_sctpmap = false;
2881 AddSctpDataChannel(use_sctpmap);
2882 JsepSessionDescription jdesc(kDummyType);
2883 std::string sdp_with_data = kSdpString;
2884
2885 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2886 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002887 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002888 JsepSessionDescription jdesc_output(kDummyType);
2889
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002890 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2891 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2892}
2893
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002894// Test to check the behaviour if sctp-port is specified
2895// on the m= line and in a=sctp-port.
2896TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002897 bool use_sctpmap = true;
2898 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002899 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002900 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002901
2902 std::string sdp_with_data = kSdpString;
2903 // Append m= attributes
2904 sdp_with_data.append(kSdpSctpDataChannelString);
2905 // Append a=sctp-port attribute
2906 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002907 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002908
2909 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2910}
2911
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002912// Test behavior if a=rtpmap occurs in an SCTP section.
2913TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
2914 std::string sdp_with_data = kSdpString;
2915 // Append m= attributes
2916 sdp_with_data.append(kSdpSctpDataChannelString);
2917 // Append a=rtpmap attribute
2918 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
2919 JsepSessionDescription jdesc_output(kDummyType);
2920 // Correct behavior is to ignore the extra attribute.
2921 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2922}
2923
2924TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
2925 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
2926 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
2927 for (auto proto : bad_strings) {
2928 std::string sdp_with_data = kSdpString;
2929 sdp_with_data.append("m=application 9 ");
2930 sdp_with_data.append(proto);
2931 sdp_with_data.append(" 47\r\n");
2932 JsepSessionDescription jdesc_output(kDummyType);
2933 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
2934 << "Parsing should have failed on " << proto;
2935 }
2936 // The following strings are strange, but acceptable as RTP.
2937 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
2938 "obviously-bogus/RTP/"};
2939 for (auto proto : weird_strings) {
2940 std::string sdp_with_data = kSdpString;
2941 sdp_with_data.append("m=application 9 ");
2942 sdp_with_data.append(proto);
2943 sdp_with_data.append(" 47\r\n");
2944 JsepSessionDescription jdesc_output(kDummyType);
2945 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
2946 << "Parsing should have succeeded on " << proto;
2947 }
2948}
2949
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002950// For crbug/344475.
2951TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2952 std::string sdp_with_data = kSdpString;
2953 sdp_with_data.append(kSdpSctpDataChannelString);
2954 // Remove the "\n" at the end.
2955 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002956 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002957
2958 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2959 // No crash is a pass.
2960}
2961
zstein4b2e0822017-02-17 19:48:38 -08002962TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2963 bool use_sctpmap = true;
2964 AddSctpDataChannel(use_sctpmap);
2965
2966 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002967 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002968 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00002969
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002970 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002971 std::string sdp_with_data = kSdpString;
2972 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002973 absl::StrReplaceAll(
2974 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2975 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002976 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002977
2978 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2979 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002980}
2981
2982TEST_F(WebRtcSdpTest,
2983 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2984 bool use_sctpmap = false;
2985 AddSctpDataChannel(use_sctpmap);
2986
Steve Antona3a92c22017-12-07 10:27:41 -08002987 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002988 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002989
2990 // We need to test the deserialized JsepSessionDescription from
2991 // kSdpSctpDataChannelStringWithSctpPort for
2992 // draft-ietf-mmusic-sctp-sdp-07
2993 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002994 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002995 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002996 absl::StrReplaceAll(
2997 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2998 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002999 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003000
3001 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3002 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003003}
3004
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003005TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003006 // We want to test that deserializing data content limits bandwidth
3007 // settings (it should never be greater than the default).
3008 // This should prevent someone from using unlimited data bandwidth through
3009 // JS and "breaking the Internet".
3010 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003011 std::string sdp_with_bandwidth = kSdpString;
3012 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003013 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003014 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003015 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003016
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003017 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3018}
3019
3020TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003021 bool use_sctpmap = true;
3022 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003023 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003024 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003025 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003026 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003027
3028 std::string sdp_with_bandwidth = kSdpString;
3029 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003030 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003031 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003032 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003033
3034 // SCTP has congestion control, so we shouldn't limit the bandwidth
3035 // as we do for RTP.
3036 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003037 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3038}
3039
Yves Gerey665174f2018-06-19 15:03:05 +02003040class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003041 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003042
3043TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003044 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003045 bool encrypted = GetParam();
3046 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047}
3048
Yves Gerey665174f2018-06-19 15:03:05 +02003049TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003050 bool encrypted = GetParam();
3051 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052}
3053
Yves Gerey665174f2018-06-19 15:03:05 +02003054TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003055 bool encrypted = GetParam();
3056 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057}
3058
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003059INSTANTIATE_TEST_SUITE_P(Encrypted,
3060 WebRtcSdpExtmapTest,
3061 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003062
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003063TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003064 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003065 std::string sdp = kSdpFullString;
3066 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3067 // Deserialize
3068 SdpParseError error;
3069 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003070 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003071 EXPECT_EQ(lastline, error.line);
3072 EXPECT_EQ("Invalid SDP line.", error.description);
3073}
3074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3076 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3077 std::string new_sdp = kSdpOneCandidate;
3078 Replace("udp", "unsupported_transport", &new_sdp);
3079 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3080 new_sdp = kSdpOneCandidate;
3081 Replace("udp", "uDP", &new_sdp);
3082 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3083 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3084 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3085 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3086}
3087
honghaiza54a0802015-12-16 18:37:23 -08003088TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003090 EXPECT_TRUE(
3091 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3093 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3094 Candidate ref_candidate = jcandidate_->candidate();
3095 ref_candidate.set_username("user_rtp");
3096 ref_candidate.set_password("password_rtp");
3097 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3098}
3099
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003100TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003101 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003102
3103 // Deserialize
3104 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3105
3106 // Verify
3107 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003108 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003109 EXPECT_TRUE(audio->conference_mode());
3110
3111 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003112 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003113 EXPECT_TRUE(video->conference_mode());
3114}
3115
deadbeefd45aea82017-09-16 01:24:29 -07003116TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003117 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003118
3119 // We tested deserialization already above, so just test that if we serialize
3120 // and deserialize the flag doesn't disappear.
3121 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003122 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003123 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3124
3125 // Verify.
3126 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003127 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003128 EXPECT_TRUE(audio->conference_mode());
3129
3130 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003131 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003132 EXPECT_TRUE(video->conference_mode());
3133}
3134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3136 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003137 const char kSdpEmptyType[] = " =candidate";
3138 const char kSdpEqualAsPlus[] = "a+candidate";
3139 const char kSdpSpaceAfterEqual[] = "a= candidate";
3140 const char kSdpUpperType[] = "A=candidate";
3141 const char kSdpEmptyLine[] = "";
3142 const char kSdpMissingValue[] = "a=";
3143
Yves Gerey665174f2018-06-19 15:03:05 +02003144 const char kSdpBrokenFingerprint[] =
3145 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 15:03:05 +02003147 const char kSdpExtraField[] =
3148 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
Yves Gerey665174f2018-06-19 15:03:05 +02003150 const char kSdpMissingSpace[] =
3151 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003153 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003154 const char kSdpMd5[] =
3155 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003156 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157
3158 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003159 ExpectParseFailure("v=", kSdpDestroyer);
3160 ExpectParseFailure("o=", kSdpDestroyer);
3161 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003163 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164
3165 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003166 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3167 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003168
3169 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003170 ExpectParseFailure("a=candidate", kSdpEmptyType);
3171 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3172 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3173 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174
3175 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3176 // because it's orthogonal to what we are replacing and hence
3177 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003178 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3179 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3180 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3181 ExpectParseFailure("a=sendrecv", kSdpMd5);
3182
3183 // Empty Line
3184 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3185 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003186}
3187
3188TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3189 // ssrc
3190 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003191 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003192 // crypto
3193 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3194 // rtpmap
3195 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3196 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3197 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3198 // candidate
3199 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3200 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3201 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3202 ExpectParseFailure("rport 2346", "rport badvalue");
3203 ExpectParseFailure("rport 2346 generation 2",
3204 "rport 2346 generation badvalue");
3205 // m line
3206 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3207 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3208
3209 // bandwidth
3210 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003211 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003212 // rtcp-fb
3213 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3214 "a=rtcp-fb:badvalue nack\r\n",
3215 "a=rtcp-fb:badvalue nack");
3216 // extmap
3217 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3218 "a=extmap:badvalue http://example.com\r\n",
3219 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220}
3221
3222TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003223 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224
3225 const char kSdpWithReorderedPlTypesString[] =
3226 "v=0\r\n"
3227 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3228 "s=-\r\n"
3229 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003230 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003231 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3232 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003234 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235
3236 // Deserialize
3237 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3238
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003239 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003240 GetFirstAudioContentDescription(jdesc_output.description());
3241 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003243 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3244 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 EXPECT_EQ(104, acd->codecs()[0].id);
3246}
3247
3248TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003249 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250 CodecParams params;
3251 params.max_ptime = 40;
3252 params.ptime = 30;
3253 params.min_ptime = 10;
3254 params.sprop_stereo = 1;
3255 params.stereo = 1;
3256 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003257 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003259 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260}
3261
3262TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3263 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003264 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003266 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267}
3268
3269TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3270 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003271 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003273 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274}
3275
3276TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003277 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003278
3279 const char kSdpWithFmtpString[] =
3280 "v=0\r\n"
3281 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3282 "s=-\r\n"
3283 "t=0 0\r\n"
3284 "m=video 3457 RTP/SAVPF 120\r\n"
3285 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003286 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3287
3288 // Deserialize
3289 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003290 EXPECT_TRUE(
3291 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003292
Donald Curtis0e07f922015-05-15 09:21:23 -07003293 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003294 GetFirstVideoContentDescription(jdesc_output.description());
3295 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003296 ASSERT_FALSE(vcd->codecs().empty());
3297 cricket::VideoCodec vp8 = vcd->codecs()[0];
3298 EXPECT_EQ("VP8", vp8.name);
3299 EXPECT_EQ(120, vp8.id);
3300 cricket::CodecParameterMap::iterator found =
3301 vp8.params.find("x-google-min-bitrate");
3302 ASSERT_TRUE(found != vp8.params.end());
3303 EXPECT_EQ(found->second, "10");
3304 found = vp8.params.find("x-google-max-quantization");
3305 ASSERT_TRUE(found != vp8.params.end());
3306 EXPECT_EQ(found->second, "40");
3307}
3308
johan2d8d23e2016-06-03 01:22:42 -07003309TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003310 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003311
3312 const char kSdpWithFmtpString[] =
3313 "v=0\r\n"
3314 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3315 "s=-\r\n"
3316 "t=0 0\r\n"
3317 "m=video 49170 RTP/AVP 98\r\n"
3318 "a=rtpmap:98 H264/90000\r\n"
3319 "a=fmtp:98 profile-level-id=42A01E; "
3320 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3321
3322 // Deserialize.
3323 SdpParseError error;
3324 EXPECT_TRUE(
3325 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3326
johan2d8d23e2016-06-03 01:22:42 -07003327 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003328 GetFirstVideoContentDescription(jdesc_output.description());
3329 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003330 ASSERT_FALSE(vcd->codecs().empty());
3331 cricket::VideoCodec h264 = vcd->codecs()[0];
3332 EXPECT_EQ("H264", h264.name);
3333 EXPECT_EQ(98, h264.id);
3334 cricket::CodecParameterMap::const_iterator found =
3335 h264.params.find("profile-level-id");
3336 ASSERT_TRUE(found != h264.params.end());
3337 EXPECT_EQ(found->second, "42A01E");
3338 found = h264.params.find("sprop-parameter-sets");
3339 ASSERT_TRUE(found != h264.params.end());
3340 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3341}
3342
Donald Curtis0e07f922015-05-15 09:21:23 -07003343TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003344 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003345
3346 const char kSdpWithFmtpString[] =
3347 "v=0\r\n"
3348 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3349 "s=-\r\n"
3350 "t=0 0\r\n"
3351 "m=video 3457 RTP/SAVPF 120\r\n"
3352 "a=rtpmap:120 VP8/90000\r\n"
3353 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354
3355 // Deserialize
3356 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003357 EXPECT_TRUE(
3358 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003361 GetFirstVideoContentDescription(jdesc_output.description());
3362 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003363 ASSERT_FALSE(vcd->codecs().empty());
3364 cricket::VideoCodec vp8 = vcd->codecs()[0];
3365 EXPECT_EQ("VP8", vp8.name);
3366 EXPECT_EQ(120, vp8.id);
3367 cricket::CodecParameterMap::iterator found =
3368 vp8.params.find("x-google-min-bitrate");
3369 ASSERT_TRUE(found != vp8.params.end());
3370 EXPECT_EQ(found->second, "10");
3371 found = vp8.params.find("x-google-max-quantization");
3372 ASSERT_TRUE(found != vp8.params.end());
3373 EXPECT_EQ(found->second, "40");
3374}
3375
ossuaa4b0772017-01-30 07:41:18 -08003376TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003377 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003378
3379 cricket::AudioCodecs codecs = acd->codecs();
3380 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3381 acd->set_codecs(codecs);
3382
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003383 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003384 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003385 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003386 std::string sdp_with_fmtp = kSdpFullString;
3387 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3388 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3389 &sdp_with_fmtp);
3390 EXPECT_EQ(sdp_with_fmtp, message);
3391}
3392
3393TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003394 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003395
3396 cricket::AudioCodecs codecs = acd->codecs();
3397 codecs[0].params["stereo"] = "1";
3398 acd->set_codecs(codecs);
3399
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003400 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003401 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003402 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003403 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003404 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003405 &sdp_with_fmtp);
3406 EXPECT_EQ(sdp_with_fmtp, message);
3407}
3408
3409TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003410 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003411
3412 cricket::AudioCodecs codecs = acd->codecs();
3413 codecs[0].params["ptime"] = "20";
3414 codecs[0].params["maxptime"] = "120";
3415 acd->set_codecs(codecs);
3416
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003417 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003418 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003419 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003420 std::string sdp_with_fmtp = kSdpFullString;
3421 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3422 "a=maxptime:120\r\n" // No comma here. String merging!
3423 "a=ptime:20\r\n",
3424 &sdp_with_fmtp);
3425 EXPECT_EQ(sdp_with_fmtp, message);
3426}
3427
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003429 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430
3431 cricket::VideoCodecs codecs = vcd->codecs();
3432 codecs[0].params["x-google-min-bitrate"] = "10";
3433 vcd->set_codecs(codecs);
3434
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003435 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003437 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 std::string sdp_with_fmtp = kSdpFullString;
3439 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003440 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 EXPECT_EQ(sdp_with_fmtp, message);
3442}
3443
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003444TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3445 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003446 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 std::string sdp_with_icelite = kSdpFullString;
3448 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3449 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3450 const cricket::TransportInfo* tinfo1 =
3451 desc->GetTransportInfoByName("audio_content_name");
3452 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3453 const cricket::TransportInfo* tinfo2 =
3454 desc->GetTransportInfoByName("video_content_name");
3455 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003456
3457 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003458 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3460 desc = jdesc_with_icelite.description();
3461 const cricket::TransportInfo* atinfo =
3462 desc->GetTransportInfoByName("audio_content_name");
3463 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3464 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003465 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003467
3468 // Now that we know deserialization works, we can use TestSerialize to test
3469 // serialization.
3470 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471}
3472
3473// Verifies that the candidates in the input SDP are parsed and serialized
3474// correctly in the output SDP.
3475TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3476 std::string sdp_with_data = kSdpString;
3477 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003478 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479
3480 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003481 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003483
3484TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3485 AddFingerprint();
3486 TransportInfo audio_transport_info =
3487 *(desc_.GetTransportInfoByName(kAudioContentName));
3488 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3489 audio_transport_info.description.connection_role);
3490 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003491 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003492
3493 TransportInfo video_transport_info =
3494 *(desc_.GetTransportInfoByName(kVideoContentName));
3495 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3496 video_transport_info.description.connection_role);
3497 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003498 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003499
3500 desc_.RemoveTransportInfoByName(kAudioContentName);
3501 desc_.RemoveTransportInfoByName(kVideoContentName);
3502
3503 desc_.AddTransportInfo(audio_transport_info);
3504 desc_.AddTransportInfo(video_transport_info);
3505
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003506 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003507 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003508 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003509 std::string sdp_with_dtlssetup = kSdpFullString;
3510
3511 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003512 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3513 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003514 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003515 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003516 EXPECT_EQ(sdp_with_dtlssetup, message);
3517}
3518
3519TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003520 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003521 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003522 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003523 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3524 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3525 const cricket::TransportInfo* atinfo =
3526 desc->GetTransportInfoByName("audio_content_name");
3527 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3528 atinfo->description.connection_role);
3529 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003530 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003531 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3532 vtinfo->description.connection_role);
3533}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003534
3535// Verifies that the order of the serialized m-lines follows the order of the
3536// ContentInfo in SessionDescription, and vise versa for deserialization.
3537TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003538 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003539 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3540 kSdpSctpDataChannelString};
3541 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3542 cricket::MEDIA_TYPE_VIDEO,
3543 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003544
3545 // Verifies all 6 permutations.
3546 for (size_t i = 0; i < 6; ++i) {
3547 size_t media_content_in_sdp[3];
3548 // The index of the first media content.
3549 media_content_in_sdp[0] = i / 2;
3550 // The index of the second media content.
3551 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3552 // The index of the third media content.
3553 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3554
3555 std::string sdp_string = kSdpSessionString;
3556 for (size_t i = 0; i < 3; ++i)
3557 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3558
3559 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3560 cricket::SessionDescription* desc = jdesc.description();
3561 EXPECT_EQ(3u, desc->contents().size());
3562
3563 for (size_t i = 0; i < 3; ++i) {
3564 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003565 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003566 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3567 }
3568
Steve Antone831b8c2018-02-01 12:22:16 -08003569 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003570 EXPECT_EQ(sdp_string, serialized_sdp);
3571 }
3572}
deadbeef9d3584c2016-02-16 17:54:10 -08003573
deadbeef25ed4352016-12-12 18:37:36 -08003574TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3575 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003576 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003577 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003578 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3579 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3580}
3581
deadbeef12771a12017-01-03 13:53:47 -08003582// The semantics of "a=bundle-only" are only defined when it's used in
3583// combination with a 0 port on the m= line. We should ignore it if used with a
3584// nonzero port.
3585TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3586 // Make the base bundle-only description but unset the bundle-only flag.
3587 MakeBundleOnlyDescription();
3588 jdesc_.description()->contents()[1].bundle_only = false;
3589
3590 std::string modified_sdp = kBundleOnlySdpFullString;
3591 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003592 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003593 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3594 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003595}
3596
3597TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3598 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003599 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003600}
3601
deadbeef9d3584c2016-02-16 17:54:10 -08003602TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3603 MakePlanBDescription();
3604
Steve Antona3a92c22017-12-07 10:27:41 -08003605 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003606 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3607
3608 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3609}
3610
3611TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3612 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003613 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003614}
3615
3616TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3617 MakeUnifiedPlanDescription();
3618
Steve Antona3a92c22017-12-07 10:27:41 -08003619 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003620 EXPECT_TRUE(
3621 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3622
3623 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3624}
3625
3626TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3627 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003628 TestSerialize(jdesc_);
3629}
3630
Seth Hampson5b4f0752018-04-02 16:31:36 -07003631// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003632// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3633// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003634// with no stream ids and multiple stream ids. For parsing this, the Unified
3635// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3636// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003637TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3638 // Create both msid lines for Plan B and Unified Plan support.
3639 MakeUnifiedPlanDescriptionMultipleStreamIds(
3640 cricket::kMsidSignalingMediaSection |
3641 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003642
3643 JsepSessionDescription deserialized_description(kDummyType);
3644 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3645 &deserialized_description));
3646
3647 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003648 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3649 cricket::kMsidSignalingSsrcAttribute,
3650 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003651}
3652
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003653// Tests the serialization of a Unified Plan SDP that is compatible for both
3654// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3655// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3656// multiple stream ids.
3657TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3658 // Create both msid lines for Plan B and Unified Plan support.
3659 MakeUnifiedPlanDescriptionMultipleStreamIds(
3660 cricket::kMsidSignalingMediaSection |
3661 cricket::kMsidSignalingSsrcAttribute);
3662 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3663 // We explicitly test that the serialized SDP string is equal to the hard
3664 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3665 // take priority over "a=ssrc msid" lines. This means if we just used
3666 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3667 // and still pass, because the deserialized version would be the same.
3668 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3669}
3670
3671// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3672// that signal stream IDs) is deserialized appropriately. It tests the case for
3673// no stream ids and multiple stream ids.
3674TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3675 // Only create a=msid lines for strictly Unified Plan stream ID support.
3676 MakeUnifiedPlanDescriptionMultipleStreamIds(
3677 cricket::kMsidSignalingMediaSection);
3678
3679 JsepSessionDescription deserialized_description(kDummyType);
3680 std::string unified_plan_sdp_string =
3681 kUnifiedPlanSdpFullStringWithSpecialMsid;
3682 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3683 EXPECT_TRUE(
3684 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3685
3686 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3687}
3688
3689// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3690// that signal stream IDs) is serialized appropriately. It tests the case for no
3691// stream ids and multiple stream ids.
3692TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3693 // Only create a=msid lines for strictly Unified Plan stream ID support.
3694 MakeUnifiedPlanDescriptionMultipleStreamIds(
3695 cricket::kMsidSignalingMediaSection);
3696
Seth Hampson5b4f0752018-04-02 16:31:36 -07003697 TestSerialize(jdesc_);
3698}
3699
Seth Hampson5897a6e2018-04-03 11:16:33 -07003700// This tests that a Unified Plan SDP with no a=ssrc lines is
3701// serialized/deserialized appropriately. In this case the
3702// MediaContentDescription will contain a StreamParams object that doesn't have
3703// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3704// SSRC lines.
3705TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3706 MakeUnifiedPlanDescription();
3707 RemoveSsrcSignalingFromStreamParams();
3708 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3709 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3710
3711 JsepSessionDescription deserialized_description(kDummyType);
3712 EXPECT_TRUE(
3713 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3714 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3715}
3716
3717TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3718 MakeUnifiedPlanDescription();
3719 RemoveSsrcSignalingFromStreamParams();
3720
3721 TestSerialize(jdesc_);
3722}
3723
Steve Antone831b8c2018-02-01 12:22:16 -08003724TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3725 JsepSessionDescription jsep_desc(kDummyType);
3726 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3727 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3728}
3729
3730TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3731 JsepSessionDescription jsep_desc(kDummyType);
3732 std::string sdp = kSdpSessionString;
3733 sdp += kSdpSctpDataChannelString;
3734 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3735 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3736}
3737
3738TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3739 JsepSessionDescription jsep_desc(kDummyType);
3740 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3741 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3742 jsep_desc.description()->msid_signaling());
3743}
3744
3745TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3746 JsepSessionDescription jsep_desc(kDummyType);
3747 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3748 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3749 jsep_desc.description()->msid_signaling());
3750}
3751
3752const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3753const char kSsrcAttributeMsidLine[] =
3754 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3755
3756TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3757 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3758 std::string sdp = webrtc::SdpSerialize(jdesc_);
3759
3760 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3761 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3762}
3763
3764TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3765 jdesc_.description()->set_msid_signaling(
3766 cricket::kMsidSignalingSsrcAttribute);
3767 std::string sdp = webrtc::SdpSerialize(jdesc_);
3768
3769 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3770 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3771}
3772
3773TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3774 jdesc_.description()->set_msid_signaling(
3775 cricket::kMsidSignalingMediaSection |
3776 cricket::kMsidSignalingSsrcAttribute);
3777 std::string sdp = webrtc::SdpSerialize(jdesc_);
3778
3779 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3780 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003781}
deadbeef7e146cb2016-09-28 10:04:34 -07003782
3783// Regression test for heap overflow bug:
3784// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3785TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003786 // The issue occurs when the sctp-port attribute is found in a video
3787 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003788 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003789 "v=0\r\n"
3790 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3791 "s=-\r\n"
3792 "t=0 0\r\n"
3793 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3794 "a=sctp-port 5000\r\n"
3795 "a=fmtp:108 foo=10\r\n";
3796
3797 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3798 "sctp-port");
3799}
deadbeefb2362572016-12-13 16:37:06 -08003800
3801// Regression test for integer overflow bug:
3802// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3803TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003804 // Bandwidth attribute is the max signed 32-bit int, which will get
3805 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003806 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003807 "v=0\r\n"
3808 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3809 "s=-\r\n"
3810 "t=0 0\r\n"
3811 "m=video 3457 RTP/SAVPF 120\r\n"
3812 "b=AS:2147483647\r\n"
3813 "foo=fail\r\n";
3814
3815 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3816}
deadbeef7bcdb692017-01-20 12:43:58 -08003817
deadbeefbc88c6b2017-08-02 11:26:34 -07003818// Similar to the above, except that negative values are illegal, not just
3819// error-prone as large values are.
3820// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3821TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3822 static const char kSdpWithNegativeBandwidth[] =
3823 "v=0\r\n"
3824 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3825 "s=-\r\n"
3826 "t=0 0\r\n"
3827 "m=video 3457 RTP/SAVPF 120\r\n"
3828 "b=AS:-1000\r\n";
3829
3830 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3831}
3832
deadbeef3e8016e2017-08-03 17:49:30 -07003833// An exception to the above rule: a value of -1 for b=AS should just be
3834// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3835// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3836// limit", but this is now what ommitting the attribute entirely will do, so
3837// ignoring it will have the intended effect.
3838TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3839 static const char kSdpWithBandwidthOfNegativeOne[] =
3840 "v=0\r\n"
3841 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3842 "s=-\r\n"
3843 "t=0 0\r\n"
3844 "m=video 3457 RTP/SAVPF 120\r\n"
3845 "b=AS:-1\r\n";
3846
Steve Antona3a92c22017-12-07 10:27:41 -08003847 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003848 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003849 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003850 GetFirstVideoContentDescription(jdesc_output.description());
3851 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003852 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3853}
3854
deadbeef7bcdb692017-01-20 12:43:58 -08003855// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3856// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3857// Regression test for:
3858// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3859TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3860 // Important piece is "ufrag foo pwd bar".
3861 static const char kSdpWithIceCredentialsInCandidateString[] =
3862 "v=0\r\n"
3863 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3864 "s=-\r\n"
3865 "t=0 0\r\n"
3866 "m=audio 9 RTP/SAVPF 111\r\n"
3867 "c=IN IP4 0.0.0.0\r\n"
3868 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3869 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3870 "a=rtpmap:111 opus/48000/2\r\n"
3871 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3872 "generation 2 ufrag foo pwd bar\r\n";
3873
Steve Antona3a92c22017-12-07 10:27:41 -08003874 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003875 EXPECT_TRUE(
3876 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3877 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3878 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003879 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003880 cricket::Candidate c = candidates->at(0)->candidate();
3881 EXPECT_EQ("ufrag_voice", c.username());
3882 EXPECT_EQ("pwd_voice", c.password());
3883}
deadbeef90f1e1e2017-02-10 12:35:05 -08003884
Johannes Kron211856b2018-09-06 12:12:28 +02003885// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3886// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3887// Regression test for:
3888// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3889TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3890 static const char kSdpWithFooIceCredentials[] =
3891 "v=0\r\n"
3892 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3893 "s=-\r\n"
3894 "t=0 0\r\n"
3895 "m=audio 9 RTP/SAVPF 111\r\n"
3896 "c=IN IP4 0.0.0.0\r\n"
3897 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3898 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3899 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3900 "a=rtpmap:111 opus/48000/2\r\n"
3901 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3902 "generation 2\r\n";
3903
3904 JsepSessionDescription jdesc_output(kDummyType);
3905 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3906 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3907 ASSERT_NE(nullptr, candidates);
3908 ASSERT_EQ(1U, candidates->count());
3909 cricket::Candidate c = candidates->at(0)->candidate();
3910 EXPECT_EQ("ufrag_voice", c.username());
3911 EXPECT_EQ("pwd_voice", c.password());
3912}
3913
deadbeef90f1e1e2017-02-10 12:35:05 -08003914// Test that SDP with an invalid port number in "a=candidate" lines is
3915// rejected, without crashing.
3916// Regression test for:
3917// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3918TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3919 static const char kSdpWithInvalidCandidatePort[] =
3920 "v=0\r\n"
3921 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3922 "s=-\r\n"
3923 "t=0 0\r\n"
3924 "m=audio 9 RTP/SAVPF 111\r\n"
3925 "c=IN IP4 0.0.0.0\r\n"
3926 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3927 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3928 "a=rtpmap:111 opus/48000/2\r\n"
3929 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3930 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3931
Steve Antona3a92c22017-12-07 10:27:41 -08003932 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003933 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3934}
deadbeefa4549d62017-02-10 17:26:22 -08003935
3936// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3937// Regression test for:
3938// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3939TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3940 static const char kSdpWithMissingTrackId[] =
3941 "v=0\r\n"
3942 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3943 "s=-\r\n"
3944 "t=0 0\r\n"
3945 "m=audio 9 RTP/SAVPF 111\r\n"
3946 "c=IN IP4 0.0.0.0\r\n"
3947 "a=rtpmap:111 opus/48000/2\r\n"
3948 "a=msid:stream_id \r\n";
3949
Steve Antona3a92c22017-12-07 10:27:41 -08003950 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003951 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3952}
3953
3954TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3955 static const char kSdpWithMissingStreamId[] =
3956 "v=0\r\n"
3957 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3958 "s=-\r\n"
3959 "t=0 0\r\n"
3960 "m=audio 9 RTP/SAVPF 111\r\n"
3961 "c=IN IP4 0.0.0.0\r\n"
3962 "a=rtpmap:111 opus/48000/2\r\n"
3963 "a=msid: track_id\r\n";
3964
Steve Antona3a92c22017-12-07 10:27:41 -08003965 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003966 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3967}
zhihuang38989e52017-03-21 11:04:53 -07003968
3969// Tests that if both session-level address and media-level address exist, use
3970// the media-level address.
3971TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003972 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003973
3974 // Sesssion-level address.
3975 std::string sdp = kSdpFullString;
3976 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3977 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3978
3979 const auto& content1 = jsep_desc.description()->contents()[0];
3980 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003981 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003982 const auto& content2 = jsep_desc.description()->contents()[1];
3983 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003984 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003985}
3986
3987// Tests that the session-level connection address will be used if the media
3988// level-addresses are not specified.
3989TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003990 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003991
3992 // Sesssion-level address.
3993 std::string sdp = kSdpString;
3994 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3995 // Remove the media level addresses.
3996 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3997 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3998 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3999
4000 const auto& content1 = jsep_desc.description()->contents()[0];
4001 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004002 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004003 const auto& content2 = jsep_desc.description()->contents()[1];
4004 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004005 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004006}
4007
4008TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004009 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004010
4011 std::string sdp = kSdpString;
4012 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4013 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4014 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4015 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4016 &sdp);
4017 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4018 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4019 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4020 &sdp);
4021 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4022 const auto& content1 = jsep_desc.description()->contents()[0];
4023 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004024 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004025 const auto& content2 = jsep_desc.description()->contents()[1];
4026 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004027 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004028}
4029
Qingsi Wang56991422019-02-08 12:53:06 -08004030// Test that a c= line that contains a hostname connection address can be
4031// parsed.
4032TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4033 JsepSessionDescription jsep_desc(kDummyType);
4034 std::string sdp = kSdpString;
4035 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4036
4037 sdp = kSdpString;
4038 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4039 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4040 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4041
4042 ASSERT_NE(nullptr, jsep_desc.description());
4043 const auto& content1 = jsep_desc.description()->contents()[0];
4044 EXPECT_EQ("example.local:9",
4045 content1.media_description()->connection_address().ToString());
4046 const auto& content2 = jsep_desc.description()->contents()[1];
4047 EXPECT_EQ("example.local:9",
4048 content2.media_description()->connection_address().ToString());
4049}
4050
4051// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004052TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004053 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004054 std::string sdp = kSdpString;
4055 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4056
4057 // Unsupported multicast IPv4 address.
4058 sdp = kSdpFullString;
4059 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4060 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4061
4062 // Unsupported multicast IPv6 address.
4063 sdp = kSdpFullString;
4064 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4065 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4066
4067 // Mismatched address type.
4068 sdp = kSdpFullString;
4069 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4070 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4071
4072 sdp = kSdpFullString;
4073 Replace("c=IN IP4 74.125.224.39\r\n",
4074 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4075 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4076}
4077
4078TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004079 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004080 MakeDescriptionWithoutCandidates(&expected_jsep);
4081 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004082 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004083 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004084 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004085 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004086 auto audio_desc = jdesc.description()
4087 ->GetContentByName(kAudioContentName)
4088 ->media_description();
4089 auto video_desc = jdesc.description()
4090 ->GetContentByName(kVideoContentName)
4091 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004092 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4093 audio_desc->connection_address().ToString());
4094 EXPECT_EQ(video_desc_->connection_address().ToString(),
4095 video_desc->connection_address().ToString());
4096}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004097
Qingsi Wang56991422019-02-08 12:53:06 -08004098// Test that a media description that contains a hostname connection address can
4099// be correctly serialized.
4100TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4101 JsepSessionDescription expected_jsep(kDummyType);
4102 cricket::Candidate c;
4103 const rtc::SocketAddress hostname_addr("example.local", 1234);
4104 audio_desc_->set_connection_address(hostname_addr);
4105 video_desc_->set_connection_address(hostname_addr);
4106 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004107 expected_jsep.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Qingsi Wang56991422019-02-08 12:53:06 -08004108 // Serialization.
4109 std::string message = webrtc::SdpSerialize(expected_jsep);
4110 // Deserialization.
4111 JsepSessionDescription jdesc(kDummyType);
4112 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4113 auto audio_desc = jdesc.description()
4114 ->GetContentByName(kAudioContentName)
4115 ->media_description();
4116 auto video_desc = jdesc.description()
4117 ->GetContentByName(kVideoContentName)
4118 ->media_description();
4119 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4120 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4121}
4122
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004123// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4124// used (i.e., a single space as the session name)." So we should accept that.
4125TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4126 JsepSessionDescription jsep_desc(kDummyType);
4127 std::string sdp = kSdpString;
4128 Replace("s=-\r\n", "s= \r\n", &sdp);
4129 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4130}
Amit Hilbucha2012042018-12-03 11:35:05 -08004131
4132// Simulcast malformed input test for invalid format.
4133TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4134 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4135 "a=simulcast:\r\n", "a=simulcast:");
4136}
4137
4138// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4139TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4140 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4141 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4142 "a=simulcast:");
4143}
4144
4145// Validates that deserialization uses the a=simulcast: attribute
4146TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004147 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4148 sdp += "a=rid:1 send\r\n";
4149 sdp += "a=rid:2 send\r\n";
4150 sdp += "a=rid:3 send\r\n";
4151 sdp += "a=rid:4 recv\r\n";
4152 sdp += "a=rid:5 recv\r\n";
4153 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004154 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4155 JsepSessionDescription output(kDummyType);
4156 SdpParseError error;
4157 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4158 const cricket::ContentInfos& contents = output.description()->contents();
4159 const cricket::MediaContentDescription* media =
4160 contents.back().media_description();
4161 EXPECT_TRUE(media->HasSimulcast());
4162 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4163 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004164 EXPECT_FALSE(media->streams().empty());
4165 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4166 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004167}
4168
4169// Validates that deserialization removes rids that do not appear in SDP
4170TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4171 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4172 sdp += "a=rid:1 send\r\n";
4173 sdp += "a=rid:3 send\r\n";
4174 sdp += "a=rid:4 recv\r\n";
4175 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4176 JsepSessionDescription output(kDummyType);
4177 SdpParseError error;
4178 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4179 const cricket::ContentInfos& contents = output.description()->contents();
4180 const cricket::MediaContentDescription* media =
4181 contents.back().media_description();
4182 EXPECT_TRUE(media->HasSimulcast());
4183 const SimulcastDescription& simulcast = media->simulcast_description();
4184 EXPECT_EQ(2ul, simulcast.send_layers().size());
4185 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4186
4187 std::vector<SimulcastLayer> all_send_layers =
4188 simulcast.send_layers().GetAllLayers();
4189 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004190 EXPECT_EQ(0,
4191 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4192 return layer.rid == "2";
4193 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004194
4195 std::vector<SimulcastLayer> all_receive_layers =
4196 simulcast.receive_layers().GetAllLayers();
4197 ASSERT_EQ(1ul, all_receive_layers.size());
4198 EXPECT_EQ("4", all_receive_layers[0].rid);
4199
4200 EXPECT_FALSE(media->streams().empty());
4201 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4202 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004203}
4204
4205// Validates that Simulcast removes rids that appear in both send and receive.
4206TEST_F(WebRtcSdpTest,
4207 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4208 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4209 sdp += "a=rid:1 send\r\n";
4210 sdp += "a=rid:2 send\r\n";
4211 sdp += "a=rid:3 send\r\n";
4212 sdp += "a=rid:4 recv\r\n";
4213 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4214 JsepSessionDescription output(kDummyType);
4215 SdpParseError error;
4216 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4217 const cricket::ContentInfos& contents = output.description()->contents();
4218 const cricket::MediaContentDescription* media =
4219 contents.back().media_description();
4220 EXPECT_TRUE(media->HasSimulcast());
4221 const SimulcastDescription& simulcast = media->simulcast_description();
4222 EXPECT_EQ(2ul, simulcast.send_layers().size());
4223 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4224 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4225 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4226
4227 EXPECT_FALSE(media->streams().empty());
4228 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4229 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004230}
4231
4232// Ignores empty rid line.
4233TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4234 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4235 sdp += "a=rid:1 send\r\n";
4236 sdp += "a=rid:2 send\r\n";
4237 sdp += "a=rid\r\n"; // Should ignore this line.
4238 sdp += "a=rid:\r\n"; // Should ignore this line.
4239 sdp += "a=simulcast:send 1;2\r\n";
4240 JsepSessionDescription output(kDummyType);
4241 SdpParseError error;
4242 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4243 const cricket::ContentInfos& contents = output.description()->contents();
4244 const cricket::MediaContentDescription* media =
4245 contents.back().media_description();
4246 EXPECT_TRUE(media->HasSimulcast());
4247 const SimulcastDescription& simulcast = media->simulcast_description();
4248 EXPECT_TRUE(simulcast.receive_layers().empty());
4249 EXPECT_EQ(2ul, simulcast.send_layers().size());
4250 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4251
4252 EXPECT_FALSE(media->streams().empty());
4253 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4254 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004255}
4256
4257// Ignores malformed rid lines.
4258TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4259 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4260 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4261 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4262 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4263 sdp += "a=rid:4\r\n"; // Should ignore this line.
4264 sdp += "a=rid:5 send\r\n";
4265 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4266 JsepSessionDescription output(kDummyType);
4267 SdpParseError error;
4268 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4269 const cricket::ContentInfos& contents = output.description()->contents();
4270 const cricket::MediaContentDescription* media =
4271 contents.back().media_description();
4272 EXPECT_TRUE(media->HasSimulcast());
4273 const SimulcastDescription& simulcast = media->simulcast_description();
4274 EXPECT_TRUE(simulcast.receive_layers().empty());
4275 EXPECT_EQ(1ul, simulcast.send_layers().size());
4276 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4277
4278 EXPECT_FALSE(media->streams().empty());
4279 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4280 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004281}
4282
4283// Removes RIDs that specify a different format than the m= section.
4284TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4285 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4286 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4287 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4288 sdp += "a=simulcast:send 1;2\r\n";
4289 JsepSessionDescription output(kDummyType);
4290 SdpParseError error;
4291 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4292 const cricket::ContentInfos& contents = output.description()->contents();
4293 const cricket::MediaContentDescription* media =
4294 contents.back().media_description();
4295 EXPECT_TRUE(media->HasSimulcast());
4296 const SimulcastDescription& simulcast = media->simulcast_description();
4297 EXPECT_TRUE(simulcast.receive_layers().empty());
4298 EXPECT_EQ(1ul, simulcast.send_layers().size());
4299 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4300 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4301 EXPECT_EQ(1ul, media->streams().size());
4302 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4303 EXPECT_EQ(1ul, rids.size());
4304 EXPECT_EQ("1", rids[0].rid);
4305 EXPECT_EQ(1ul, rids[0].payload_types.size());
4306 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004307}
4308
4309// Ignores duplicate rid lines
4310TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4311 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4312 sdp += "a=rid:1 send\r\n";
4313 sdp += "a=rid:2 send\r\n";
4314 sdp += "a=rid:2 send\r\n";
4315 sdp += "a=rid:3 send\r\n";
4316 sdp += "a=rid:4 recv\r\n";
4317 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4318 JsepSessionDescription output(kDummyType);
4319 SdpParseError error;
4320 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4321 const cricket::ContentInfos& contents = output.description()->contents();
4322 const cricket::MediaContentDescription* media =
4323 contents.back().media_description();
4324 EXPECT_TRUE(media->HasSimulcast());
4325 const SimulcastDescription& simulcast = media->simulcast_description();
4326 EXPECT_EQ(2ul, simulcast.send_layers().size());
4327 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4328 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4329 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4330
4331 EXPECT_FALSE(media->streams().empty());
4332 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4333 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004334}
4335
4336// Simulcast serialization integration test.
4337// This test will serialize and deserialize the description and compare.
4338// More detailed tests for parsing simulcast can be found in
4339// unit tests for SdpSerializer.
4340TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004341 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004342 auto description = jdesc_.description();
4343 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004344 ASSERT_EQ(media->streams().size(), 1ul);
4345 StreamParams& send_stream = media->mutable_streams()[0];
4346 std::vector<RidDescription> send_rids;
4347 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4348 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4349 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4350 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4351 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004352
Amit Hilbucha2012042018-12-03 11:35:05 -08004353 SimulcastDescription& simulcast = media->simulcast_description();
4354 simulcast.send_layers().AddLayerWithAlternatives(
4355 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4356 simulcast.send_layers().AddLayerWithAlternatives(
4357 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4358
Amit Hilbucha2012042018-12-03 11:35:05 -08004359 TestSerialize(jdesc_);
4360}
Steve Anton06817cd2018-12-18 15:55:30 -08004361
4362// Test that the content name is empty if the media section does not have an
4363// a=mid line.
4364TEST_F(WebRtcSdpTest, ParseNoMid) {
4365 std::string sdp = kSdpString;
4366 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4367 Replace("a=mid:video_content_name\r\n", "", &sdp);
4368
4369 JsepSessionDescription output(kDummyType);
4370 SdpParseError error;
4371 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4372
4373 EXPECT_THAT(output.description()->contents(),
4374 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4375 Field("name", &cricket::ContentInfo::name, "")));
4376}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004377
4378// Test that the media transport name and base64-decoded setting is parsed from
4379// an a=x-mt line.
4380TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4381 JsepSessionDescription output(kDummyType);
4382 std::string sdp = kSdpSessionString;
4383 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4384 SdpParseError error;
4385
4386 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4387 << error.description;
4388 const auto& settings = output.description()->MediaTransportSettings();
4389 ASSERT_EQ(1u, settings.size());
4390 EXPECT_EQ("rtp", settings[0].transport_name);
4391 EXPECT_EQ("test64", settings[0].transport_setting);
4392}
4393
4394// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4395TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4396 JsepSessionDescription output(kDummyType);
4397 std::string sdp = kSdpSessionString;
4398 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4399 SdpParseError error;
4400
4401 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4402}
4403
4404// Test that multiple a=x-mt lines are parsed in the order of preference (the
4405// order of the lines in the SDP).
4406TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4407 JsepSessionDescription output(kDummyType);
4408 std::string sdp = kSdpSessionString;
4409 sdp +=
4410 "a=x-mt:rtp:dGVzdDY0\r\n"
4411 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4412 SdpParseError error;
4413
4414 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4415 << error.description;
4416 const auto& settings = output.description()->MediaTransportSettings();
4417 ASSERT_EQ(2u, settings.size());
4418 EXPECT_EQ("rtp", settings[0].transport_name);
4419 EXPECT_EQ("test64", settings[0].transport_setting);
4420 EXPECT_EQ("generic", settings[1].transport_name);
4421 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4422}
4423
4424// Test that only the first a=x-mt line associated with a transport name is
4425// parsed and the rest ignored.
4426TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4427 JsepSessionDescription output(kDummyType);
4428 std::string sdp = kSdpSessionString;
4429 sdp +=
4430 "a=x-mt:rtp:dGVzdDY0\r\n"
4431 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4432 SdpParseError error;
4433
4434 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4435 // but ignore the repeated transport.
4436 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4437 const auto& settings = output.description()->MediaTransportSettings();
4438 EXPECT_EQ("test64", settings[0].transport_setting);
4439}
4440
4441// Test that an a=x-mt line fails to parse if it is missing a setting.
4442TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4443 JsepSessionDescription output(kDummyType);
4444 std::string sdp = kSdpSessionString;
4445 sdp += "a=x-mt:rtp\r\n";
4446 SdpParseError error;
4447
4448 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4449}
4450
4451// Test that an a=x-mt line fails to parse if its missing a name and setting.
4452TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4453 JsepSessionDescription output(kDummyType);
4454 std::string sdp = kSdpSessionString;
4455 sdp += "a=x-mt\r\n";
4456 SdpParseError error;
4457
4458 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4459}
4460
4461TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4462 JsepSessionDescription output(kDummyType);
4463 std::string sdp = kSdpSessionString;
4464 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4465 SdpParseError error;
4466
4467 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4468 << error.description;
4469 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4470}
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004471
4472TEST_F(WebRtcSdpTest, SerializeMediaTransportSettings) {
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004473 auto description = absl::make_unique<cricket::SessionDescription>();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004474
4475 JsepSessionDescription output(SdpType::kOffer);
4476 // JsepSessionDescription takes ownership of the description.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004477 output.Initialize(std::move(description), "session_id", "session_version");
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004478 output.description()->AddMediaTransportSetting("foo", "bar");
4479 std::string serialized_out;
4480 output.ToString(&serialized_out);
4481 ASSERT_THAT(serialized_out, ::testing::HasSubstr("\r\na=x-mt:foo:YmFy\r\n"));
4482}
4483
4484TEST_F(WebRtcSdpTest, SerializeMediaTransportSettingsTestCopy) {
4485 cricket::SessionDescription description;
4486 description.AddMediaTransportSetting("name", "setting");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004487 std::unique_ptr<cricket::SessionDescription> copy = description.Clone();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004488 ASSERT_EQ(1u, copy->MediaTransportSettings().size());
4489 EXPECT_EQ("name", copy->MediaTransportSettings()[0].transport_name);
4490 EXPECT_EQ("setting", copy->MediaTransportSettings()[0].transport_setting);
4491}
Harald Alvestrandc3f48202019-05-14 17:27:11 +02004492
4493TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4494 AddSctpDataChannel(false); // Don't use sctpmap
4495 JsepSessionDescription jsep_desc(kDummyType);
4496 MakeDescriptionWithoutCandidates(&jsep_desc);
4497 std::string message = webrtc::SdpSerialize(jsep_desc);
4498 EXPECT_NE(std::string::npos,
4499 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4500}
4501
4502TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4503 AddSctpDataChannel(false);
4504 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4505 cricket::kMediaProtocolUdpDtlsSctp,
4506 cricket::kMediaProtocolTcpDtlsSctp};
4507 for (const auto& protocol : protocols) {
4508 sctp_desc_->set_protocol(protocol);
4509 JsepSessionDescription jsep_desc(kDummyType);
4510 MakeDescriptionWithoutCandidates(&jsep_desc);
4511 std::string message = webrtc::SdpSerialize(jsep_desc);
4512 EXPECT_NE(std::string::npos, message.find(protocol));
4513 JsepSessionDescription jsep_output(kDummyType);
4514 SdpParseError error;
4515 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4516 }
4517}