blob: 78fc8e07648ad930924e3577426d27a6a72ac63f [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;
59using cricket::DataContentDescription;
60using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080066using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand8a9193c2019-04-16 21:26:47 +020068using 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
279static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000280 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000281 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000287// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200288// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
289// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000290static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000291 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000292 "a=sctp-port 5000\r\n"
293 "c=IN IP4 0.0.0.0\r\n"
294 "a=ice-ufrag:ufrag_data\r\n"
295 "a=ice-pwd:pwd_data\r\n"
296 "a=mid:data_content_name\r\n";
297
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200298// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700299static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
300 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700301 "a=sctp-port:5000\r\n"
302 "c=IN IP4 0.0.0.0\r\n"
303 "a=ice-ufrag:ufrag_data\r\n"
304 "a=ice-pwd:pwd_data\r\n"
305 "a=mid:data_content_name\r\n";
306
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307static const char kSdpSctpDataChannelWithCandidatesString[] =
308 "m=application 2345 DTLS/SCTP 5000\r\n"
309 "c=IN IP4 74.125.127.126\r\n"
310 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
311 "generation 2\r\n"
312 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
315 "raddr 192.168.1.5 rport 2346 "
316 "generation 2\r\n"
317 "a=ice-ufrag:ufrag_data\r\n"
318 "a=ice-pwd:pwd_data\r\n"
319 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000320 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000322static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "v=0\r\n"
324 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
325 "s=-\r\n"
326 "t=0 0\r\n"
327 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000328 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000329 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000330 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000331 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000332 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000333 "a=x-google-flag:conference\r\n";
334
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335static const char kSdpSessionString[] =
336 "v=0\r\n"
337 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
338 "s=-\r\n"
339 "t=0 0\r\n"
340 "a=msid-semantic: WMS local_stream\r\n";
341
342static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000343 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000344 "c=IN IP4 0.0.0.0\r\n"
345 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000346 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
347 "a=mid:audio_content_name\r\n"
348 "a=sendrecv\r\n"
349 "a=rtpmap:111 opus/48000/2\r\n"
350 "a=ssrc:1 cname:stream_1_cname\r\n"
351 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
352 "a=ssrc:1 mslabel:local_stream\r\n"
353 "a=ssrc:1 label:audio_track_id_1\r\n";
354
355static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000356 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000357 "c=IN IP4 0.0.0.0\r\n"
358 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000359 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
360 "a=mid:video_content_name\r\n"
361 "a=sendrecv\r\n"
362 "a=rtpmap:120 VP8/90000\r\n"
363 "a=ssrc:2 cname:stream_1_cname\r\n"
364 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
365 "a=ssrc:2 mslabel:local_stream\r\n"
366 "a=ssrc:2 label:video_track_id_1\r\n";
367
deadbeef25ed4352016-12-12 18:37:36 -0800368// Reference sdp string using bundle-only.
369static const char kBundleOnlySdpFullString[] =
370 "v=0\r\n"
371 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
372 "s=-\r\n"
373 "t=0 0\r\n"
374 "a=group:BUNDLE audio_content_name video_content_name\r\n"
375 "a=msid-semantic: WMS local_stream_1\r\n"
376 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
377 "c=IN IP4 74.125.127.126\r\n"
378 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
379 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
388 "raddr 192.168.1.5 rport 2346 "
389 "generation 2\r\n"
390 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
391 "raddr 192.168.1.5 rport 2348 "
392 "generation 2\r\n"
393 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
394 "a=mid:audio_content_name\r\n"
395 "a=sendrecv\r\n"
396 "a=rtcp-mux\r\n"
397 "a=rtcp-rsize\r\n"
398 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
399 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
400 "dummy_session_params\r\n"
401 "a=rtpmap:111 opus/48000/2\r\n"
402 "a=rtpmap:103 ISAC/16000\r\n"
403 "a=rtpmap:104 ISAC/32000\r\n"
404 "a=ssrc:1 cname:stream_1_cname\r\n"
405 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
406 "a=ssrc:1 mslabel:local_stream_1\r\n"
407 "a=ssrc:1 label:audio_track_id_1\r\n"
408 "m=video 0 RTP/SAVPF 120\r\n"
409 "c=IN IP4 0.0.0.0\r\n"
410 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
411 "a=bundle-only\r\n"
412 "a=mid:video_content_name\r\n"
413 "a=sendrecv\r\n"
414 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
415 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
416 "a=rtpmap:120 VP8/90000\r\n"
417 "a=ssrc-group:FEC 2 3\r\n"
418 "a=ssrc:2 cname:stream_1_cname\r\n"
419 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
420 "a=ssrc:2 mslabel:local_stream_1\r\n"
421 "a=ssrc:2 label:video_track_id_1\r\n"
422 "a=ssrc:3 cname:stream_1_cname\r\n"
423 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
424 "a=ssrc:3 mslabel:local_stream_1\r\n"
425 "a=ssrc:3 label:video_track_id_1\r\n";
426
deadbeef9d3584c2016-02-16 17:54:10 -0800427// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
428// tracks.
429static const char kPlanBSdpFullString[] =
430 "v=0\r\n"
431 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
432 "s=-\r\n"
433 "t=0 0\r\n"
434 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
435 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
436 "c=IN IP4 74.125.127.126\r\n"
437 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
438 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
439 "generation 2\r\n"
440 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
443 "generation 2\r\n"
444 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
447 "raddr 192.168.1.5 rport 2346 "
448 "generation 2\r\n"
449 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
450 "raddr 192.168.1.5 rport 2348 "
451 "generation 2\r\n"
452 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
453 "a=mid:audio_content_name\r\n"
454 "a=sendrecv\r\n"
455 "a=rtcp-mux\r\n"
456 "a=rtcp-rsize\r\n"
457 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
458 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
459 "dummy_session_params\r\n"
460 "a=rtpmap:111 opus/48000/2\r\n"
461 "a=rtpmap:103 ISAC/16000\r\n"
462 "a=rtpmap:104 ISAC/32000\r\n"
463 "a=ssrc:1 cname:stream_1_cname\r\n"
464 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
465 "a=ssrc:1 mslabel:local_stream_1\r\n"
466 "a=ssrc:1 label:audio_track_id_1\r\n"
467 "a=ssrc:4 cname:stream_2_cname\r\n"
468 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
469 "a=ssrc:4 mslabel:local_stream_2\r\n"
470 "a=ssrc:4 label:audio_track_id_2\r\n"
471 "m=video 3457 RTP/SAVPF 120\r\n"
472 "c=IN IP4 74.125.224.39\r\n"
473 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
474 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
475 "generation 2\r\n"
476 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
479 "generation 2\r\n"
480 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
481 "generation 2\r\n"
482 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
483 "generation 2\r\n"
484 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
485 "generation 2\r\n"
486 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
487 "a=mid:video_content_name\r\n"
488 "a=sendrecv\r\n"
489 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
490 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
491 "a=rtpmap:120 VP8/90000\r\n"
492 "a=ssrc-group:FEC 2 3\r\n"
493 "a=ssrc:2 cname:stream_1_cname\r\n"
494 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
495 "a=ssrc:2 mslabel:local_stream_1\r\n"
496 "a=ssrc:2 label:video_track_id_1\r\n"
497 "a=ssrc:3 cname:stream_1_cname\r\n"
498 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
499 "a=ssrc:3 mslabel:local_stream_1\r\n"
500 "a=ssrc:3 label:video_track_id_1\r\n"
501 "a=ssrc:5 cname:stream_2_cname\r\n"
502 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
503 "a=ssrc:5 mslabel:local_stream_2\r\n"
504 "a=ssrc:5 label:video_track_id_2\r\n"
505 "a=ssrc:6 cname:stream_2_cname\r\n"
506 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
507 "a=ssrc:6 mslabel:local_stream_2\r\n"
508 "a=ssrc:6 label:video_track_id_3\r\n";
509
510// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
511// tracks.
512static const char kUnifiedPlanSdpFullString[] =
513 "v=0\r\n"
514 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
515 "s=-\r\n"
516 "t=0 0\r\n"
517 "a=msid-semantic: WMS local_stream_1\r\n"
518 // Audio track 1, stream 1 (with candidates).
519 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
520 "c=IN IP4 74.125.127.126\r\n"
521 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
522 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
523 "generation 2\r\n"
524 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
531 "raddr 192.168.1.5 rport 2346 "
532 "generation 2\r\n"
533 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
534 "raddr 192.168.1.5 rport 2348 "
535 "generation 2\r\n"
536 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
537 "a=mid:audio_content_name\r\n"
538 "a=msid:local_stream_1 audio_track_id_1\r\n"
539 "a=sendrecv\r\n"
540 "a=rtcp-mux\r\n"
541 "a=rtcp-rsize\r\n"
542 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
543 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
544 "dummy_session_params\r\n"
545 "a=rtpmap:111 opus/48000/2\r\n"
546 "a=rtpmap:103 ISAC/16000\r\n"
547 "a=rtpmap:104 ISAC/32000\r\n"
548 "a=ssrc:1 cname:stream_1_cname\r\n"
549 // Video track 1, stream 1 (with candidates).
550 "m=video 3457 RTP/SAVPF 120\r\n"
551 "c=IN IP4 74.125.224.39\r\n"
552 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
553 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
554 "generation 2\r\n"
555 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
558 "generation 2\r\n"
559 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
560 "generation 2\r\n"
561 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
562 "generation 2\r\n"
563 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
564 "generation 2\r\n"
565 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
566 "a=mid:video_content_name\r\n"
567 "a=msid:local_stream_1 video_track_id_1\r\n"
568 "a=sendrecv\r\n"
569 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
570 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
571 "a=rtpmap:120 VP8/90000\r\n"
572 "a=ssrc-group:FEC 2 3\r\n"
573 "a=ssrc:2 cname:stream_1_cname\r\n"
574 "a=ssrc:3 cname:stream_1_cname\r\n"
575 // Audio track 2, stream 2.
576 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
577 "c=IN IP4 0.0.0.0\r\n"
578 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
579 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
580 "a=mid:audio_content_name_2\r\n"
581 "a=msid:local_stream_2 audio_track_id_2\r\n"
582 "a=sendrecv\r\n"
583 "a=rtcp-mux\r\n"
584 "a=rtcp-rsize\r\n"
585 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
586 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
587 "dummy_session_params\r\n"
588 "a=rtpmap:111 opus/48000/2\r\n"
589 "a=rtpmap:103 ISAC/16000\r\n"
590 "a=rtpmap:104 ISAC/32000\r\n"
591 "a=ssrc:4 cname:stream_2_cname\r\n"
592 // Video track 2, stream 2.
593 "m=video 9 RTP/SAVPF 120\r\n"
594 "c=IN IP4 0.0.0.0\r\n"
595 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
596 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
597 "a=mid:video_content_name_2\r\n"
598 "a=msid:local_stream_2 video_track_id_2\r\n"
599 "a=sendrecv\r\n"
600 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
601 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
602 "a=rtpmap:120 VP8/90000\r\n"
603 "a=ssrc:5 cname:stream_2_cname\r\n"
604 // Video track 3, stream 2.
605 "m=video 9 RTP/SAVPF 120\r\n"
606 "c=IN IP4 0.0.0.0\r\n"
607 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
608 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
609 "a=mid:video_content_name_3\r\n"
610 "a=msid:local_stream_2 video_track_id_3\r\n"
611 "a=sendrecv\r\n"
612 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
613 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
614 "a=rtpmap:120 VP8/90000\r\n"
615 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616
Seth Hampson5b4f0752018-04-02 16:31:36 -0700617// Unified Plan SDP reference string:
618// - audio track 1 has 1 a=msid lines
619// - audio track 2 has 2 a=msid lines
620// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
621// there are 0 media stream ids.
622// This Unified Plan SDP represents a SDP that signals the msid using both
623// a=msid and a=ssrc msid semantics.
624static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
625 "v=0\r\n"
626 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
627 "s=-\r\n"
628 "t=0 0\r\n"
629 "a=msid-semantic: WMS local_stream_1\r\n"
630 // Audio track 1, with 1 stream id.
631 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
632 "c=IN IP4 74.125.127.126\r\n"
633 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
634 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
635 "generation 2\r\n"
636 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
639 "generation 2\r\n"
640 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
641 "generation 2\r\n"
642 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
643 "raddr 192.168.1.5 rport 2346 "
644 "generation 2\r\n"
645 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
646 "raddr 192.168.1.5 rport 2348 "
647 "generation 2\r\n"
648 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
649 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700650 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700651 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700652 "a=rtcp-mux\r\n"
653 "a=rtcp-rsize\r\n"
654 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
655 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
656 "dummy_session_params\r\n"
657 "a=rtpmap:111 opus/48000/2\r\n"
658 "a=rtpmap:103 ISAC/16000\r\n"
659 "a=rtpmap:104 ISAC/32000\r\n"
660 "a=ssrc:1 cname:stream_1_cname\r\n"
661 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
662 "a=ssrc:1 mslabel:local_stream_1\r\n"
663 "a=ssrc:1 label:audio_track_id_1\r\n"
664 // Audio track 2, with two stream ids.
665 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
666 "c=IN IP4 0.0.0.0\r\n"
667 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
668 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
669 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700670 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700671 "a=msid:local_stream_1 audio_track_id_2\r\n"
672 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700673 "a=rtcp-mux\r\n"
674 "a=rtcp-rsize\r\n"
675 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
676 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
677 "dummy_session_params\r\n"
678 "a=rtpmap:111 opus/48000/2\r\n"
679 "a=rtpmap:103 ISAC/16000\r\n"
680 "a=rtpmap:104 ISAC/32000\r\n"
681 "a=ssrc:4 cname:stream_1_cname\r\n"
682 // The support for Plan B msid signaling only includes the
683 // first media stream id "local_stream_1."
684 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
685 "a=ssrc:4 mslabel:local_stream_1\r\n"
686 "a=ssrc:4 label:audio_track_id_2\r\n"
687 // Audio track 3, with no stream ids.
688 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
689 "c=IN IP4 0.0.0.0\r\n"
690 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
691 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
692 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700693 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700694 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700695 "a=rtcp-mux\r\n"
696 "a=rtcp-rsize\r\n"
697 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
698 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
699 "dummy_session_params\r\n"
700 "a=rtpmap:111 opus/48000/2\r\n"
701 "a=rtpmap:103 ISAC/16000\r\n"
702 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700703 "a=ssrc:7 cname:stream_2_cname\r\n"
704 "a=ssrc:7 msid:- audio_track_id_3\r\n"
705 "a=ssrc:7 mslabel:-\r\n"
706 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700707
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800708// SDP string for unified plan without SSRCs
709static const char kUnifiedPlanSdpFullStringNoSsrc[] =
710 "v=0\r\n"
711 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
712 "s=-\r\n"
713 "t=0 0\r\n"
714 "a=msid-semantic: WMS local_stream_1\r\n"
715 // Audio track 1, stream 1 (with candidates).
716 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
717 "c=IN IP4 74.125.127.126\r\n"
718 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
719 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
720 "generation 2\r\n"
721 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
724 "generation 2\r\n"
725 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
726 "generation 2\r\n"
727 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
728 "raddr 192.168.1.5 rport 2346 "
729 "generation 2\r\n"
730 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
731 "raddr 192.168.1.5 rport 2348 "
732 "generation 2\r\n"
733 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
734 "a=mid:audio_content_name\r\n"
735 "a=msid:local_stream_1 audio_track_id_1\r\n"
736 "a=sendrecv\r\n"
737 "a=rtcp-mux\r\n"
738 "a=rtcp-rsize\r\n"
739 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
740 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
741 "dummy_session_params\r\n"
742 "a=rtpmap:111 opus/48000/2\r\n"
743 "a=rtpmap:103 ISAC/16000\r\n"
744 "a=rtpmap:104 ISAC/32000\r\n"
745 // Video track 1, stream 1 (with candidates).
746 "m=video 3457 RTP/SAVPF 120\r\n"
747 "c=IN IP4 74.125.224.39\r\n"
748 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
749 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
750 "generation 2\r\n"
751 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
754 "generation 2\r\n"
755 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
756 "generation 2\r\n"
757 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
758 "generation 2\r\n"
759 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
760 "generation 2\r\n"
761 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
762 "a=mid:video_content_name\r\n"
763 "a=msid:local_stream_1 video_track_id_1\r\n"
764 "a=sendrecv\r\n"
765 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
766 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
767 "a=rtpmap:120 VP8/90000\r\n"
768 // Audio track 2, stream 2.
769 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
770 "c=IN IP4 0.0.0.0\r\n"
771 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
772 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
773 "a=mid:audio_content_name_2\r\n"
774 "a=msid:local_stream_2 audio_track_id_2\r\n"
775 "a=sendrecv\r\n"
776 "a=rtcp-mux\r\n"
777 "a=rtcp-rsize\r\n"
778 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
779 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
780 "dummy_session_params\r\n"
781 "a=rtpmap:111 opus/48000/2\r\n"
782 "a=rtpmap:103 ISAC/16000\r\n"
783 "a=rtpmap:104 ISAC/32000\r\n"
784 // Video track 2, stream 2.
785 "m=video 9 RTP/SAVPF 120\r\n"
786 "c=IN IP4 0.0.0.0\r\n"
787 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
788 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
789 "a=mid:video_content_name_2\r\n"
790 "a=msid:local_stream_2 video_track_id_2\r\n"
791 "a=sendrecv\r\n"
792 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
793 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
794 "a=rtpmap:120 VP8/90000\r\n"
795 // Video track 3, stream 2.
796 "m=video 9 RTP/SAVPF 120\r\n"
797 "c=IN IP4 0.0.0.0\r\n"
798 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
799 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
800 "a=mid:video_content_name_3\r\n"
801 "a=msid:local_stream_2 video_track_id_3\r\n"
802 "a=sendrecv\r\n"
803 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
804 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
805 "a=rtpmap:120 VP8/90000\r\n";
806
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807// One candidate reference string as per W3c spec.
808// candidate:<blah> not a=candidate:<blah>CRLF
809static const char kRawCandidate[] =
810 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
811// One candidate reference string.
812static const char kSdpOneCandidate[] =
813 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
814 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000815
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000816static const char kSdpTcpActiveCandidate[] =
817 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
818 "tcptype active generation 2";
819static const char kSdpTcpPassiveCandidate[] =
820 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
821 "tcptype passive generation 2";
822static const char kSdpTcpSOCandidate[] =
823 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
824 "tcptype so generation 2";
825static const char kSdpTcpInvalidCandidate[] =
826 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
827 "tcptype invalid generation 2";
828
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000829// One candidate reference string with IPV6 address.
830static const char kRawIPV6Candidate[] =
831 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700832 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833
834// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800835static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800837 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838
Zach Steinb336c272018-08-09 01:16:13 -0700839static const char kRawHostnameCandidate[] =
840 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
841
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842// Session id and version
843static const char kSessionId[] = "18446744069414584320";
844static const char kSessionVersion[] = "18446462598732840960";
845
deadbeef9d3584c2016-02-16 17:54:10 -0800846// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847static const char kIceOption1[] = "iceoption1";
848static const char kIceOption2[] = "iceoption2";
849static const char kIceOption3[] = "iceoption3";
850
deadbeef9d3584c2016-02-16 17:54:10 -0800851// ICE ufrags/passwords.
852static const char kUfragVoice[] = "ufrag_voice";
853static const char kPwdVoice[] = "pwd_voice";
854static const char kUfragVideo[] = "ufrag_video";
855static const char kPwdVideo[] = "pwd_video";
856static const char kUfragData[] = "ufrag_data";
857static const char kPwdData[] = "pwd_data";
858
859// Extra ufrags/passwords for extra unified plan m= sections.
860static const char kUfragVoice2[] = "ufrag_voice_2";
861static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700862static const char kUfragVoice3[] = "ufrag_voice_3";
863static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800864static const char kUfragVideo2[] = "ufrag_video_2";
865static const char kPwdVideo2[] = "pwd_video_2";
866static const char kUfragVideo3[] = "ufrag_video_3";
867static const char kPwdVideo3[] = "pwd_video_3";
868
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869// Content name
870static const char kAudioContentName[] = "audio_content_name";
871static const char kVideoContentName[] = "video_content_name";
872static const char kDataContentName[] = "data_content_name";
873
deadbeef9d3584c2016-02-16 17:54:10 -0800874// Extra content names for extra unified plan m= sections.
875static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700876static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800877static const char kVideoContentName2[] = "video_content_name_2";
878static const char kVideoContentName3[] = "video_content_name_3";
879
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800881static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882static const char kStream1Cname[] = "stream_1_cname";
883static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200884static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800886static const uint32_t kVideoTrack1Ssrc1 = 2;
887static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888
889// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800890static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891static const char kStream2Cname[] = "stream_2_cname";
892static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200893static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800894static const char kVideoTrackId2[] = "video_track_id_2";
895static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800897static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700898static const char kAudioTrackId3[] = "audio_track_id_3";
899static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900
901// DataChannel
902static const char kDataChannelLabel[] = "data_channel";
903static const char kDataChannelMsid[] = "data_channeld0";
904static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200905static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
907// Candidate
908static const char kDummyMid[] = "dummy_mid";
909static const int kDummyIndex = 123;
910
911// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800912static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914// Helper functions
915
916static bool SdpDeserialize(const std::string& message,
917 JsepSessionDescription* jdesc) {
918 return webrtc::SdpDeserialize(message, jdesc, NULL);
919}
920
921static bool SdpDeserializeCandidate(const std::string& message,
922 JsepIceCandidate* candidate) {
923 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
924}
925
926// Add some extra |newlines| to the |message| after |line|.
927static void InjectAfter(const std::string& line,
928 const std::string& newlines,
929 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800930 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931}
932
933static void Replace(const std::string& line,
934 const std::string& newlines,
935 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800936 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937}
938
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000939// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
940// message.
941static void ExpectParseFailure(const std::string& bad_sdp,
942 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800943 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000945 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000947 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
948}
949
950// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
951static void ExpectParseFailure(const char* good_part, const char* bad_part) {
952 std::string bad_sdp = kSdpFullString;
953 Replace(good_part, bad_part, &bad_sdp);
954 ExpectParseFailure(bad_sdp, bad_part);
955}
956
957// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
958static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
959 const std::string& newlines,
960 const std::string& bad_part) {
961 std::string bad_sdp = kSdpFullString;
962 InjectAfter(injectpoint, newlines, &bad_sdp);
963 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964}
965
Steve Anton4e70a722017-11-28 14:57:10 -0800966static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 std::string* message) {
968 std::string new_direction;
969 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800970 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 new_direction = "a=inactive";
972 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800973 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 new_direction = "a=sendonly";
975 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800976 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 new_direction = "a=recvonly";
978 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800979 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 default:
981 new_direction = "a=sendrecv";
982 break;
983 }
984 Replace("a=sendrecv", new_direction, message);
985}
986
Yves Gerey665174f2018-06-19 15:03:05 +0200987static void ReplaceRejected(bool audio_rejected,
988 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 std::string* message) {
990 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800991 Replace("m=audio 9", "m=audio 0", message);
992 Replace(kAttributeIceUfragVoice, "", message);
993 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 }
995 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800996 Replace("m=video 9", "m=video 0", message);
997 Replace(kAttributeIceUfragVideo, "", message);
998 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 }
1000}
1001
1002// WebRtcSdpTest
1003
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001004class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001006 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001007#ifdef WEBRTC_ANDROID
1008 webrtc::InitializeAndroidObjects();
1009#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 // AudioContentDescription
1011 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001012 StreamParams audio_stream;
1013 audio_stream.id = kAudioTrackId1;
1014 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001015 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001016 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1017 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001018 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1019 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001020 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021
1022 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001023 video_desc_ = CreateVideoContentDescription();
1024 StreamParams video_stream;
1025 video_stream.id = kVideoTrackId1;
1026 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001027 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001028 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1029 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1030 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1031 video_stream.ssrc_groups.push_back(ssrc_group);
1032 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001033 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1034 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001035 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036
1037 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001038 desc_.AddTransportInfo(TransportInfo(
1039 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1040 desc_.AddTransportInfo(TransportInfo(
1041 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042
1043 // v4 host
1044 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001045 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001046 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1048 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001050 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001051 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1052 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001058 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001059 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1060 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061
1062 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001063 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001064 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1065 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001066 cricket::LOCAL_PORT_TYPE,
1067 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001069 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1070 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001071 cricket::LOCAL_PORT_TYPE,
1072 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001074 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1075 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001076 cricket::LOCAL_PORT_TYPE,
1077 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001079 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1080 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001081 cricket::LOCAL_PORT_TYPE,
1082 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083
1084 // stun
1085 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1087 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001088 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1089 address_stun, kCandidatePriority, "", "",
1090 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001091 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 candidate9.set_related_address(rel_address_stun);
1093
1094 address_stun.SetPort(port_stun++);
1095 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001096 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1097 address_stun, kCandidatePriority, "", "",
1098 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001099 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 candidate10.set_related_address(rel_address_stun);
1101
1102 // relay
1103 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001104 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001105 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1106 address_relay, kCandidatePriority, "", "",
1107 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001108 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001110 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1111 address_relay, kCandidatePriority, "", "",
1112 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001113 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114
1115 // voice
1116 candidates_.push_back(candidate1);
1117 candidates_.push_back(candidate2);
1118 candidates_.push_back(candidate5);
1119 candidates_.push_back(candidate6);
1120 candidates_.push_back(candidate9);
1121 candidates_.push_back(candidate10);
1122
1123 // video
1124 candidates_.push_back(candidate3);
1125 candidates_.push_back(candidate4);
1126 candidates_.push_back(candidate7);
1127 candidates_.push_back(candidate8);
1128 candidates_.push_back(candidate11);
1129 candidates_.push_back(candidate12);
1130
Yves Gerey665174f2018-06-19 15:03:05 +02001131 jcandidate_.reset(
1132 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133
1134 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001135 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 std::string mline_id;
1137 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001138 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 // In this test, the audio m line index will be 0, and the video m line
1140 // will be 1.
1141 bool is_video = (i > 5);
1142 mline_id = is_video ? "video_content_name" : "audio_content_name";
1143 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001144 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 jdesc_.AddCandidate(&jice);
1146 }
1147 }
1148
Seth Hampson5b4f0752018-04-02 16:31:36 -07001149 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001150 const IceCandidateCollection* video_candidates_collection =
1151 jdesc_.candidates(1);
1152 ASSERT_NE(nullptr, video_candidates_collection);
1153 std::vector<cricket::Candidate> video_candidates;
1154 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1155 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1156 c.set_transport_name("video_content_name");
1157 video_candidates.push_back(c);
1158 }
1159 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001160 }
1161
1162 // Turns the existing reference description into a description using
1163 // a=bundle-only. This means no transport attributes and a 0 port value on
1164 // the m= sections not associated with the BUNDLE-tag.
1165 void MakeBundleOnlyDescription() {
1166 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001167
1168 // And the rest of the transport attributes.
1169 desc_.transport_infos()[1].description.ice_ufrag.clear();
1170 desc_.transport_infos()[1].description.ice_pwd.clear();
1171 desc_.transport_infos()[1].description.connection_role =
1172 cricket::CONNECTIONROLE_NONE;
1173
1174 // Set bundle-only flag.
1175 desc_.contents()[1].bundle_only = true;
1176
1177 // Add BUNDLE group.
1178 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1179 group.AddContentName(kAudioContentName);
1180 group.AddContentName(kVideoContentName);
1181 desc_.AddGroup(group);
1182
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001183 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001184 jdesc_.session_version()));
1185 }
1186
deadbeef9d3584c2016-02-16 17:54:10 -08001187 // Turns the existing reference description into a plan B description,
1188 // with 2 audio tracks and 3 video tracks.
1189 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001190 audio_desc_ = audio_desc_->Copy();
1191 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001192
1193 StreamParams audio_track_2;
1194 audio_track_2.id = kAudioTrackId2;
1195 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001196 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001197 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1198 audio_desc_->AddStream(audio_track_2);
1199
1200 StreamParams video_track_2;
1201 video_track_2.id = kVideoTrackId2;
1202 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001203 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001204 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1205 video_desc_->AddStream(video_track_2);
1206
1207 StreamParams video_track_3;
1208 video_track_3.id = kVideoTrackId3;
1209 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001210 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001211 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1212 video_desc_->AddStream(video_track_3);
1213
1214 desc_.RemoveContentByName(kAudioContentName);
1215 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001216 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1217 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001218
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001219 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001220 jdesc_.session_version()));
1221 }
1222
1223 // Turns the existing reference description into a unified plan description,
1224 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001225 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001226 // Audio track 2.
1227 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1228 StreamParams audio_track_2;
1229 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001230 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001231 if (use_ssrcs) {
1232 audio_track_2.cname = kStream2Cname;
1233 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1234 }
deadbeef9d3584c2016-02-16 17:54:10 -08001235 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001236 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001237 desc_.AddTransportInfo(TransportInfo(
1238 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001239 // Video track 2, in stream 2.
1240 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1241 StreamParams video_track_2;
1242 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001243 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001244 if (use_ssrcs) {
1245 video_track_2.cname = kStream2Cname;
1246 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1247 }
deadbeef9d3584c2016-02-16 17:54:10 -08001248 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001249 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001250 desc_.AddTransportInfo(TransportInfo(
1251 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001252
1253 // Video track 3, in stream 2.
1254 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1255 StreamParams video_track_3;
1256 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001257 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001258 if (use_ssrcs) {
1259 video_track_3.cname = kStream2Cname;
1260 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1261 }
deadbeef9d3584c2016-02-16 17:54:10 -08001262 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001263 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001264 desc_.AddTransportInfo(TransportInfo(
1265 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001266 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001267
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001268 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001269 jdesc_.session_version()));
1270 }
1271
1272 // Creates an audio content description with no streams, and some default
1273 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 AudioContentDescription* CreateAudioContentDescription() {
1275 AudioContentDescription* audio = new AudioContentDescription();
1276 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001277 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001278 audio->AddCrypto(CryptoParams(
1279 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1281 "dummy_session_params"));
1282 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001283 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001284 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001285 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1286 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 return audio;
1288 }
1289
Seth Hampson5b4f0752018-04-02 16:31:36 -07001290 // Turns the existing reference description into a unified plan description,
1291 // with 3 audio MediaContentDescriptions with special StreamParams that
1292 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1293 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001294 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001295 desc_.RemoveContentByName(kVideoContentName);
1296 desc_.RemoveTransportInfoByName(kVideoContentName);
1297 RemoveVideoCandidates();
1298
1299 // Audio track 2 has 2 media stream ids.
1300 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1301 StreamParams audio_track_2;
1302 audio_track_2.id = kAudioTrackId2;
1303 audio_track_2.cname = kStream1Cname;
1304 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1305 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1306 audio_desc_2->AddStream(audio_track_2);
1307 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001308 desc_.AddTransportInfo(TransportInfo(
1309 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001310
1311 // Audio track 3 has no stream ids.
1312 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1313 StreamParams audio_track_3;
1314 audio_track_3.id = kAudioTrackId3;
1315 audio_track_3.cname = kStream2Cname;
1316 audio_track_3.set_stream_ids({});
1317 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1318 audio_desc_3->AddStream(audio_track_3);
1319 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001320 desc_.AddTransportInfo(TransportInfo(
1321 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001322 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001323 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001324 jdesc_.session_version()));
1325 }
1326
Seth Hampson5897a6e2018-04-03 11:16:33 -07001327 // Turns the existing reference description into a unified plan description
1328 // with one audio MediaContentDescription that contains one StreamParams with
1329 // 0 ssrcs.
1330 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1331 desc_.RemoveContentByName(kVideoContentName);
1332 desc_.RemoveContentByName(kAudioContentName);
1333 desc_.RemoveTransportInfoByName(kVideoContentName);
1334 RemoveVideoCandidates();
1335
1336 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1337 StreamParams audio_track;
1338 audio_track.id = kAudioTrackId1;
1339 audio_track.set_stream_ids({kStreamId1});
1340 audio_desc->AddStream(audio_track);
1341 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1342
1343 // Enable signaling a=msid lines.
1344 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001345 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001346 jdesc_.session_version()));
1347 }
1348
deadbeef9d3584c2016-02-16 17:54:10 -08001349 // Creates a video content description with no streams, and some default
1350 // configuration.
1351 VideoContentDescription* CreateVideoContentDescription() {
1352 VideoContentDescription* video = new VideoContentDescription();
1353 video->AddCrypto(CryptoParams(
1354 1, "AES_CM_128_HMAC_SHA1_80",
1355 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1356 video->set_protocol(cricket::kMediaProtocolSavpf);
1357 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001358 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001359 return video;
1360 }
1361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001363 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 // type
1365 EXPECT_EQ(cd1->type(), cd1->type());
1366
1367 // content direction
1368 EXPECT_EQ(cd1->direction(), cd2->direction());
1369
1370 // rtcp_mux
1371 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1372
deadbeef13871492015-12-09 12:37:51 -08001373 // rtcp_reduced_size
1374 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 // cryptos
1377 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1378 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1379 ADD_FAILURE();
1380 return;
1381 }
Yves Gerey665174f2018-06-19 15:03:05 +02001382 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 const CryptoParams c1 = cd1->cryptos().at(i);
1384 const CryptoParams c2 = cd2->cryptos().at(i);
1385 EXPECT_TRUE(c1.Matches(c2));
1386 EXPECT_EQ(c1.key_params, c2.key_params);
1387 EXPECT_EQ(c1.session_params, c2.session_params);
1388 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001391 // Use an equivalence class here, for old and new versions of the
1392 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001393 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1394 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1395 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001396 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001397 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1398 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1399 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001400 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001401 } else {
1402 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1403 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404
1405 // codecs
1406 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1407
1408 // bandwidth
1409 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1410
1411 // streams
1412 EXPECT_EQ(cd1->streams(), cd2->streams());
1413
Johannes Kron0854eb62018-10-10 22:33:20 +02001414 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001415 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 // extmap
1418 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1419 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001420 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001421 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1422 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 EXPECT_EQ(ext1.uri, ext2.uri);
1424 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001425 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 }
1428
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001429 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1430 const std::vector<std::string>& ids) {
1431 // Order of elements does not matter, only equivalence of sets.
1432 EXPECT_EQ(rids.size(), ids.size());
1433 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001434 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1435 return rid.rid == id;
1436 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001437 }
1438 }
1439
Amit Hilbucha2012042018-12-03 11:35:05 -08001440 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1441 const SimulcastDescription& simulcast2) {
1442 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1443 EXPECT_EQ(simulcast1.receive_layers().size(),
1444 simulcast2.receive_layers().size());
1445 }
1446
zstein4b2e0822017-02-17 19:48:38 -08001447 void CompareDataContentDescription(const DataContentDescription* dcd1,
1448 const DataContentDescription* dcd2) {
zstein4b2e0822017-02-17 19:48:38 -08001449 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1450 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02001452 void CompareSctpDataContentDescription(
1453 const SctpDataContentDescription* dcd1,
1454 const SctpDataContentDescription* dcd2) {
1455 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1456 EXPECT_EQ(dcd1->port(), dcd2->port());
1457 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
1458 }
1459
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 void CompareSessionDescription(const SessionDescription& desc1,
1461 const SessionDescription& desc2) {
1462 // Compare content descriptions.
1463 if (desc1.contents().size() != desc2.contents().size()) {
1464 ADD_FAILURE();
1465 return;
1466 }
Yves Gerey665174f2018-06-19 15:03:05 +02001467 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1469 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001470 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001472 EXPECT_EQ(c1.type, c2.type);
1473 EXPECT_EQ(c1.rejected, c2.rejected);
1474 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475
1476 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1477 if (IsAudioContent(&c1)) {
1478 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001479 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001481 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1483 }
1484
1485 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1486 if (IsVideoContent(&c1)) {
1487 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001488 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001490 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1492 }
1493
1494 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02001495 if (c1.media_description()->as_sctp()) {
1496 ASSERT_TRUE(c2.media_description()->as_sctp());
1497 const SctpDataContentDescription* scd1 =
1498 c1.media_description()->as_sctp();
1499 const SctpDataContentDescription* scd2 =
1500 c2.media_description()->as_sctp();
1501 CompareSctpDataContentDescription(scd1, scd2);
1502 } else {
1503 if (IsDataContent(&c1)) {
1504 const DataContentDescription* dcd1 =
1505 c1.media_description()->as_data();
1506 const DataContentDescription* dcd2 =
1507 c2.media_description()->as_data();
1508 CompareDataContentDescription(dcd1, dcd2);
1509 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001511
1512 CompareSimulcastDescription(
1513 c1.media_description()->simulcast_description(),
1514 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 }
1516
1517 // group
1518 const cricket::ContentGroups groups1 = desc1.groups();
1519 const cricket::ContentGroups groups2 = desc2.groups();
1520 EXPECT_EQ(groups1.size(), groups1.size());
1521 if (groups1.size() != groups2.size()) {
1522 ADD_FAILURE();
1523 return;
1524 }
1525 for (size_t i = 0; i < groups1.size(); ++i) {
1526 const cricket::ContentGroup group1 = groups1.at(i);
1527 const cricket::ContentGroup group2 = groups2.at(i);
1528 EXPECT_EQ(group1.semantics(), group2.semantics());
1529 const cricket::ContentNames names1 = group1.content_names();
1530 const cricket::ContentNames names2 = group2.content_names();
1531 EXPECT_EQ(names1.size(), names2.size());
1532 if (names1.size() != names2.size()) {
1533 ADD_FAILURE();
1534 return;
1535 }
1536 cricket::ContentNames::const_iterator iter1 = names1.begin();
1537 cricket::ContentNames::const_iterator iter2 = names2.begin();
1538 while (iter1 != names1.end()) {
1539 EXPECT_EQ(*iter1++, *iter2++);
1540 }
1541 }
1542
1543 // transport info
1544 const cricket::TransportInfos transports1 = desc1.transport_infos();
1545 const cricket::TransportInfos transports2 = desc2.transport_infos();
1546 EXPECT_EQ(transports1.size(), transports2.size());
1547 if (transports1.size() != transports2.size()) {
1548 ADD_FAILURE();
1549 return;
1550 }
1551 for (size_t i = 0; i < transports1.size(); ++i) {
1552 const cricket::TransportInfo transport1 = transports1.at(i);
1553 const cricket::TransportInfo transport2 = transports2.at(i);
1554 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 EXPECT_EQ(transport1.description.ice_ufrag,
1556 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001557 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001558 EXPECT_EQ(transport1.description.ice_mode,
1559 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 if (transport1.description.identity_fingerprint) {
1561 EXPECT_EQ(*transport1.description.identity_fingerprint,
1562 *transport2.description.identity_fingerprint);
1563 } else {
1564 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1565 transport2.description.identity_fingerprint.get());
1566 }
1567 EXPECT_EQ(transport1.description.transport_options,
1568 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 }
deadbeefc80741f2015-10-22 13:14:45 -07001570
1571 // global attributes
1572 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001573 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 }
1575
Yves Gerey665174f2018-06-19 15:03:05 +02001576 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1577 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1579 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1580 CompareSessionDescription(*desc1.description(), *desc2.description());
1581 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1582 return false;
1583 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1584 const IceCandidateCollection* cc1 = desc1.candidates(i);
1585 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001586 if (cc1->count() != cc2->count()) {
1587 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001589 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 for (size_t j = 0; j < cc1->count(); ++j) {
1591 const IceCandidateInterface* c1 = cc1->at(j);
1592 const IceCandidateInterface* c2 = cc2->at(j);
1593 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1594 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1595 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1596 }
1597 }
1598 return true;
1599 }
1600
1601 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1602 // them with invalid keywords so that the parser will just ignore them.
1603 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001604 absl::StrReplaceAll(
1605 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 return true;
1607 }
1608
1609 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001610 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1611 int mline_index,
1612 const std::string& ufrag,
1613 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 std::string content_name;
1615 if (mline_index == 0) {
1616 content_name = kAudioContentName;
1617 } else if (mline_index == 1) {
1618 content_name = kVideoContentName;
1619 } else {
nissec80e7412017-01-11 05:56:46 -08001620 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 }
Yves Gerey665174f2018-06-19 15:03:05 +02001622 TransportInfo transport_info(content_name,
1623 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 SessionDescription* desc =
1625 const_cast<SessionDescription*>(jdesc->description());
1626 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001627 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1629 const IceCandidateCollection* cc = jdesc_.candidates(i);
1630 for (size_t j = 0; j < cc->count(); ++j) {
1631 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001632 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1633 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 }
1635 }
1636 }
1637 return true;
1638 }
1639
1640 void AddIceOptions(const std::string& content_name,
1641 const std::vector<std::string>& transport_options) {
1642 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1643 cricket::TransportInfo transport_info =
1644 *(desc_.GetTransportInfoByName(content_name));
1645 desc_.RemoveTransportInfoByName(content_name);
1646 transport_info.description.transport_options = transport_options;
1647 desc_.AddTransportInfo(transport_info);
1648 }
1649
deadbeef3f7219b2015-12-28 15:17:14 -08001650 void SetIceUfragPwd(const std::string& content_name,
1651 const std::string& ice_ufrag,
1652 const std::string& ice_pwd) {
1653 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1654 cricket::TransportInfo transport_info =
1655 *(desc_.GetTransportInfoByName(content_name));
1656 desc_.RemoveTransportInfoByName(content_name);
1657 transport_info.description.ice_ufrag = ice_ufrag;
1658 transport_info.description.ice_pwd = ice_pwd;
1659 desc_.AddTransportInfo(transport_info);
1660 }
1661
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 void AddFingerprint() {
1663 desc_.RemoveTransportInfoByName(kAudioContentName);
1664 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001665 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001666 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001667 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001668 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1669 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001670 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1671 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001672 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001673 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1674 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001675 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 }
1677
jbauch5869f502017-06-29 12:31:36 -07001678 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001679 audio_desc_ = audio_desc_->Copy();
1680 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001681 audio_desc_->AddRtpHeaderExtension(
1682 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1683 video_desc_->AddRtpHeaderExtension(
1684 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 desc_.RemoveContentByName(kAudioContentName);
1686 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001687 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1688 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 }
1690
1691 void RemoveCryptos() {
1692 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1693 video_desc_->set_cryptos(std::vector<CryptoParams>());
1694 }
1695
Seth Hampson5897a6e2018-04-03 11:16:33 -07001696 // Removes everything in StreamParams from the session description that is
1697 // used for a=ssrc lines.
1698 void RemoveSsrcSignalingFromStreamParams() {
1699 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1700 // With Unified Plan there should be one StreamParams per m= section.
1701 StreamParams& stream =
1702 content_info.media_description()->mutable_streams()[0];
1703 stream.ssrcs.clear();
1704 stream.ssrc_groups.clear();
1705 stream.cname.clear();
1706 }
1707 }
1708
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001709 // Removes all a=ssrc lines from the SDP string, except for the
1710 // "a=ssrc:... cname:..." lines.
1711 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1712 const char kAttributeSsrc[] = "a=ssrc";
1713 const char kAttributeCname[] = "cname";
1714 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1715 while (ssrc_line_pos != std::string::npos) {
1716 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1717 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1718 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1719 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1720 // Only erase a=ssrc lines that don't contain "cname".
1721 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1722 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1723 } else {
1724 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1725 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1726 }
1727 }
1728 }
1729
Seth Hampson5897a6e2018-04-03 11:16:33 -07001730 // Removes all a=ssrc lines from the SDP string.
1731 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1732 const char kAttributeSsrc[] = "a=ssrc";
1733 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1734 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1735 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1736 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1737 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1738 }
1739 }
1740
Steve Anton4e70a722017-11-28 14:57:10 -08001741 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 audio_desc_->set_direction(direction);
1743 video_desc_->set_direction(direction);
1744 std::string new_sdp = kSdpFullString;
1745 ReplaceDirection(direction, &new_sdp);
1746
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001747 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 jdesc_.session_version())) {
1749 return false;
1750 }
Steve Antone831b8c2018-02-01 12:22:16 -08001751 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 EXPECT_EQ(new_sdp, message);
1753 return true;
1754 }
1755
1756 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001757 audio_desc_ = audio_desc_->Copy();
1758 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001759
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 desc_.RemoveContentByName(kAudioContentName);
1761 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001762 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001764 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001766 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1767 audio_rejected ? "" : kPwdVoice);
1768 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1769 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001770
1771 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1773
Steve Antona3a92c22017-12-07 10:27:41 -08001774 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001775 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001776 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 EXPECT_EQ(new_sdp, message);
1778 return true;
1779 }
1780
zstein4b2e0822017-02-17 19:48:38 -08001781 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02001782 std::unique_ptr<SctpDataContentDescription> data(
1783 new SctpDataContentDescription());
1784 sctp_desc_ = data.get();
1785 sctp_desc_->set_use_sctpmap(use_sctpmap);
1786 sctp_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
1787 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001788 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1789 data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001790 desc_.AddTransportInfo(TransportInfo(
1791 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 }
1793
1794 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001795 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 data_desc_ = data.get();
1797
deadbeef67cf2c12016-04-13 10:07:16 -07001798 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 StreamParams data_stream;
1800 data_stream.id = kDataChannelMsid;
1801 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001802 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 data_stream.ssrcs.push_back(kDataChannelSsrc);
1804 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001805 data_desc_->AddCrypto(
1806 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1807 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001809 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001810 desc_.AddTransportInfo(TransportInfo(
1811 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 }
1813
Steve Anton4e70a722017-11-28 14:57:10 -08001814 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 std::string new_sdp = kSdpFullString;
1816 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001817 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818
1819 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1820
1821 audio_desc_->set_direction(direction);
1822 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001823 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 jdesc_.session_version())) {
1825 return false;
1826 }
1827 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1828 return true;
1829 }
1830
1831 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001832 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001834 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001836
Steve Antonb1c1de12017-12-21 15:14:30 -08001837 audio_desc_ = audio_desc_->Copy();
1838 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 desc_.RemoveContentByName(kAudioContentName);
1840 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001841 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001843 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001845 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1846 audio_rejected ? "" : kPwdVoice);
1847 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1848 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001849 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001850 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001851 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 return false;
1853 }
deadbeef3f7219b2015-12-28 15:17:14 -08001854 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 return true;
1856 }
1857
Yves Gerey665174f2018-06-19 15:03:05 +02001858 void TestDeserializeExtmap(bool session_level,
1859 bool media_level,
1860 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001861 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001862 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001863 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001865 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 std::string sdp_with_extmap = kSdpString;
1867 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001868 InjectAfter(kSessionTime,
1869 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1870 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 &sdp_with_extmap);
1872 }
1873 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001874 InjectAfter(kAttributeIcePwdVoice,
1875 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1876 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001878 InjectAfter(kAttributeIcePwdVideo,
1879 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1880 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 &sdp_with_extmap);
1882 }
1883 // The extmap can't be present at the same time in both session level and
1884 // media level.
1885 if (session_level && media_level) {
1886 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001887 EXPECT_FALSE(
1888 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1890 } else {
1891 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1892 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1893 }
1894 }
1895
1896 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001897 const std::string& name,
1898 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 cricket::CodecParameterMap::const_iterator found = params.find(name);
1900 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001901 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 }
1903
1904 void TestDeserializeCodecParams(const CodecParams& params,
1905 JsepSessionDescription* jdesc_output) {
1906 std::string sdp =
1907 "v=0\r\n"
1908 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1909 "s=-\r\n"
1910 "t=0 0\r\n"
1911 // Include semantics for WebRTC Media Streams since it is supported by
1912 // this parser, and will be added to the SDP when serializing a session
1913 // description.
1914 "a=msid-semantic: WMS\r\n"
1915 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001916 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 // Pltype 111 listed before 103 and 104 in the map.
1918 "a=rtpmap:111 opus/48000/2\r\n"
1919 // Pltype 103 listed before 104.
1920 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001921 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001922 "a=fmtp:111 0-15,66,70\r\n"
1923 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001925 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001926 << "; sprop-stereo=" << params.sprop_stereo
1927 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001928 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 << "a=ptime:" << params.ptime << "\r\n"
1930 << "a=maxptime:" << params.max_ptime << "\r\n";
1931 sdp += os.str();
1932
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001933 os.clear();
1934 os.str("");
1935 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001936 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001937 << "a=rtpmap:99 VP8/90000\r\n"
1938 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001939 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001940 sdp += os.str();
1941
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 // Deserialize
1943 SdpParseError error;
1944 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1945
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001947 GetFirstAudioContentDescription(jdesc_output->description());
1948 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 ASSERT_FALSE(acd->codecs().empty());
1950 cricket::AudioCodec opus = acd->codecs()[0];
1951 EXPECT_EQ("opus", opus.name);
1952 EXPECT_EQ(111, opus.id);
1953 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1954 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1955 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1956 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001957 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1958 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1960 cricket::AudioCodec codec = acd->codecs()[i];
1961 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1962 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001964
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001965 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001966 GetFirstVideoContentDescription(jdesc_output->description());
1967 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001968 ASSERT_FALSE(vcd->codecs().empty());
1969 cricket::VideoCodec vp8 = vcd->codecs()[0];
1970 EXPECT_EQ("VP8", vp8.name);
1971 EXPECT_EQ(99, vp8.id);
1972 cricket::VideoCodec rtx = vcd->codecs()[1];
1973 EXPECT_EQ("RTX", rtx.name);
1974 EXPECT_EQ(95, rtx.id);
1975 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 }
1977
1978 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1979 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001980 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 "v=0\r\n"
1982 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1983 "s=-\r\n"
1984 "t=0 0\r\n"
1985 // Include semantics for WebRTC Media Streams since it is supported by
1986 // this parser, and will be added to the SDP when serializing a session
1987 // description.
1988 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001989 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001990 "a=rtpmap:111 opus/48000/2\r\n";
1991 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 "m=video 3457 RTP/SAVPF 101\r\n"
1993 "a=rtpmap:101 VP8/90000\r\n"
1994 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001995 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001996 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001998 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001999 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002000 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002001 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002002 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 // Deserialize
2004 SdpParseError error;
2005 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002007 GetFirstAudioContentDescription(jdesc_output->description());
2008 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 ASSERT_FALSE(acd->codecs().empty());
2010 cricket::AudioCodec opus = acd->codecs()[0];
2011 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002012 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2013 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002016 GetFirstVideoContentDescription(jdesc_output->description());
2017 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 ASSERT_FALSE(vcd->codecs().empty());
2019 cricket::VideoCodec vp8 = vcd->codecs()[0];
2020 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2021 vp8.name.c_str());
2022 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002023 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2024 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2025 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2026 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2027 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2028 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2029 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2030 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 }
2032
2033 // Two SDP messages can mean the same thing but be different strings, e.g.
2034 // some of the lines can be serialized in different order.
2035 // However, a deserialized description can be compared field by field and has
2036 // no order. If deserializer has already been tested, serializing then
2037 // deserializing and comparing JsepSessionDescription will test
2038 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002039 void TestSerialize(const JsepSessionDescription& jdesc) {
2040 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002041 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 SdpParseError error;
2043 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2044 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2045 }
2046
zhihuang38989e52017-03-21 11:04:53 -07002047 // Calling 'Initialize' with a copy of the inner SessionDescription will
2048 // create a copy of the JsepSessionDescription without candidates. The
2049 // 'connection address' field, previously set from the candidates, must also
2050 // be reset.
2051 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2052 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2053 rtc::SocketAddress video_addr("0.0.0.0", 9);
2054 audio_desc_->set_connection_address(audio_addr);
2055 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002056 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002057 }
2058
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 protected:
2060 SessionDescription desc_;
2061 AudioContentDescription* audio_desc_;
2062 VideoContentDescription* video_desc_;
2063 DataContentDescription* data_desc_;
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002064 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002066 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 JsepSessionDescription jdesc_;
2068};
2069
2070void TestMismatch(const std::string& string1, const std::string& string2) {
2071 int position = 0;
2072 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2073 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002074 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 break;
2076 }
2077 }
2078 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2079 << " character\n"
2080 << " 1: " << string1.substr(position, 20) << "\n"
2081 << " 2: " << string2.substr(position, 20) << "\n";
2082}
2083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2085 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002086 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 TestMismatch(std::string(kSdpFullString), message);
2088}
2089
2090TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002091 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002092 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093}
2094
2095// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2096// the case in a DTLS offer.
2097TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2098 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002099 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002100 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002101 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
2103 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002104 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2105 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106
2107 EXPECT_EQ(sdp_with_fingerprint, message);
2108}
2109
2110// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2111// be the case in a DTLS answer.
2112TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2113 AddFingerprint();
2114 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002115 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002116 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002117 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118
2119 std::string sdp_with_fingerprint = kSdpString;
2120 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2121 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002122 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2123 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124
2125 EXPECT_EQ(sdp_with_fingerprint, message);
2126}
2127
2128TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2129 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002130 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002131 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002132 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 EXPECT_EQ(std::string(kSdpString), message);
2134}
2135
2136TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2137 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2138 group.AddContentName(kAudioContentName);
2139 group.AddContentName(kVideoContentName);
2140 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002141 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002143 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 std::string sdp_with_bundle = kSdpFullString;
2145 InjectAfter(kSessionTime,
2146 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2147 &sdp_with_bundle);
2148 EXPECT_EQ(sdp_with_bundle, message);
2149}
2150
2151TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002152 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002154 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002156 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002158 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002160 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002162 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 &sdp_with_bandwidth);
2164 EXPECT_EQ(sdp_with_bandwidth, message);
2165}
2166
2167TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2168 std::vector<std::string> transport_options;
2169 transport_options.push_back(kIceOption1);
2170 transport_options.push_back(kIceOption3);
2171 AddIceOptions(kAudioContentName, transport_options);
2172 transport_options.clear();
2173 transport_options.push_back(kIceOption2);
2174 transport_options.push_back(kIceOption3);
2175 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002176 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002178 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002180 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002182 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 &sdp_with_ice_options);
2184 EXPECT_EQ(sdp_with_ice_options, message);
2185}
2186
2187TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002188 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189}
2190
2191TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002192 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193}
2194
2195TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002196 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197}
2198
2199TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2200 EXPECT_TRUE(TestSerializeRejected(true, false));
2201}
2202
2203TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2204 EXPECT_TRUE(TestSerializeRejected(false, true));
2205}
2206
2207TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2208 EXPECT_TRUE(TestSerializeRejected(true, true));
2209}
2210
2211TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2212 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002213 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214
zhihuang38989e52017-03-21 11:04:53 -07002215 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002216 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
2218 std::string expected_sdp = kSdpString;
2219 expected_sdp.append(kSdpRtpDataChannelString);
2220 EXPECT_EQ(expected_sdp, message);
2221}
2222
2223TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002224 bool use_sctpmap = true;
2225 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002226 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227
zhihuang38989e52017-03-21 11:04:53 -07002228 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002229 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230
2231 std::string expected_sdp = kSdpString;
2232 expected_sdp.append(kSdpSctpDataChannelString);
2233 EXPECT_EQ(message, expected_sdp);
2234}
2235
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002236void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2237 const SessionDescription& desc,
2238 int port) {
2239 // Take our pre-built session description and change the SCTP port.
2240 cricket::SessionDescription* mutant = desc.Copy();
2241 SctpDataContentDescription* dcdesc =
2242 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2243 dcdesc->set_port(port);
2244 // Note: mutant's owned by jdesc now.
2245 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
2246}
2247
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002248TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002249 bool use_sctpmap = true;
2250 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002251 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002252 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002253
2254 const int kNewPort = 1234;
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002255 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002256
Steve Antone831b8c2018-02-01 12:22:16 -08002257 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002258
2259 std::string expected_sdp = kSdpString;
2260 expected_sdp.append(kSdpSctpDataChannelString);
2261
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002262 absl::StrReplaceAll(
2263 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2264 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002265
2266 EXPECT_EQ(expected_sdp, message);
2267}
2268
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002269TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002270 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002271 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002272 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002273 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002274 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002275
2276 std::string expected_sdp = kSdpString;
2277 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002278 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002279 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002280 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002281 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002282}
2283
Johannes Kron0854eb62018-10-10 22:33:20 +02002284TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002285 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002286 TestSerialize(jdesc_);
2287}
2288
2289TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2290 cricket::MediaContentDescription* video_desc =
2291 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2292 ASSERT_TRUE(video_desc);
2293 cricket::MediaContentDescription* audio_desc =
2294 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2295 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002296 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002297 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002298 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002299 cricket::MediaContentDescription::kMedia);
2300 TestSerialize(jdesc_);
2301}
2302
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002304 bool encrypted = false;
2305 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002306 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002307 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002308 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309
2310 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002311 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2312 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313
2314 EXPECT_EQ(sdp_with_extmap, message);
2315}
2316
jbauch5869f502017-06-29 12:31:36 -07002317TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2318 bool encrypted = true;
2319 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002320 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002321 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002322 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002323 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002324}
2325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326TEST_F(WebRtcSdpTest, SerializeCandidates) {
2327 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002328 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002329
2330 Candidate candidate_with_ufrag(candidates_.front());
2331 candidate_with_ufrag.set_username("ABC");
2332 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2333 candidate_with_ufrag));
2334 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2335 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002336
2337 Candidate candidate_with_network_info(candidates_.front());
2338 candidate_with_network_info.set_network_id(1);
2339 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2340 candidate_with_network_info));
2341 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2342 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2343 candidate_with_network_info.set_network_cost(999);
2344 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2345 candidate_with_network_info));
2346 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2347 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2348 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349}
2350
Zach Steinb336c272018-08-09 01:16:13 -07002351TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2352 rtc::SocketAddress address("a.test", 1234);
2353 cricket::Candidate candidate(
2354 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2355 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2356 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2357 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2358 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2359}
2360
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002361// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2362// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002363TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002364 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002365 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2366 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2367 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002368 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002369 std::unique_ptr<IceCandidateInterface> jcandidate(
2370 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002371
2372 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2373 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2374}
2375
htaa6b99442016-04-12 10:29:17 -07002376TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002377 cricket::VideoCodec h264_codec("H264");
2378 h264_codec.SetParam("profile-level-id", "42e01f");
2379 h264_codec.SetParam("level-asymmetry-allowed", "1");
2380 h264_codec.SetParam("packetization-mode", "1");
2381 video_desc_->AddCodec(h264_codec);
2382
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002383 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002384
Steve Antone831b8c2018-02-01 12:22:16 -08002385 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002386 size_t after_pt = message.find(" H264/90000");
2387 ASSERT_NE(after_pt, std::string::npos);
2388 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2389 ASSERT_NE(before_pt, std::string::npos);
2390 before_pt += strlen("a=rtpmap:");
2391 std::string pt = message.substr(before_pt, after_pt - before_pt);
2392 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2393 std::string to_find = "a=fmtp:" + pt + " ";
2394 size_t fmtp_pos = message.find(to_find);
2395 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002396 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002397 ASSERT_NE(std::string::npos, fmtp_endpos);
2398 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2399 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2400 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2401 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002402 // Check that there are no spaces after semicolons.
2403 // https://bugs.webrtc.org/5793
2404 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002405}
2406
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002408 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 // Deserialize
2410 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2411 // Verify
2412 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2413}
2414
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002415TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002416 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002417 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002418 "v=0\r\n"
2419 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2420 "s=-\r\n"
2421 "t=0 0\r\n"
2422 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002423 // Deserialize
2424 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2425 EXPECT_EQ(0u, jdesc.description()->contents().size());
2426}
2427
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002429 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 std::string sdp_without_carriage_return = kSdpFullString;
2431 Replace("\r\n", "\n", &sdp_without_carriage_return);
2432 // Deserialize
2433 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2434 // Verify
2435 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2436}
2437
2438TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2439 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002440 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002441 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002442 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002443 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2445 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2446}
2447
2448TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2449 static const char kSdpNoRtpmapString[] =
2450 "v=0\r\n"
2451 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2452 "s=-\r\n"
2453 "t=0 0\r\n"
2454 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2455 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002456 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 // The rtpmap line for static payload codec is optional.
2458 "a=rtpmap:18 G729/16000\r\n"
2459 "a=rtpmap:103 ISAC/16000\r\n";
2460
Steve Antona3a92c22017-12-07 10:27:41 -08002461 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2463 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002464 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002466 // The codecs in the AudioContentDescription should be in the same order as
2467 // the payload types (<fmt>s) on the m= line.
2468 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2469 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002470 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 EXPECT_EQ(ref_codecs, audio->codecs());
2472}
2473
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002474TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2475 static const char kSdpNoRtpmapString[] =
2476 "v=0\r\n"
2477 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2478 "s=-\r\n"
2479 "t=0 0\r\n"
2480 "m=audio 49232 RTP/AVP 18 103\r\n"
2481 "a=fmtp:18 annexb=yes\r\n"
2482 "a=rtpmap:103 ISAC/16000\r\n";
2483
Steve Antona3a92c22017-12-07 10:27:41 -08002484 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002485 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2486 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002487 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002488
2489 cricket::AudioCodec g729 = audio->codecs()[0];
2490 EXPECT_EQ("G729", g729.name);
2491 EXPECT_EQ(8000, g729.clockrate);
2492 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002493 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002494 ASSERT_TRUE(found != g729.params.end());
2495 EXPECT_EQ(found->second, "yes");
2496
2497 cricket::AudioCodec isac = audio->codecs()[1];
2498 EXPECT_EQ("ISAC", isac.name);
2499 EXPECT_EQ(103, isac.id);
2500 EXPECT_EQ(16000, isac.clockrate);
2501}
2502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503// Ensure that we can deserialize SDP with a=fingerprint properly.
2504TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2505 // Add a DTLS a=fingerprint attribute to our session description.
2506 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002507 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002508 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 jdesc_.session_version()));
2510
Steve Antona3a92c22017-12-07 10:27:41 -08002511 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 std::string sdp_with_fingerprint = kSdpString;
2513 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2514 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2515 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2516 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2517}
2518
2519TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002520 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 std::string sdp_with_bundle = kSdpFullString;
2522 InjectAfter(kSessionTime,
2523 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2524 &sdp_with_bundle);
2525 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2526 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2527 group.AddContentName(kAudioContentName);
2528 group.AddContentName(kVideoContentName);
2529 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002530 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 jdesc_.session_version()));
2532 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2533}
2534
2535TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002536 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002538 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002540 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002542 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002543 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002545 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002547 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 jdesc_.session_version()));
2549 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2550}
2551
2552TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002553 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002555 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002557 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002559 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 &sdp_with_ice_options);
2561 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2562 std::vector<std::string> transport_options;
2563 transport_options.push_back(kIceOption3);
2564 transport_options.push_back(kIceOption1);
2565 AddIceOptions(kAudioContentName, transport_options);
2566 transport_options.clear();
2567 transport_options.push_back(kIceOption3);
2568 transport_options.push_back(kIceOption2);
2569 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002570 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 jdesc_.session_version()));
2572 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2573}
2574
2575TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2576 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002577 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 std::string sdp_with_ufrag_pwd = kSdpFullString;
2579 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2580 // Add session level ufrag and pwd
2581 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002582 "a=ice-pwd:session+level+icepwd\r\n"
2583 "a=ice-ufrag:session+level+iceufrag\r\n",
2584 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002586 InjectAfter(
2587 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2589 &sdp_with_ufrag_pwd);
2590 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002591 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2592 "media+level+icepwd"));
2593 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2594 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2596 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2597}
2598
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002600 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601}
2602
2603TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002604 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605}
2606
2607TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002608 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609}
2610
2611TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2612 EXPECT_TRUE(TestDeserializeRejected(true, false));
2613}
2614
2615TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2616 EXPECT_TRUE(TestDeserializeRejected(false, true));
2617}
2618
2619TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2620 EXPECT_TRUE(TestDeserializeRejected(true, true));
2621}
2622
2623// Tests that we can still handle the sdp uses mslabel and label instead of
2624// msid for backward compatibility.
2625TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002626 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002627 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 std::string sdp_without_msid = kSdpFullString;
2629 Replace("msid", "xmsid", &sdp_without_msid);
2630 // Deserialize
2631 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2632 // Verify
2633 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002634 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2635 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636}
2637
Johannes Kron0854eb62018-10-10 22:33:20 +02002638TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002639 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002640 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2641 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2642 // Deserialize
2643 JsepSessionDescription jdesc_deserialized(kDummyType);
2644 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2645 // Verify
2646 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2647}
2648
2649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002650 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002651 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2652 // Deserialize
2653 JsepSessionDescription jdesc_deserialized(kDummyType);
2654 EXPECT_TRUE(
2655 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2656 // Verify
2657 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2658}
2659
2660TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2661 cricket::MediaContentDescription* video_desc =
2662 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2663 ASSERT_TRUE(video_desc);
2664 cricket::MediaContentDescription* audio_desc =
2665 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2666 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002667 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002668 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002669 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002670 cricket::MediaContentDescription::kMedia);
2671
2672 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2673 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2674 &sdp_with_extmap_allow_mixed);
2675 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2676 &sdp_with_extmap_allow_mixed);
2677
2678 // Deserialize
2679 JsepSessionDescription jdesc_deserialized(kDummyType);
2680 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2681 // Verify
2682 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2683}
2684
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2686 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2687
2688 std::string sdp = kSdpOneCandidate;
2689 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2690 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2691 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2692 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002693 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694
2695 // Candidate line without generation extension.
2696 sdp = kSdpOneCandidate;
2697 Replace(" generation 2", "", &sdp);
2698 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2699 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2700 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2701 Candidate expected = jcandidate_->candidate();
2702 expected.set_generation(0);
2703 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2704
honghaiza0c44ea2016-03-23 16:07:48 -07002705 // Candidate with network id and/or cost.
2706 sdp = kSdpOneCandidate;
2707 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2708 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2709 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2710 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2711 expected = jcandidate_->candidate();
2712 expected.set_network_id(2);
2713 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2714 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2715 // Add network cost
2716 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2717 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2718 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2719 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2720
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002721 sdp = kSdpTcpActiveCandidate;
2722 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2723 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002724 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002725 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2726 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2727 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002728 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2729 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002730 EXPECT_TRUE(
2731 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002732 sdp = kSdpTcpPassiveCandidate;
2733 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2734 sdp = kSdpTcpSOCandidate;
2735 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736}
2737
2738// This test verifies the deserialization of candidate-attribute
2739// as per RFC 5245. Candiate-attribute will be of the format
2740// candidate:<blah>. This format will be used when candidates
2741// are trickled.
2742TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2743 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2744
2745 std::string candidate_attribute = kRawCandidate;
2746 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2747 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2748 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2749 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2750 EXPECT_EQ(2u, jcandidate.candidate().generation());
2751
2752 // Candidate line without generation extension.
2753 candidate_attribute = kRawCandidate;
2754 Replace(" generation 2", "", &candidate_attribute);
2755 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2756 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2757 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2758 Candidate expected = jcandidate_->candidate();
2759 expected.set_generation(0);
2760 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2761
2762 // Candidate line without candidate:
2763 candidate_attribute = kRawCandidate;
2764 Replace("candidate:", "", &candidate_attribute);
2765 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2766
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002767 // Candidate line with IPV6 address.
2768 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002769
2770 // Candidate line with hostname address.
2771 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002772}
2773
2774// This test verifies that the deserialization of an invalid candidate string
2775// fails.
2776TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002777 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002778
2779 std::string candidate_attribute = kRawCandidate;
2780 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002782
2783 candidate_attribute = kSdpOneCandidate;
2784 candidate_attribute.replace(0, 1, "x");
2785 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2786
2787 candidate_attribute = kRawCandidate;
2788 candidate_attribute.append("\r\n");
2789 candidate_attribute.append(kRawCandidate);
2790 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2791
2792 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793}
2794
2795TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2796 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002797 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002798 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799
2800 std::string sdp_with_data = kSdpString;
2801 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002802 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803
2804 // Deserialize
2805 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2806 // Verify
2807 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2808}
2809
2810TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002811 bool use_sctpmap = true;
2812 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002813 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002814 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815
2816 std::string sdp_with_data = kSdpString;
2817 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002818 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819
lally@webrtc.org36300852015-02-24 20:19:35 +00002820 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2821 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2822 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2823
2824 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002825 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2826 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002827 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2828 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2829
2830 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002831 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2832 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2834 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2835}
2836
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002837TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002838 bool use_sctpmap = false;
2839 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002840 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002841 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002842
2843 std::string sdp_with_data = kSdpString;
2844 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002845 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002846
lally@webrtc.org36300852015-02-24 20:19:35 +00002847 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002848 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2849 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002850
lally@webrtc.org36300852015-02-24 20:19:35 +00002851 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002852 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2853 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002854 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2855 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002856
lally@webrtc.org36300852015-02-24 20:19:35 +00002857 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002858 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2859 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002860 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2861 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2862}
2863
lally69f57602015-10-08 10:15:04 -07002864TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002865 bool use_sctpmap = false;
2866 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002867 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002868 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002869
2870 std::string sdp_with_data = kSdpString;
2871 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002872 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002873
2874 // Verify with DTLS/SCTP.
2875 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2876 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2877
2878 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002879 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2880 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002881 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2882 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2883
2884 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002885 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2886 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002887 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2888 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2889}
2890
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002891// Helper function to set the max-message-size parameter in the
2892// SCTP data codec.
2893void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002894 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002895 JsepSessionDescription* jdesc) {
2896 cricket::SessionDescription* mutant = desc.Copy();
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002897 SctpDataContentDescription* dcdesc =
2898 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2899 dcdesc->set_max_message_size(new_value);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002900 jdesc->Initialize(mutant, kSessionId, kSessionVersion);
2901}
2902
2903TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2904 bool use_sctpmap = false;
2905 AddSctpDataChannel(use_sctpmap);
2906 JsepSessionDescription jdesc(kDummyType);
2907 std::string sdp_with_data = kSdpString;
2908
2909 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2910 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002911 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002912 JsepSessionDescription jdesc_output(kDummyType);
2913
2914 // Verify with DTLS/SCTP.
2915 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2916 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2917
2918 // Verify with UDP/DTLS/SCTP.
2919 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2920 kUdpDtlsSctp);
2921 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2922 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2923
2924 // Verify with TCP/DTLS/SCTP.
2925 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2926 kTcpDtlsSctp);
2927 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2928 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2929}
2930
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002931// Test to check the behaviour if sctp-port is specified
2932// on the m= line and in a=sctp-port.
2933TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002934 bool use_sctpmap = true;
2935 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002936 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002937 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002938
2939 std::string sdp_with_data = kSdpString;
2940 // Append m= attributes
2941 sdp_with_data.append(kSdpSctpDataChannelString);
2942 // Append a=sctp-port attribute
2943 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002944 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002945
2946 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2947}
2948
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002949// For crbug/344475.
2950TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2951 std::string sdp_with_data = kSdpString;
2952 sdp_with_data.append(kSdpSctpDataChannelString);
2953 // Remove the "\n" at the end.
2954 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002955 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002956
2957 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2958 // No crash is a pass.
2959}
2960
zstein4b2e0822017-02-17 19:48:38 -08002961TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2962 bool use_sctpmap = true;
2963 AddSctpDataChannel(use_sctpmap);
2964
2965 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002966 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002967 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00002968
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002969 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002970 std::string sdp_with_data = kSdpString;
2971 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002972 absl::StrReplaceAll(
2973 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2974 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002975 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002976
2977 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2978 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002979}
2980
2981TEST_F(WebRtcSdpTest,
2982 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2983 bool use_sctpmap = false;
2984 AddSctpDataChannel(use_sctpmap);
2985
Steve Antona3a92c22017-12-07 10:27:41 -08002986 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02002987 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002988
2989 // We need to test the deserialized JsepSessionDescription from
2990 // kSdpSctpDataChannelStringWithSctpPort for
2991 // draft-ietf-mmusic-sctp-sdp-07
2992 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002993 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002994 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002995 absl::StrReplaceAll(
2996 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2997 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002998 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002999
3000 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3001 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003002}
3003
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003004TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003005 // We want to test that deserializing data content limits bandwidth
3006 // settings (it should never be greater than the default).
3007 // This should prevent someone from using unlimited data bandwidth through
3008 // JS and "breaking the Internet".
3009 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003010 std::string sdp_with_bandwidth = kSdpString;
3011 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003012 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003013 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003014 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003015
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003016 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3017}
3018
3019TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003020 bool use_sctpmap = true;
3021 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003022 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand8a9193c2019-04-16 21:26:47 +02003023 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003024 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003025 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003026
3027 std::string sdp_with_bandwidth = kSdpString;
3028 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003029 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003030 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003031 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003032
3033 // SCTP has congestion control, so we shouldn't limit the bandwidth
3034 // as we do for RTP.
3035 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003036 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3037}
3038
Yves Gerey665174f2018-06-19 15:03:05 +02003039class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003040 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003041
3042TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003043 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003044 bool encrypted = GetParam();
3045 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046}
3047
Yves Gerey665174f2018-06-19 15:03:05 +02003048TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003049 bool encrypted = GetParam();
3050 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051}
3052
Yves Gerey665174f2018-06-19 15:03:05 +02003053TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003054 bool encrypted = GetParam();
3055 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056}
3057
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003058INSTANTIATE_TEST_SUITE_P(Encrypted,
3059 WebRtcSdpExtmapTest,
3060 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003061
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003062TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003063 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003064 std::string sdp = kSdpFullString;
3065 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3066 // Deserialize
3067 SdpParseError error;
3068 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003069 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003070 EXPECT_EQ(lastline, error.line);
3071 EXPECT_EQ("Invalid SDP line.", error.description);
3072}
3073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3075 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3076 std::string new_sdp = kSdpOneCandidate;
3077 Replace("udp", "unsupported_transport", &new_sdp);
3078 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3079 new_sdp = kSdpOneCandidate;
3080 Replace("udp", "uDP", &new_sdp);
3081 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3082 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3083 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3084 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3085}
3086
honghaiza54a0802015-12-16 18:37:23 -08003087TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003089 EXPECT_TRUE(
3090 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3092 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3093 Candidate ref_candidate = jcandidate_->candidate();
3094 ref_candidate.set_username("user_rtp");
3095 ref_candidate.set_password("password_rtp");
3096 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3097}
3098
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003099TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003100 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003101
3102 // Deserialize
3103 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3104
3105 // Verify
3106 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003107 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003108 EXPECT_TRUE(audio->conference_mode());
3109
3110 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003111 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003112 EXPECT_TRUE(video->conference_mode());
3113}
3114
deadbeefd45aea82017-09-16 01:24:29 -07003115TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003116 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003117
3118 // We tested deserialization already above, so just test that if we serialize
3119 // and deserialize the flag doesn't disappear.
3120 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003121 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003122 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3123
3124 // Verify.
3125 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003126 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003127 EXPECT_TRUE(audio->conference_mode());
3128
3129 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003130 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003131 EXPECT_TRUE(video->conference_mode());
3132}
3133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3135 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003136 const char kSdpEmptyType[] = " =candidate";
3137 const char kSdpEqualAsPlus[] = "a+candidate";
3138 const char kSdpSpaceAfterEqual[] = "a= candidate";
3139 const char kSdpUpperType[] = "A=candidate";
3140 const char kSdpEmptyLine[] = "";
3141 const char kSdpMissingValue[] = "a=";
3142
Yves Gerey665174f2018-06-19 15:03:05 +02003143 const char kSdpBrokenFingerprint[] =
3144 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145 "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 +02003146 const char kSdpExtraField[] =
3147 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003148 "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 +02003149 const char kSdpMissingSpace[] =
3150 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151 "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 +00003152 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003153 const char kSdpMd5[] =
3154 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003155 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156
3157 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003158 ExpectParseFailure("v=", kSdpDestroyer);
3159 ExpectParseFailure("o=", kSdpDestroyer);
3160 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003162 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003163
3164 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003165 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3166 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167
3168 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003169 ExpectParseFailure("a=candidate", kSdpEmptyType);
3170 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3171 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3172 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173
3174 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3175 // because it's orthogonal to what we are replacing and hence
3176 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003177 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3178 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3179 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3180 ExpectParseFailure("a=sendrecv", kSdpMd5);
3181
3182 // Empty Line
3183 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3184 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003185}
3186
3187TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3188 // ssrc
3189 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003190 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003191 // crypto
3192 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3193 // rtpmap
3194 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3195 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3196 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3197 // candidate
3198 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3199 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3200 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3201 ExpectParseFailure("rport 2346", "rport badvalue");
3202 ExpectParseFailure("rport 2346 generation 2",
3203 "rport 2346 generation badvalue");
3204 // m line
3205 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3206 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3207
3208 // bandwidth
3209 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003210 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003211 // rtcp-fb
3212 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3213 "a=rtcp-fb:badvalue nack\r\n",
3214 "a=rtcp-fb:badvalue nack");
3215 // extmap
3216 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3217 "a=extmap:badvalue http://example.com\r\n",
3218 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003219}
3220
3221TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003222 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003223
3224 const char kSdpWithReorderedPlTypesString[] =
3225 "v=0\r\n"
3226 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3227 "s=-\r\n"
3228 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003229 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003230 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3231 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003233 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234
3235 // Deserialize
3236 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3237
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003239 GetFirstAudioContentDescription(jdesc_output.description());
3240 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003241 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003242 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3243 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244 EXPECT_EQ(104, acd->codecs()[0].id);
3245}
3246
3247TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003248 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 CodecParams params;
3250 params.max_ptime = 40;
3251 params.ptime = 30;
3252 params.min_ptime = 10;
3253 params.sprop_stereo = 1;
3254 params.stereo = 1;
3255 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003256 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003258 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259}
3260
3261TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3262 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003263 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003265 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266}
3267
3268TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3269 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003270 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003272 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273}
3274
3275TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003276 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277
3278 const char kSdpWithFmtpString[] =
3279 "v=0\r\n"
3280 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3281 "s=-\r\n"
3282 "t=0 0\r\n"
3283 "m=video 3457 RTP/SAVPF 120\r\n"
3284 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003285 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3286
3287 // Deserialize
3288 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003289 EXPECT_TRUE(
3290 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003291
Donald Curtis0e07f922015-05-15 09:21:23 -07003292 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003293 GetFirstVideoContentDescription(jdesc_output.description());
3294 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003295 ASSERT_FALSE(vcd->codecs().empty());
3296 cricket::VideoCodec vp8 = vcd->codecs()[0];
3297 EXPECT_EQ("VP8", vp8.name);
3298 EXPECT_EQ(120, vp8.id);
3299 cricket::CodecParameterMap::iterator found =
3300 vp8.params.find("x-google-min-bitrate");
3301 ASSERT_TRUE(found != vp8.params.end());
3302 EXPECT_EQ(found->second, "10");
3303 found = vp8.params.find("x-google-max-quantization");
3304 ASSERT_TRUE(found != vp8.params.end());
3305 EXPECT_EQ(found->second, "40");
3306}
3307
johan2d8d23e2016-06-03 01:22:42 -07003308TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003309 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003310
3311 const char kSdpWithFmtpString[] =
3312 "v=0\r\n"
3313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3314 "s=-\r\n"
3315 "t=0 0\r\n"
3316 "m=video 49170 RTP/AVP 98\r\n"
3317 "a=rtpmap:98 H264/90000\r\n"
3318 "a=fmtp:98 profile-level-id=42A01E; "
3319 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3320
3321 // Deserialize.
3322 SdpParseError error;
3323 EXPECT_TRUE(
3324 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3325
johan2d8d23e2016-06-03 01:22:42 -07003326 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003327 GetFirstVideoContentDescription(jdesc_output.description());
3328 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003329 ASSERT_FALSE(vcd->codecs().empty());
3330 cricket::VideoCodec h264 = vcd->codecs()[0];
3331 EXPECT_EQ("H264", h264.name);
3332 EXPECT_EQ(98, h264.id);
3333 cricket::CodecParameterMap::const_iterator found =
3334 h264.params.find("profile-level-id");
3335 ASSERT_TRUE(found != h264.params.end());
3336 EXPECT_EQ(found->second, "42A01E");
3337 found = h264.params.find("sprop-parameter-sets");
3338 ASSERT_TRUE(found != h264.params.end());
3339 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3340}
3341
Donald Curtis0e07f922015-05-15 09:21:23 -07003342TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003343 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003344
3345 const char kSdpWithFmtpString[] =
3346 "v=0\r\n"
3347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3348 "s=-\r\n"
3349 "t=0 0\r\n"
3350 "m=video 3457 RTP/SAVPF 120\r\n"
3351 "a=rtpmap:120 VP8/90000\r\n"
3352 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353
3354 // Deserialize
3355 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003356 EXPECT_TRUE(
3357 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003360 GetFirstVideoContentDescription(jdesc_output.description());
3361 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 ASSERT_FALSE(vcd->codecs().empty());
3363 cricket::VideoCodec vp8 = vcd->codecs()[0];
3364 EXPECT_EQ("VP8", vp8.name);
3365 EXPECT_EQ(120, vp8.id);
3366 cricket::CodecParameterMap::iterator found =
3367 vp8.params.find("x-google-min-bitrate");
3368 ASSERT_TRUE(found != vp8.params.end());
3369 EXPECT_EQ(found->second, "10");
3370 found = vp8.params.find("x-google-max-quantization");
3371 ASSERT_TRUE(found != vp8.params.end());
3372 EXPECT_EQ(found->second, "40");
3373}
3374
ossuaa4b0772017-01-30 07:41:18 -08003375TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003376 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003377
3378 cricket::AudioCodecs codecs = acd->codecs();
3379 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3380 acd->set_codecs(codecs);
3381
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003382 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003383 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003384 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003385 std::string sdp_with_fmtp = kSdpFullString;
3386 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3387 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3388 &sdp_with_fmtp);
3389 EXPECT_EQ(sdp_with_fmtp, message);
3390}
3391
3392TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003393 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003394
3395 cricket::AudioCodecs codecs = acd->codecs();
3396 codecs[0].params["stereo"] = "1";
3397 acd->set_codecs(codecs);
3398
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003399 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003400 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003401 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003402 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003403 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003404 &sdp_with_fmtp);
3405 EXPECT_EQ(sdp_with_fmtp, message);
3406}
3407
3408TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003409 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003410
3411 cricket::AudioCodecs codecs = acd->codecs();
3412 codecs[0].params["ptime"] = "20";
3413 codecs[0].params["maxptime"] = "120";
3414 acd->set_codecs(codecs);
3415
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003416 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003417 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003418 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003419 std::string sdp_with_fmtp = kSdpFullString;
3420 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3421 "a=maxptime:120\r\n" // No comma here. String merging!
3422 "a=ptime:20\r\n",
3423 &sdp_with_fmtp);
3424 EXPECT_EQ(sdp_with_fmtp, message);
3425}
3426
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003428 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429
3430 cricket::VideoCodecs codecs = vcd->codecs();
3431 codecs[0].params["x-google-min-bitrate"] = "10";
3432 vcd->set_codecs(codecs);
3433
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003434 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003436 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 std::string sdp_with_fmtp = kSdpFullString;
3438 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003439 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 EXPECT_EQ(sdp_with_fmtp, message);
3441}
3442
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003443TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3444 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003445 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 std::string sdp_with_icelite = kSdpFullString;
3447 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3448 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3449 const cricket::TransportInfo* tinfo1 =
3450 desc->GetTransportInfoByName("audio_content_name");
3451 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3452 const cricket::TransportInfo* tinfo2 =
3453 desc->GetTransportInfoByName("video_content_name");
3454 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003455
3456 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003457 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3459 desc = jdesc_with_icelite.description();
3460 const cricket::TransportInfo* atinfo =
3461 desc->GetTransportInfoByName("audio_content_name");
3462 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3463 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003464 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003466
3467 // Now that we know deserialization works, we can use TestSerialize to test
3468 // serialization.
3469 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470}
3471
3472// Verifies that the candidates in the input SDP are parsed and serialized
3473// correctly in the output SDP.
3474TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3475 std::string sdp_with_data = kSdpString;
3476 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003477 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478
3479 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003480 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003482
3483TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3484 AddFingerprint();
3485 TransportInfo audio_transport_info =
3486 *(desc_.GetTransportInfoByName(kAudioContentName));
3487 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3488 audio_transport_info.description.connection_role);
3489 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003490 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003491
3492 TransportInfo video_transport_info =
3493 *(desc_.GetTransportInfoByName(kVideoContentName));
3494 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3495 video_transport_info.description.connection_role);
3496 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003497 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003498
3499 desc_.RemoveTransportInfoByName(kAudioContentName);
3500 desc_.RemoveTransportInfoByName(kVideoContentName);
3501
3502 desc_.AddTransportInfo(audio_transport_info);
3503 desc_.AddTransportInfo(video_transport_info);
3504
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003505 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003506 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003507 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003508 std::string sdp_with_dtlssetup = kSdpFullString;
3509
3510 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003511 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3512 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003513 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003514 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003515 EXPECT_EQ(sdp_with_dtlssetup, message);
3516}
3517
3518TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003519 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003520 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003521 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003522 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3523 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3524 const cricket::TransportInfo* atinfo =
3525 desc->GetTransportInfoByName("audio_content_name");
3526 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3527 atinfo->description.connection_role);
3528 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003529 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003530 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3531 vtinfo->description.connection_role);
3532}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003533
3534// Verifies that the order of the serialized m-lines follows the order of the
3535// ContentInfo in SessionDescription, and vise versa for deserialization.
3536TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003537 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003538 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3539 kSdpSctpDataChannelString};
3540 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3541 cricket::MEDIA_TYPE_VIDEO,
3542 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003543
3544 // Verifies all 6 permutations.
3545 for (size_t i = 0; i < 6; ++i) {
3546 size_t media_content_in_sdp[3];
3547 // The index of the first media content.
3548 media_content_in_sdp[0] = i / 2;
3549 // The index of the second media content.
3550 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3551 // The index of the third media content.
3552 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3553
3554 std::string sdp_string = kSdpSessionString;
3555 for (size_t i = 0; i < 3; ++i)
3556 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3557
3558 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3559 cricket::SessionDescription* desc = jdesc.description();
3560 EXPECT_EQ(3u, desc->contents().size());
3561
3562 for (size_t i = 0; i < 3; ++i) {
3563 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003564 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003565 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3566 }
3567
Steve Antone831b8c2018-02-01 12:22:16 -08003568 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003569 EXPECT_EQ(sdp_string, serialized_sdp);
3570 }
3571}
deadbeef9d3584c2016-02-16 17:54:10 -08003572
deadbeef25ed4352016-12-12 18:37:36 -08003573TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3574 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003575 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003576 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003577 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3578 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3579}
3580
deadbeef12771a12017-01-03 13:53:47 -08003581// The semantics of "a=bundle-only" are only defined when it's used in
3582// combination with a 0 port on the m= line. We should ignore it if used with a
3583// nonzero port.
3584TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3585 // Make the base bundle-only description but unset the bundle-only flag.
3586 MakeBundleOnlyDescription();
3587 jdesc_.description()->contents()[1].bundle_only = false;
3588
3589 std::string modified_sdp = kBundleOnlySdpFullString;
3590 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003591 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003592 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3593 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003594}
3595
3596TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3597 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003598 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003599}
3600
deadbeef9d3584c2016-02-16 17:54:10 -08003601TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3602 MakePlanBDescription();
3603
Steve Antona3a92c22017-12-07 10:27:41 -08003604 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003605 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3606
3607 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3608}
3609
3610TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3611 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003612 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003613}
3614
3615TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3616 MakeUnifiedPlanDescription();
3617
Steve Antona3a92c22017-12-07 10:27:41 -08003618 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003619 EXPECT_TRUE(
3620 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3621
3622 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3623}
3624
3625TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3626 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003627 TestSerialize(jdesc_);
3628}
3629
Seth Hampson5b4f0752018-04-02 16:31:36 -07003630// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003631// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3632// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003633// with no stream ids and multiple stream ids. For parsing this, the Unified
3634// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3635// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003636TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3637 // Create both msid lines for Plan B and Unified Plan support.
3638 MakeUnifiedPlanDescriptionMultipleStreamIds(
3639 cricket::kMsidSignalingMediaSection |
3640 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003641
3642 JsepSessionDescription deserialized_description(kDummyType);
3643 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3644 &deserialized_description));
3645
3646 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003647 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3648 cricket::kMsidSignalingSsrcAttribute,
3649 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003650}
3651
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003652// Tests the serialization of a Unified Plan SDP that is compatible for both
3653// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3654// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3655// multiple stream ids.
3656TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3657 // Create both msid lines for Plan B and Unified Plan support.
3658 MakeUnifiedPlanDescriptionMultipleStreamIds(
3659 cricket::kMsidSignalingMediaSection |
3660 cricket::kMsidSignalingSsrcAttribute);
3661 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3662 // We explicitly test that the serialized SDP string is equal to the hard
3663 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3664 // take priority over "a=ssrc msid" lines. This means if we just used
3665 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3666 // and still pass, because the deserialized version would be the same.
3667 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3668}
3669
3670// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3671// that signal stream IDs) is deserialized appropriately. It tests the case for
3672// no stream ids and multiple stream ids.
3673TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3674 // Only create a=msid lines for strictly Unified Plan stream ID support.
3675 MakeUnifiedPlanDescriptionMultipleStreamIds(
3676 cricket::kMsidSignalingMediaSection);
3677
3678 JsepSessionDescription deserialized_description(kDummyType);
3679 std::string unified_plan_sdp_string =
3680 kUnifiedPlanSdpFullStringWithSpecialMsid;
3681 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3682 EXPECT_TRUE(
3683 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3684
3685 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3686}
3687
3688// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3689// that signal stream IDs) is serialized appropriately. It tests the case for no
3690// stream ids and multiple stream ids.
3691TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3692 // Only create a=msid lines for strictly Unified Plan stream ID support.
3693 MakeUnifiedPlanDescriptionMultipleStreamIds(
3694 cricket::kMsidSignalingMediaSection);
3695
Seth Hampson5b4f0752018-04-02 16:31:36 -07003696 TestSerialize(jdesc_);
3697}
3698
Seth Hampson5897a6e2018-04-03 11:16:33 -07003699// This tests that a Unified Plan SDP with no a=ssrc lines is
3700// serialized/deserialized appropriately. In this case the
3701// MediaContentDescription will contain a StreamParams object that doesn't have
3702// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3703// SSRC lines.
3704TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3705 MakeUnifiedPlanDescription();
3706 RemoveSsrcSignalingFromStreamParams();
3707 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3708 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3709
3710 JsepSessionDescription deserialized_description(kDummyType);
3711 EXPECT_TRUE(
3712 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3713 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3714}
3715
3716TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3717 MakeUnifiedPlanDescription();
3718 RemoveSsrcSignalingFromStreamParams();
3719
3720 TestSerialize(jdesc_);
3721}
3722
Steve Antone831b8c2018-02-01 12:22:16 -08003723TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3724 JsepSessionDescription jsep_desc(kDummyType);
3725 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3726 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3727}
3728
3729TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3730 JsepSessionDescription jsep_desc(kDummyType);
3731 std::string sdp = kSdpSessionString;
3732 sdp += kSdpSctpDataChannelString;
3733 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3734 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3735}
3736
3737TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3738 JsepSessionDescription jsep_desc(kDummyType);
3739 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3740 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3741 jsep_desc.description()->msid_signaling());
3742}
3743
3744TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3745 JsepSessionDescription jsep_desc(kDummyType);
3746 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3747 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3748 jsep_desc.description()->msid_signaling());
3749}
3750
3751const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3752const char kSsrcAttributeMsidLine[] =
3753 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3754
3755TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3756 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3757 std::string sdp = webrtc::SdpSerialize(jdesc_);
3758
3759 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3760 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3761}
3762
3763TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3764 jdesc_.description()->set_msid_signaling(
3765 cricket::kMsidSignalingSsrcAttribute);
3766 std::string sdp = webrtc::SdpSerialize(jdesc_);
3767
3768 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3769 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3770}
3771
3772TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3773 jdesc_.description()->set_msid_signaling(
3774 cricket::kMsidSignalingMediaSection |
3775 cricket::kMsidSignalingSsrcAttribute);
3776 std::string sdp = webrtc::SdpSerialize(jdesc_);
3777
3778 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3779 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003780}
deadbeef7e146cb2016-09-28 10:04:34 -07003781
3782// Regression test for heap overflow bug:
3783// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3784TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003785 // The issue occurs when the sctp-port attribute is found in a video
3786 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003787 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003788 "v=0\r\n"
3789 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3790 "s=-\r\n"
3791 "t=0 0\r\n"
3792 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3793 "a=sctp-port 5000\r\n"
3794 "a=fmtp:108 foo=10\r\n";
3795
3796 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3797 "sctp-port");
3798}
deadbeefb2362572016-12-13 16:37:06 -08003799
3800// Regression test for integer overflow bug:
3801// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3802TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003803 // Bandwidth attribute is the max signed 32-bit int, which will get
3804 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003805 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003806 "v=0\r\n"
3807 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3808 "s=-\r\n"
3809 "t=0 0\r\n"
3810 "m=video 3457 RTP/SAVPF 120\r\n"
3811 "b=AS:2147483647\r\n"
3812 "foo=fail\r\n";
3813
3814 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3815}
deadbeef7bcdb692017-01-20 12:43:58 -08003816
deadbeefbc88c6b2017-08-02 11:26:34 -07003817// Similar to the above, except that negative values are illegal, not just
3818// error-prone as large values are.
3819// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3820TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3821 static const char kSdpWithNegativeBandwidth[] =
3822 "v=0\r\n"
3823 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3824 "s=-\r\n"
3825 "t=0 0\r\n"
3826 "m=video 3457 RTP/SAVPF 120\r\n"
3827 "b=AS:-1000\r\n";
3828
3829 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3830}
3831
deadbeef3e8016e2017-08-03 17:49:30 -07003832// An exception to the above rule: a value of -1 for b=AS should just be
3833// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3834// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3835// limit", but this is now what ommitting the attribute entirely will do, so
3836// ignoring it will have the intended effect.
3837TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3838 static const char kSdpWithBandwidthOfNegativeOne[] =
3839 "v=0\r\n"
3840 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3841 "s=-\r\n"
3842 "t=0 0\r\n"
3843 "m=video 3457 RTP/SAVPF 120\r\n"
3844 "b=AS:-1\r\n";
3845
Steve Antona3a92c22017-12-07 10:27:41 -08003846 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003847 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003848 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003849 GetFirstVideoContentDescription(jdesc_output.description());
3850 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003851 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3852}
3853
deadbeef7bcdb692017-01-20 12:43:58 -08003854// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3855// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3856// Regression test for:
3857// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3858TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3859 // Important piece is "ufrag foo pwd bar".
3860 static const char kSdpWithIceCredentialsInCandidateString[] =
3861 "v=0\r\n"
3862 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3863 "s=-\r\n"
3864 "t=0 0\r\n"
3865 "m=audio 9 RTP/SAVPF 111\r\n"
3866 "c=IN IP4 0.0.0.0\r\n"
3867 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3868 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3869 "a=rtpmap:111 opus/48000/2\r\n"
3870 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3871 "generation 2 ufrag foo pwd bar\r\n";
3872
Steve Antona3a92c22017-12-07 10:27:41 -08003873 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003874 EXPECT_TRUE(
3875 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3876 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3877 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003878 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003879 cricket::Candidate c = candidates->at(0)->candidate();
3880 EXPECT_EQ("ufrag_voice", c.username());
3881 EXPECT_EQ("pwd_voice", c.password());
3882}
deadbeef90f1e1e2017-02-10 12:35:05 -08003883
Johannes Kron211856b2018-09-06 12:12:28 +02003884// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3885// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3886// Regression test for:
3887// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3888TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3889 static const char kSdpWithFooIceCredentials[] =
3890 "v=0\r\n"
3891 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3892 "s=-\r\n"
3893 "t=0 0\r\n"
3894 "m=audio 9 RTP/SAVPF 111\r\n"
3895 "c=IN IP4 0.0.0.0\r\n"
3896 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3897 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3898 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3899 "a=rtpmap:111 opus/48000/2\r\n"
3900 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3901 "generation 2\r\n";
3902
3903 JsepSessionDescription jdesc_output(kDummyType);
3904 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3905 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3906 ASSERT_NE(nullptr, candidates);
3907 ASSERT_EQ(1U, candidates->count());
3908 cricket::Candidate c = candidates->at(0)->candidate();
3909 EXPECT_EQ("ufrag_voice", c.username());
3910 EXPECT_EQ("pwd_voice", c.password());
3911}
3912
deadbeef90f1e1e2017-02-10 12:35:05 -08003913// Test that SDP with an invalid port number in "a=candidate" lines is
3914// rejected, without crashing.
3915// Regression test for:
3916// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3917TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3918 static const char kSdpWithInvalidCandidatePort[] =
3919 "v=0\r\n"
3920 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3921 "s=-\r\n"
3922 "t=0 0\r\n"
3923 "m=audio 9 RTP/SAVPF 111\r\n"
3924 "c=IN IP4 0.0.0.0\r\n"
3925 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3926 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3927 "a=rtpmap:111 opus/48000/2\r\n"
3928 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3929 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3930
Steve Antona3a92c22017-12-07 10:27:41 -08003931 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003932 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3933}
deadbeefa4549d62017-02-10 17:26:22 -08003934
3935// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3936// Regression test for:
3937// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3938TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3939 static const char kSdpWithMissingTrackId[] =
3940 "v=0\r\n"
3941 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3942 "s=-\r\n"
3943 "t=0 0\r\n"
3944 "m=audio 9 RTP/SAVPF 111\r\n"
3945 "c=IN IP4 0.0.0.0\r\n"
3946 "a=rtpmap:111 opus/48000/2\r\n"
3947 "a=msid:stream_id \r\n";
3948
Steve Antona3a92c22017-12-07 10:27:41 -08003949 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003950 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3951}
3952
3953TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3954 static const char kSdpWithMissingStreamId[] =
3955 "v=0\r\n"
3956 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3957 "s=-\r\n"
3958 "t=0 0\r\n"
3959 "m=audio 9 RTP/SAVPF 111\r\n"
3960 "c=IN IP4 0.0.0.0\r\n"
3961 "a=rtpmap:111 opus/48000/2\r\n"
3962 "a=msid: track_id\r\n";
3963
Steve Antona3a92c22017-12-07 10:27:41 -08003964 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003965 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3966}
zhihuang38989e52017-03-21 11:04:53 -07003967
3968// Tests that if both session-level address and media-level address exist, use
3969// the media-level address.
3970TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003971 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003972
3973 // Sesssion-level address.
3974 std::string sdp = kSdpFullString;
3975 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3976 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3977
3978 const auto& content1 = jsep_desc.description()->contents()[0];
3979 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003980 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003981 const auto& content2 = jsep_desc.description()->contents()[1];
3982 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003983 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003984}
3985
3986// Tests that the session-level connection address will be used if the media
3987// level-addresses are not specified.
3988TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003989 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003990
3991 // Sesssion-level address.
3992 std::string sdp = kSdpString;
3993 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3994 // Remove the media level addresses.
3995 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3996 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3997 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3998
3999 const auto& content1 = jsep_desc.description()->contents()[0];
4000 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004001 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004002 const auto& content2 = jsep_desc.description()->contents()[1];
4003 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004004 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004005}
4006
4007TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004008 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004009
4010 std::string sdp = kSdpString;
4011 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4012 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4013 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4014 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4015 &sdp);
4016 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4017 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4018 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4019 &sdp);
4020 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4021 const auto& content1 = jsep_desc.description()->contents()[0];
4022 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004023 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004024 const auto& content2 = jsep_desc.description()->contents()[1];
4025 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004026 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004027}
4028
Qingsi Wang56991422019-02-08 12:53:06 -08004029// Test that a c= line that contains a hostname connection address can be
4030// parsed.
4031TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4032 JsepSessionDescription jsep_desc(kDummyType);
4033 std::string sdp = kSdpString;
4034 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4035
4036 sdp = kSdpString;
4037 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4038 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4039 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4040
4041 ASSERT_NE(nullptr, jsep_desc.description());
4042 const auto& content1 = jsep_desc.description()->contents()[0];
4043 EXPECT_EQ("example.local:9",
4044 content1.media_description()->connection_address().ToString());
4045 const auto& content2 = jsep_desc.description()->contents()[1];
4046 EXPECT_EQ("example.local:9",
4047 content2.media_description()->connection_address().ToString());
4048}
4049
4050// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004051TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004052 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004053 std::string sdp = kSdpString;
4054 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4055
4056 // Unsupported multicast IPv4 address.
4057 sdp = kSdpFullString;
4058 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4059 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4060
4061 // Unsupported multicast IPv6 address.
4062 sdp = kSdpFullString;
4063 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4064 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4065
4066 // Mismatched address type.
4067 sdp = kSdpFullString;
4068 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4069 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4070
4071 sdp = kSdpFullString;
4072 Replace("c=IN IP4 74.125.224.39\r\n",
4073 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4074 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4075}
4076
4077TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004078 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004079 MakeDescriptionWithoutCandidates(&expected_jsep);
4080 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004081 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004082 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004083 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004084 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004085 auto audio_desc = jdesc.description()
4086 ->GetContentByName(kAudioContentName)
4087 ->media_description();
4088 auto video_desc = jdesc.description()
4089 ->GetContentByName(kVideoContentName)
4090 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004091 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4092 audio_desc->connection_address().ToString());
4093 EXPECT_EQ(video_desc_->connection_address().ToString(),
4094 video_desc->connection_address().ToString());
4095}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004096
Qingsi Wang56991422019-02-08 12:53:06 -08004097// Test that a media description that contains a hostname connection address can
4098// be correctly serialized.
4099TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4100 JsepSessionDescription expected_jsep(kDummyType);
4101 cricket::Candidate c;
4102 const rtc::SocketAddress hostname_addr("example.local", 1234);
4103 audio_desc_->set_connection_address(hostname_addr);
4104 video_desc_->set_connection_address(hostname_addr);
4105 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004106 expected_jsep.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Qingsi Wang56991422019-02-08 12:53:06 -08004107 // Serialization.
4108 std::string message = webrtc::SdpSerialize(expected_jsep);
4109 // Deserialization.
4110 JsepSessionDescription jdesc(kDummyType);
4111 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4112 auto audio_desc = jdesc.description()
4113 ->GetContentByName(kAudioContentName)
4114 ->media_description();
4115 auto video_desc = jdesc.description()
4116 ->GetContentByName(kVideoContentName)
4117 ->media_description();
4118 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4119 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4120}
4121
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004122// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4123// used (i.e., a single space as the session name)." So we should accept that.
4124TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4125 JsepSessionDescription jsep_desc(kDummyType);
4126 std::string sdp = kSdpString;
4127 Replace("s=-\r\n", "s= \r\n", &sdp);
4128 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4129}
Amit Hilbucha2012042018-12-03 11:35:05 -08004130
4131// Simulcast malformed input test for invalid format.
4132TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4133 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4134 "a=simulcast:\r\n", "a=simulcast:");
4135}
4136
4137// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4138TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4139 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4140 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4141 "a=simulcast:");
4142}
4143
4144// Validates that deserialization uses the a=simulcast: attribute
4145TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004146 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4147 sdp += "a=rid:1 send\r\n";
4148 sdp += "a=rid:2 send\r\n";
4149 sdp += "a=rid:3 send\r\n";
4150 sdp += "a=rid:4 recv\r\n";
4151 sdp += "a=rid:5 recv\r\n";
4152 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004153 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4154 JsepSessionDescription output(kDummyType);
4155 SdpParseError error;
4156 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4157 const cricket::ContentInfos& contents = output.description()->contents();
4158 const cricket::MediaContentDescription* media =
4159 contents.back().media_description();
4160 EXPECT_TRUE(media->HasSimulcast());
4161 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4162 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004163 EXPECT_FALSE(media->streams().empty());
4164 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4165 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004166}
4167
4168// Validates that deserialization removes rids that do not appear in SDP
4169TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4170 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4171 sdp += "a=rid:1 send\r\n";
4172 sdp += "a=rid:3 send\r\n";
4173 sdp += "a=rid:4 recv\r\n";
4174 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4175 JsepSessionDescription output(kDummyType);
4176 SdpParseError error;
4177 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4178 const cricket::ContentInfos& contents = output.description()->contents();
4179 const cricket::MediaContentDescription* media =
4180 contents.back().media_description();
4181 EXPECT_TRUE(media->HasSimulcast());
4182 const SimulcastDescription& simulcast = media->simulcast_description();
4183 EXPECT_EQ(2ul, simulcast.send_layers().size());
4184 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4185
4186 std::vector<SimulcastLayer> all_send_layers =
4187 simulcast.send_layers().GetAllLayers();
4188 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004189 EXPECT_EQ(0,
4190 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4191 return layer.rid == "2";
4192 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004193
4194 std::vector<SimulcastLayer> all_receive_layers =
4195 simulcast.receive_layers().GetAllLayers();
4196 ASSERT_EQ(1ul, all_receive_layers.size());
4197 EXPECT_EQ("4", all_receive_layers[0].rid);
4198
4199 EXPECT_FALSE(media->streams().empty());
4200 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4201 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004202}
4203
4204// Validates that Simulcast removes rids that appear in both send and receive.
4205TEST_F(WebRtcSdpTest,
4206 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4207 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4208 sdp += "a=rid:1 send\r\n";
4209 sdp += "a=rid:2 send\r\n";
4210 sdp += "a=rid:3 send\r\n";
4211 sdp += "a=rid:4 recv\r\n";
4212 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4213 JsepSessionDescription output(kDummyType);
4214 SdpParseError error;
4215 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4216 const cricket::ContentInfos& contents = output.description()->contents();
4217 const cricket::MediaContentDescription* media =
4218 contents.back().media_description();
4219 EXPECT_TRUE(media->HasSimulcast());
4220 const SimulcastDescription& simulcast = media->simulcast_description();
4221 EXPECT_EQ(2ul, simulcast.send_layers().size());
4222 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4223 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4224 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4225
4226 EXPECT_FALSE(media->streams().empty());
4227 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4228 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004229}
4230
4231// Ignores empty rid line.
4232TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4233 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4234 sdp += "a=rid:1 send\r\n";
4235 sdp += "a=rid:2 send\r\n";
4236 sdp += "a=rid\r\n"; // Should ignore this line.
4237 sdp += "a=rid:\r\n"; // Should ignore this line.
4238 sdp += "a=simulcast:send 1;2\r\n";
4239 JsepSessionDescription output(kDummyType);
4240 SdpParseError error;
4241 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4242 const cricket::ContentInfos& contents = output.description()->contents();
4243 const cricket::MediaContentDescription* media =
4244 contents.back().media_description();
4245 EXPECT_TRUE(media->HasSimulcast());
4246 const SimulcastDescription& simulcast = media->simulcast_description();
4247 EXPECT_TRUE(simulcast.receive_layers().empty());
4248 EXPECT_EQ(2ul, simulcast.send_layers().size());
4249 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4250
4251 EXPECT_FALSE(media->streams().empty());
4252 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4253 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004254}
4255
4256// Ignores malformed rid lines.
4257TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4258 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4259 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4260 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4261 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4262 sdp += "a=rid:4\r\n"; // Should ignore this line.
4263 sdp += "a=rid:5 send\r\n";
4264 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4265 JsepSessionDescription output(kDummyType);
4266 SdpParseError error;
4267 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4268 const cricket::ContentInfos& contents = output.description()->contents();
4269 const cricket::MediaContentDescription* media =
4270 contents.back().media_description();
4271 EXPECT_TRUE(media->HasSimulcast());
4272 const SimulcastDescription& simulcast = media->simulcast_description();
4273 EXPECT_TRUE(simulcast.receive_layers().empty());
4274 EXPECT_EQ(1ul, simulcast.send_layers().size());
4275 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4276
4277 EXPECT_FALSE(media->streams().empty());
4278 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4279 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004280}
4281
4282// Removes RIDs that specify a different format than the m= section.
4283TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4284 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4285 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4286 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4287 sdp += "a=simulcast:send 1;2\r\n";
4288 JsepSessionDescription output(kDummyType);
4289 SdpParseError error;
4290 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4291 const cricket::ContentInfos& contents = output.description()->contents();
4292 const cricket::MediaContentDescription* media =
4293 contents.back().media_description();
4294 EXPECT_TRUE(media->HasSimulcast());
4295 const SimulcastDescription& simulcast = media->simulcast_description();
4296 EXPECT_TRUE(simulcast.receive_layers().empty());
4297 EXPECT_EQ(1ul, simulcast.send_layers().size());
4298 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4299 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4300 EXPECT_EQ(1ul, media->streams().size());
4301 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4302 EXPECT_EQ(1ul, rids.size());
4303 EXPECT_EQ("1", rids[0].rid);
4304 EXPECT_EQ(1ul, rids[0].payload_types.size());
4305 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004306}
4307
4308// Ignores duplicate rid lines
4309TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4310 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4311 sdp += "a=rid:1 send\r\n";
4312 sdp += "a=rid:2 send\r\n";
4313 sdp += "a=rid:2 send\r\n";
4314 sdp += "a=rid:3 send\r\n";
4315 sdp += "a=rid:4 recv\r\n";
4316 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4317 JsepSessionDescription output(kDummyType);
4318 SdpParseError error;
4319 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4320 const cricket::ContentInfos& contents = output.description()->contents();
4321 const cricket::MediaContentDescription* media =
4322 contents.back().media_description();
4323 EXPECT_TRUE(media->HasSimulcast());
4324 const SimulcastDescription& simulcast = media->simulcast_description();
4325 EXPECT_EQ(2ul, simulcast.send_layers().size());
4326 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4327 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4328 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4329
4330 EXPECT_FALSE(media->streams().empty());
4331 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4332 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004333}
4334
4335// Simulcast serialization integration test.
4336// This test will serialize and deserialize the description and compare.
4337// More detailed tests for parsing simulcast can be found in
4338// unit tests for SdpSerializer.
4339TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004340 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004341 auto description = jdesc_.description();
4342 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004343 ASSERT_EQ(media->streams().size(), 1ul);
4344 StreamParams& send_stream = media->mutable_streams()[0];
4345 std::vector<RidDescription> send_rids;
4346 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4347 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4348 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4349 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4350 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004351
Amit Hilbucha2012042018-12-03 11:35:05 -08004352 SimulcastDescription& simulcast = media->simulcast_description();
4353 simulcast.send_layers().AddLayerWithAlternatives(
4354 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4355 simulcast.send_layers().AddLayerWithAlternatives(
4356 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4357
Amit Hilbucha2012042018-12-03 11:35:05 -08004358 TestSerialize(jdesc_);
4359}
Steve Anton06817cd2018-12-18 15:55:30 -08004360
4361// Test that the content name is empty if the media section does not have an
4362// a=mid line.
4363TEST_F(WebRtcSdpTest, ParseNoMid) {
4364 std::string sdp = kSdpString;
4365 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4366 Replace("a=mid:video_content_name\r\n", "", &sdp);
4367
4368 JsepSessionDescription output(kDummyType);
4369 SdpParseError error;
4370 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4371
4372 EXPECT_THAT(output.description()->contents(),
4373 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4374 Field("name", &cricket::ContentInfo::name, "")));
4375}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004376
4377// Test that the media transport name and base64-decoded setting is parsed from
4378// an a=x-mt line.
4379TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4380 JsepSessionDescription output(kDummyType);
4381 std::string sdp = kSdpSessionString;
4382 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4383 SdpParseError error;
4384
4385 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4386 << error.description;
4387 const auto& settings = output.description()->MediaTransportSettings();
4388 ASSERT_EQ(1u, settings.size());
4389 EXPECT_EQ("rtp", settings[0].transport_name);
4390 EXPECT_EQ("test64", settings[0].transport_setting);
4391}
4392
4393// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4394TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4395 JsepSessionDescription output(kDummyType);
4396 std::string sdp = kSdpSessionString;
4397 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4398 SdpParseError error;
4399
4400 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4401}
4402
4403// Test that multiple a=x-mt lines are parsed in the order of preference (the
4404// order of the lines in the SDP).
4405TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4406 JsepSessionDescription output(kDummyType);
4407 std::string sdp = kSdpSessionString;
4408 sdp +=
4409 "a=x-mt:rtp:dGVzdDY0\r\n"
4410 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4411 SdpParseError error;
4412
4413 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4414 << error.description;
4415 const auto& settings = output.description()->MediaTransportSettings();
4416 ASSERT_EQ(2u, settings.size());
4417 EXPECT_EQ("rtp", settings[0].transport_name);
4418 EXPECT_EQ("test64", settings[0].transport_setting);
4419 EXPECT_EQ("generic", settings[1].transport_name);
4420 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4421}
4422
4423// Test that only the first a=x-mt line associated with a transport name is
4424// parsed and the rest ignored.
4425TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4426 JsepSessionDescription output(kDummyType);
4427 std::string sdp = kSdpSessionString;
4428 sdp +=
4429 "a=x-mt:rtp:dGVzdDY0\r\n"
4430 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4431 SdpParseError error;
4432
4433 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4434 // but ignore the repeated transport.
4435 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4436 const auto& settings = output.description()->MediaTransportSettings();
4437 EXPECT_EQ("test64", settings[0].transport_setting);
4438}
4439
4440// Test that an a=x-mt line fails to parse if it is missing a setting.
4441TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4442 JsepSessionDescription output(kDummyType);
4443 std::string sdp = kSdpSessionString;
4444 sdp += "a=x-mt:rtp\r\n";
4445 SdpParseError error;
4446
4447 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4448}
4449
4450// Test that an a=x-mt line fails to parse if its missing a name and setting.
4451TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4452 JsepSessionDescription output(kDummyType);
4453 std::string sdp = kSdpSessionString;
4454 sdp += "a=x-mt\r\n";
4455 SdpParseError error;
4456
4457 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4458}
4459
4460TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4461 JsepSessionDescription output(kDummyType);
4462 std::string sdp = kSdpSessionString;
4463 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4464 SdpParseError error;
4465
4466 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4467 << error.description;
4468 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4469}
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004470
4471TEST_F(WebRtcSdpTest, SerializeMediaTransportSettings) {
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004472 auto description = absl::make_unique<cricket::SessionDescription>();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004473
4474 JsepSessionDescription output(SdpType::kOffer);
4475 // JsepSessionDescription takes ownership of the description.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004476 output.Initialize(std::move(description), "session_id", "session_version");
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004477 output.description()->AddMediaTransportSetting("foo", "bar");
4478 std::string serialized_out;
4479 output.ToString(&serialized_out);
4480 ASSERT_THAT(serialized_out, ::testing::HasSubstr("\r\na=x-mt:foo:YmFy\r\n"));
4481}
4482
4483TEST_F(WebRtcSdpTest, SerializeMediaTransportSettingsTestCopy) {
4484 cricket::SessionDescription description;
4485 description.AddMediaTransportSetting("name", "setting");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004486 std::unique_ptr<cricket::SessionDescription> copy = description.Clone();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004487 ASSERT_EQ(1u, copy->MediaTransportSettings().size());
4488 EXPECT_EQ("name", copy->MediaTransportSettings()[0].transport_name);
4489 EXPECT_EQ("setting", copy->MediaTransportSettings()[0].transport_setting);
4490}