blob: 1fa7ba4b40fd96887595e0ed22854306d0350f54 [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>
13#include <cstdint>
14#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Steve Anton64b626b2019-01-28 17:25:26 -080020#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080021#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080022#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto_params.h"
25#include "api/jsep_session_description.h"
26#include "api/media_types.h"
27#include "api/rtp_parameters.h"
28#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "media/base/media_constants.h"
31#include "media/base/stream_params.h"
32#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020033#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "p2p/base/transport_description.h"
35#include "p2p/base/transport_info.h"
36#include "pc/media_session.h"
37#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "rtc_base/message_digest.h"
40#include "rtc_base/socket_address.h"
41#include "rtc_base/ssl_fingerprint.h"
42#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080043#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010044#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020045
ossu7bb87ee2017-01-23 04:56:25 -080046#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080047#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080048#endif
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51using cricket::AudioCodec;
52using cricket::AudioContentDescription;
53using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080054using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055using cricket::ContentInfo;
56using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::DataCodec;
58using cricket::DataContentDescription;
59using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
60using cricket::ICE_CANDIDATE_COMPONENT_RTP;
61using cricket::kFecSsrcGroupSemantics;
62using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080063using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080064using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080065using cricket::RidDescription;
66using cricket::RidDirection;
Steve Anton06817cd2018-12-18 15:55:30 -080067using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080068using cricket::SimulcastDescription;
69using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using cricket::StreamParams;
71using cricket::STUN_PORT_TYPE;
72using cricket::TransportDescription;
73using cricket::TransportInfo;
74using cricket::VideoCodec;
75using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080076using ::testing::ElementsAre;
77using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::IceCandidateCollection;
79using webrtc::IceCandidateInterface;
80using webrtc::JsepIceCandidate;
81using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070082using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080083using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080085using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::SessionDescriptionInterface;
87
88typedef std::vector<AudioCodec> AudioCodecs;
89typedef std::vector<Candidate> Candidates;
90
Peter Boström0c4e06b2015-10-07 12:23:21 +020091static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080092static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080095static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080097static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020099static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100static const char kCandidateFoundation1[] = "a0+B/1";
101static const char kCandidateFoundation2[] = "a0+B/2";
102static const char kCandidateFoundation3[] = "a0+B/3";
103static const char kCandidateFoundation4[] = "a0+B/4";
104static const char kAttributeCryptoVoice[] =
105 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
106 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
107 "dummy_session_params\r\n";
108static const char kAttributeCryptoVideo[] =
109 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
110 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200111static const char kFingerprint[] =
112 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 "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 +0200114static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115static const int kExtmapId = 1;
116static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
117static const char kExtmap[] =
118 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
119static const char kExtmapWithDirectionAndAttribute[] =
120 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700121static const char kExtmapWithDirectionAndAttributeEncrypted[] =
122 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
123 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124
Peter Boström0c4e06b2015-10-07 12:23:21 +0200125static const uint8_t kIdentityDigest[] = {
126 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
127 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128
lally@webrtc.org34807282015-02-24 20:19:39 +0000129static const char kDtlsSctp[] = "DTLS/SCTP";
130static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
131static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133struct CodecParams {
134 int max_ptime;
135 int ptime;
136 int min_ptime;
137 int sprop_stereo;
138 int stereo;
139 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000140 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141};
142
deadbeef9d3584c2016-02-16 17:54:10 -0800143// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
144// instead of "a=crypto", and have an explicit test for adding "a=crypto".
145// Currently it's the other way around.
146
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147// Reference sdp string
148static const char kSdpFullString[] =
149 "v=0\r\n"
150 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
151 "s=-\r\n"
152 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800153 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
155 "c=IN IP4 74.125.127.126\r\n"
156 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
157 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
158 "generation 2\r\n"
159 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
166 "raddr 192.168.1.5 rport 2346 "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
169 "raddr 192.168.1.5 rport 2348 "
170 "generation 2\r\n"
171 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
172 "a=mid:audio_content_name\r\n"
173 "a=sendrecv\r\n"
174 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800175 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
177 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
178 "dummy_session_params\r\n"
179 "a=rtpmap:111 opus/48000/2\r\n"
180 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000181 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 "a=ssrc:1 cname:stream_1_cname\r\n"
183 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
184 "a=ssrc:1 mslabel:local_stream_1\r\n"
185 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "m=video 3457 RTP/SAVPF 120\r\n"
187 "c=IN IP4 74.125.224.39\r\n"
188 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
189 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
190 "generation 2\r\n"
191 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
200 "generation 2\r\n"
201 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
202 "a=mid:video_content_name\r\n"
203 "a=sendrecv\r\n"
204 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
205 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
206 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800207 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=ssrc:2 cname:stream_1_cname\r\n"
209 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
210 "a=ssrc:2 mslabel:local_stream_1\r\n"
211 "a=ssrc:2 label:video_track_id_1\r\n"
212 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800213 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800215 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216
217// SDP reference string without the candidates.
218static const char kSdpString[] =
219 "v=0\r\n"
220 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
221 "s=-\r\n"
222 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800223 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000224 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000225 "c=IN IP4 0.0.0.0\r\n"
226 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
228 "a=mid:audio_content_name\r\n"
229 "a=sendrecv\r\n"
230 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800231 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
233 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
234 "dummy_session_params\r\n"
235 "a=rtpmap:111 opus/48000/2\r\n"
236 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000237 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 "a=ssrc:1 cname:stream_1_cname\r\n"
239 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
240 "a=ssrc:1 mslabel:local_stream_1\r\n"
241 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000242 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000243 "c=IN IP4 0.0.0.0\r\n"
244 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
246 "a=mid:video_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
250 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800251 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 "a=ssrc:2 cname:stream_1_cname\r\n"
253 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
254 "a=ssrc:2 mslabel:local_stream_1\r\n"
255 "a=ssrc:2 label:video_track_id_1\r\n"
256 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800257 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800259 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260
261static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000262 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000263 "c=IN IP4 0.0.0.0\r\n"
264 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 "a=ice-ufrag:ufrag_data\r\n"
266 "a=ice-pwd:pwd_data\r\n"
267 "a=mid:data_content_name\r\n"
268 "a=sendrecv\r\n"
269 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
270 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
271 "a=rtpmap:101 google-data/90000\r\n"
272 "a=ssrc:10 cname:data_channel_cname\r\n"
273 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
274 "a=ssrc:10 mslabel:data_channel\r\n"
275 "a=ssrc:10 label:data_channeld0\r\n";
276
277static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000278 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000279 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 "a=ice-ufrag:ufrag_data\r\n"
281 "a=ice-pwd:pwd_data\r\n"
282 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000283 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000285// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200286// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
287// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000288static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000289 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000290 "a=sctp-port 5000\r\n"
291 "c=IN IP4 0.0.0.0\r\n"
292 "a=ice-ufrag:ufrag_data\r\n"
293 "a=ice-pwd:pwd_data\r\n"
294 "a=mid:data_content_name\r\n";
295
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200296// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700297static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
298 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700299 "a=sctp-port:5000\r\n"
300 "c=IN IP4 0.0.0.0\r\n"
301 "a=ice-ufrag:ufrag_data\r\n"
302 "a=ice-pwd:pwd_data\r\n"
303 "a=mid:data_content_name\r\n";
304
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305static const char kSdpSctpDataChannelWithCandidatesString[] =
306 "m=application 2345 DTLS/SCTP 5000\r\n"
307 "c=IN IP4 74.125.127.126\r\n"
308 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
309 "generation 2\r\n"
310 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
311 "generation 2\r\n"
312 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
313 "raddr 192.168.1.5 rport 2346 "
314 "generation 2\r\n"
315 "a=ice-ufrag:ufrag_data\r\n"
316 "a=ice-pwd:pwd_data\r\n"
317 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000318 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000320static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000321 "v=0\r\n"
322 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
323 "s=-\r\n"
324 "t=0 0\r\n"
325 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000326 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000327 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000328 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000329 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000331 "a=x-google-flag:conference\r\n";
332
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000333static const char kSdpSessionString[] =
334 "v=0\r\n"
335 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
336 "s=-\r\n"
337 "t=0 0\r\n"
338 "a=msid-semantic: WMS local_stream\r\n";
339
340static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000341 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000342 "c=IN IP4 0.0.0.0\r\n"
343 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000344 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
345 "a=mid:audio_content_name\r\n"
346 "a=sendrecv\r\n"
347 "a=rtpmap:111 opus/48000/2\r\n"
348 "a=ssrc:1 cname:stream_1_cname\r\n"
349 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
350 "a=ssrc:1 mslabel:local_stream\r\n"
351 "a=ssrc:1 label:audio_track_id_1\r\n";
352
353static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000354 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000355 "c=IN IP4 0.0.0.0\r\n"
356 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000357 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
358 "a=mid:video_content_name\r\n"
359 "a=sendrecv\r\n"
360 "a=rtpmap:120 VP8/90000\r\n"
361 "a=ssrc:2 cname:stream_1_cname\r\n"
362 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
363 "a=ssrc:2 mslabel:local_stream\r\n"
364 "a=ssrc:2 label:video_track_id_1\r\n";
365
deadbeef25ed4352016-12-12 18:37:36 -0800366// Reference sdp string using bundle-only.
367static const char kBundleOnlySdpFullString[] =
368 "v=0\r\n"
369 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
370 "s=-\r\n"
371 "t=0 0\r\n"
372 "a=group:BUNDLE audio_content_name video_content_name\r\n"
373 "a=msid-semantic: WMS local_stream_1\r\n"
374 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
375 "c=IN IP4 74.125.127.126\r\n"
376 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
377 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
378 "generation 2\r\n"
379 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
386 "raddr 192.168.1.5 rport 2346 "
387 "generation 2\r\n"
388 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
389 "raddr 192.168.1.5 rport 2348 "
390 "generation 2\r\n"
391 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
392 "a=mid:audio_content_name\r\n"
393 "a=sendrecv\r\n"
394 "a=rtcp-mux\r\n"
395 "a=rtcp-rsize\r\n"
396 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
397 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
398 "dummy_session_params\r\n"
399 "a=rtpmap:111 opus/48000/2\r\n"
400 "a=rtpmap:103 ISAC/16000\r\n"
401 "a=rtpmap:104 ISAC/32000\r\n"
402 "a=ssrc:1 cname:stream_1_cname\r\n"
403 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
404 "a=ssrc:1 mslabel:local_stream_1\r\n"
405 "a=ssrc:1 label:audio_track_id_1\r\n"
406 "m=video 0 RTP/SAVPF 120\r\n"
407 "c=IN IP4 0.0.0.0\r\n"
408 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
409 "a=bundle-only\r\n"
410 "a=mid:video_content_name\r\n"
411 "a=sendrecv\r\n"
412 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
413 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
414 "a=rtpmap:120 VP8/90000\r\n"
415 "a=ssrc-group:FEC 2 3\r\n"
416 "a=ssrc:2 cname:stream_1_cname\r\n"
417 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
418 "a=ssrc:2 mslabel:local_stream_1\r\n"
419 "a=ssrc:2 label:video_track_id_1\r\n"
420 "a=ssrc:3 cname:stream_1_cname\r\n"
421 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
422 "a=ssrc:3 mslabel:local_stream_1\r\n"
423 "a=ssrc:3 label:video_track_id_1\r\n";
424
deadbeef9d3584c2016-02-16 17:54:10 -0800425// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
426// tracks.
427static const char kPlanBSdpFullString[] =
428 "v=0\r\n"
429 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
430 "s=-\r\n"
431 "t=0 0\r\n"
432 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
433 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
434 "c=IN IP4 74.125.127.126\r\n"
435 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
436 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
437 "generation 2\r\n"
438 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
439 "generation 2\r\n"
440 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
443 "generation 2\r\n"
444 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
445 "raddr 192.168.1.5 rport 2346 "
446 "generation 2\r\n"
447 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
448 "raddr 192.168.1.5 rport 2348 "
449 "generation 2\r\n"
450 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
451 "a=mid:audio_content_name\r\n"
452 "a=sendrecv\r\n"
453 "a=rtcp-mux\r\n"
454 "a=rtcp-rsize\r\n"
455 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
456 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
457 "dummy_session_params\r\n"
458 "a=rtpmap:111 opus/48000/2\r\n"
459 "a=rtpmap:103 ISAC/16000\r\n"
460 "a=rtpmap:104 ISAC/32000\r\n"
461 "a=ssrc:1 cname:stream_1_cname\r\n"
462 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
463 "a=ssrc:1 mslabel:local_stream_1\r\n"
464 "a=ssrc:1 label:audio_track_id_1\r\n"
465 "a=ssrc:4 cname:stream_2_cname\r\n"
466 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
467 "a=ssrc:4 mslabel:local_stream_2\r\n"
468 "a=ssrc:4 label:audio_track_id_2\r\n"
469 "m=video 3457 RTP/SAVPF 120\r\n"
470 "c=IN IP4 74.125.224.39\r\n"
471 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
472 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
473 "generation 2\r\n"
474 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
475 "generation 2\r\n"
476 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
479 "generation 2\r\n"
480 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
481 "generation 2\r\n"
482 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
483 "generation 2\r\n"
484 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
485 "a=mid:video_content_name\r\n"
486 "a=sendrecv\r\n"
487 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
488 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
489 "a=rtpmap:120 VP8/90000\r\n"
490 "a=ssrc-group:FEC 2 3\r\n"
491 "a=ssrc:2 cname:stream_1_cname\r\n"
492 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
493 "a=ssrc:2 mslabel:local_stream_1\r\n"
494 "a=ssrc:2 label:video_track_id_1\r\n"
495 "a=ssrc:3 cname:stream_1_cname\r\n"
496 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
497 "a=ssrc:3 mslabel:local_stream_1\r\n"
498 "a=ssrc:3 label:video_track_id_1\r\n"
499 "a=ssrc:5 cname:stream_2_cname\r\n"
500 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
501 "a=ssrc:5 mslabel:local_stream_2\r\n"
502 "a=ssrc:5 label:video_track_id_2\r\n"
503 "a=ssrc:6 cname:stream_2_cname\r\n"
504 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
505 "a=ssrc:6 mslabel:local_stream_2\r\n"
506 "a=ssrc:6 label:video_track_id_3\r\n";
507
508// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
509// tracks.
510static const char kUnifiedPlanSdpFullString[] =
511 "v=0\r\n"
512 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
513 "s=-\r\n"
514 "t=0 0\r\n"
515 "a=msid-semantic: WMS local_stream_1\r\n"
516 // Audio track 1, stream 1 (with candidates).
517 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
518 "c=IN IP4 74.125.127.126\r\n"
519 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
520 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
523 "generation 2\r\n"
524 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
529 "raddr 192.168.1.5 rport 2346 "
530 "generation 2\r\n"
531 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
532 "raddr 192.168.1.5 rport 2348 "
533 "generation 2\r\n"
534 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
535 "a=mid:audio_content_name\r\n"
536 "a=msid:local_stream_1 audio_track_id_1\r\n"
537 "a=sendrecv\r\n"
538 "a=rtcp-mux\r\n"
539 "a=rtcp-rsize\r\n"
540 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
541 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
542 "dummy_session_params\r\n"
543 "a=rtpmap:111 opus/48000/2\r\n"
544 "a=rtpmap:103 ISAC/16000\r\n"
545 "a=rtpmap:104 ISAC/32000\r\n"
546 "a=ssrc:1 cname:stream_1_cname\r\n"
547 // Video track 1, stream 1 (with candidates).
548 "m=video 3457 RTP/SAVPF 120\r\n"
549 "c=IN IP4 74.125.224.39\r\n"
550 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
551 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
554 "generation 2\r\n"
555 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
558 "generation 2\r\n"
559 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
560 "generation 2\r\n"
561 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
562 "generation 2\r\n"
563 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
564 "a=mid:video_content_name\r\n"
565 "a=msid:local_stream_1 video_track_id_1\r\n"
566 "a=sendrecv\r\n"
567 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
568 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
569 "a=rtpmap:120 VP8/90000\r\n"
570 "a=ssrc-group:FEC 2 3\r\n"
571 "a=ssrc:2 cname:stream_1_cname\r\n"
572 "a=ssrc:3 cname:stream_1_cname\r\n"
573 // Audio track 2, stream 2.
574 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
575 "c=IN IP4 0.0.0.0\r\n"
576 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
577 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
578 "a=mid:audio_content_name_2\r\n"
579 "a=msid:local_stream_2 audio_track_id_2\r\n"
580 "a=sendrecv\r\n"
581 "a=rtcp-mux\r\n"
582 "a=rtcp-rsize\r\n"
583 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
584 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
585 "dummy_session_params\r\n"
586 "a=rtpmap:111 opus/48000/2\r\n"
587 "a=rtpmap:103 ISAC/16000\r\n"
588 "a=rtpmap:104 ISAC/32000\r\n"
589 "a=ssrc:4 cname:stream_2_cname\r\n"
590 // Video track 2, stream 2.
591 "m=video 9 RTP/SAVPF 120\r\n"
592 "c=IN IP4 0.0.0.0\r\n"
593 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
594 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
595 "a=mid:video_content_name_2\r\n"
596 "a=msid:local_stream_2 video_track_id_2\r\n"
597 "a=sendrecv\r\n"
598 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
599 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
600 "a=rtpmap:120 VP8/90000\r\n"
601 "a=ssrc:5 cname:stream_2_cname\r\n"
602 // Video track 3, stream 2.
603 "m=video 9 RTP/SAVPF 120\r\n"
604 "c=IN IP4 0.0.0.0\r\n"
605 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
606 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
607 "a=mid:video_content_name_3\r\n"
608 "a=msid:local_stream_2 video_track_id_3\r\n"
609 "a=sendrecv\r\n"
610 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
611 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
612 "a=rtpmap:120 VP8/90000\r\n"
613 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614
Seth Hampson5b4f0752018-04-02 16:31:36 -0700615// Unified Plan SDP reference string:
616// - audio track 1 has 1 a=msid lines
617// - audio track 2 has 2 a=msid lines
618// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
619// there are 0 media stream ids.
620// This Unified Plan SDP represents a SDP that signals the msid using both
621// a=msid and a=ssrc msid semantics.
622static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
623 "v=0\r\n"
624 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
625 "s=-\r\n"
626 "t=0 0\r\n"
627 "a=msid-semantic: WMS local_stream_1\r\n"
628 // Audio track 1, with 1 stream id.
629 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
630 "c=IN IP4 74.125.127.126\r\n"
631 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
632 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
633 "generation 2\r\n"
634 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
635 "generation 2\r\n"
636 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
639 "generation 2\r\n"
640 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
641 "raddr 192.168.1.5 rport 2346 "
642 "generation 2\r\n"
643 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
644 "raddr 192.168.1.5 rport 2348 "
645 "generation 2\r\n"
646 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
647 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700648 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700649 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700650 "a=rtcp-mux\r\n"
651 "a=rtcp-rsize\r\n"
652 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
653 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
654 "dummy_session_params\r\n"
655 "a=rtpmap:111 opus/48000/2\r\n"
656 "a=rtpmap:103 ISAC/16000\r\n"
657 "a=rtpmap:104 ISAC/32000\r\n"
658 "a=ssrc:1 cname:stream_1_cname\r\n"
659 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
660 "a=ssrc:1 mslabel:local_stream_1\r\n"
661 "a=ssrc:1 label:audio_track_id_1\r\n"
662 // Audio track 2, with two stream ids.
663 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
664 "c=IN IP4 0.0.0.0\r\n"
665 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
666 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
667 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700668 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700669 "a=msid:local_stream_1 audio_track_id_2\r\n"
670 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
679 "a=ssrc:4 cname:stream_1_cname\r\n"
680 // The support for Plan B msid signaling only includes the
681 // first media stream id "local_stream_1."
682 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
683 "a=ssrc:4 mslabel:local_stream_1\r\n"
684 "a=ssrc:4 label:audio_track_id_2\r\n"
685 // Audio track 3, with no stream ids.
686 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
687 "c=IN IP4 0.0.0.0\r\n"
688 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
689 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
690 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700691 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700692 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700693 "a=rtcp-mux\r\n"
694 "a=rtcp-rsize\r\n"
695 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
696 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
697 "dummy_session_params\r\n"
698 "a=rtpmap:111 opus/48000/2\r\n"
699 "a=rtpmap:103 ISAC/16000\r\n"
700 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700701 "a=ssrc:7 cname:stream_2_cname\r\n"
702 "a=ssrc:7 msid:- audio_track_id_3\r\n"
703 "a=ssrc:7 mslabel:-\r\n"
704 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700705
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800706// SDP string for unified plan without SSRCs
707static const char kUnifiedPlanSdpFullStringNoSsrc[] =
708 "v=0\r\n"
709 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
710 "s=-\r\n"
711 "t=0 0\r\n"
712 "a=msid-semantic: WMS local_stream_1\r\n"
713 // Audio track 1, stream 1 (with candidates).
714 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
715 "c=IN IP4 74.125.127.126\r\n"
716 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
717 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
718 "generation 2\r\n"
719 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
720 "generation 2\r\n"
721 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
724 "generation 2\r\n"
725 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
726 "raddr 192.168.1.5 rport 2346 "
727 "generation 2\r\n"
728 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
729 "raddr 192.168.1.5 rport 2348 "
730 "generation 2\r\n"
731 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
732 "a=mid:audio_content_name\r\n"
733 "a=msid:local_stream_1 audio_track_id_1\r\n"
734 "a=sendrecv\r\n"
735 "a=rtcp-mux\r\n"
736 "a=rtcp-rsize\r\n"
737 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
738 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
739 "dummy_session_params\r\n"
740 "a=rtpmap:111 opus/48000/2\r\n"
741 "a=rtpmap:103 ISAC/16000\r\n"
742 "a=rtpmap:104 ISAC/32000\r\n"
743 // Video track 1, stream 1 (with candidates).
744 "m=video 3457 RTP/SAVPF 120\r\n"
745 "c=IN IP4 74.125.224.39\r\n"
746 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
747 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
748 "generation 2\r\n"
749 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
750 "generation 2\r\n"
751 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
754 "generation 2\r\n"
755 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
756 "generation 2\r\n"
757 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
758 "generation 2\r\n"
759 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
760 "a=mid:video_content_name\r\n"
761 "a=msid:local_stream_1 video_track_id_1\r\n"
762 "a=sendrecv\r\n"
763 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
764 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
765 "a=rtpmap:120 VP8/90000\r\n"
766 // Audio track 2, stream 2.
767 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
768 "c=IN IP4 0.0.0.0\r\n"
769 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
770 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
771 "a=mid:audio_content_name_2\r\n"
772 "a=msid:local_stream_2 audio_track_id_2\r\n"
773 "a=sendrecv\r\n"
774 "a=rtcp-mux\r\n"
775 "a=rtcp-rsize\r\n"
776 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
777 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
778 "dummy_session_params\r\n"
779 "a=rtpmap:111 opus/48000/2\r\n"
780 "a=rtpmap:103 ISAC/16000\r\n"
781 "a=rtpmap:104 ISAC/32000\r\n"
782 // Video track 2, stream 2.
783 "m=video 9 RTP/SAVPF 120\r\n"
784 "c=IN IP4 0.0.0.0\r\n"
785 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
786 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
787 "a=mid:video_content_name_2\r\n"
788 "a=msid:local_stream_2 video_track_id_2\r\n"
789 "a=sendrecv\r\n"
790 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
791 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
792 "a=rtpmap:120 VP8/90000\r\n"
793 // Video track 3, stream 2.
794 "m=video 9 RTP/SAVPF 120\r\n"
795 "c=IN IP4 0.0.0.0\r\n"
796 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
797 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
798 "a=mid:video_content_name_3\r\n"
799 "a=msid:local_stream_2 video_track_id_3\r\n"
800 "a=sendrecv\r\n"
801 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
802 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
803 "a=rtpmap:120 VP8/90000\r\n";
804
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805// One candidate reference string as per W3c spec.
806// candidate:<blah> not a=candidate:<blah>CRLF
807static const char kRawCandidate[] =
808 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
809// One candidate reference string.
810static const char kSdpOneCandidate[] =
811 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
812 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000813
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000814static const char kSdpTcpActiveCandidate[] =
815 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
816 "tcptype active generation 2";
817static const char kSdpTcpPassiveCandidate[] =
818 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
819 "tcptype passive generation 2";
820static const char kSdpTcpSOCandidate[] =
821 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
822 "tcptype so generation 2";
823static const char kSdpTcpInvalidCandidate[] =
824 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
825 "tcptype invalid generation 2";
826
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000827// One candidate reference string with IPV6 address.
828static const char kRawIPV6Candidate[] =
829 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700830 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831
832// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800833static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800835 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836
Zach Steinb336c272018-08-09 01:16:13 -0700837static const char kRawHostnameCandidate[] =
838 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
839
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840// Session id and version
841static const char kSessionId[] = "18446744069414584320";
842static const char kSessionVersion[] = "18446462598732840960";
843
deadbeef9d3584c2016-02-16 17:54:10 -0800844// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845static const char kIceOption1[] = "iceoption1";
846static const char kIceOption2[] = "iceoption2";
847static const char kIceOption3[] = "iceoption3";
848
deadbeef9d3584c2016-02-16 17:54:10 -0800849// ICE ufrags/passwords.
850static const char kUfragVoice[] = "ufrag_voice";
851static const char kPwdVoice[] = "pwd_voice";
852static const char kUfragVideo[] = "ufrag_video";
853static const char kPwdVideo[] = "pwd_video";
854static const char kUfragData[] = "ufrag_data";
855static const char kPwdData[] = "pwd_data";
856
857// Extra ufrags/passwords for extra unified plan m= sections.
858static const char kUfragVoice2[] = "ufrag_voice_2";
859static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700860static const char kUfragVoice3[] = "ufrag_voice_3";
861static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800862static const char kUfragVideo2[] = "ufrag_video_2";
863static const char kPwdVideo2[] = "pwd_video_2";
864static const char kUfragVideo3[] = "ufrag_video_3";
865static const char kPwdVideo3[] = "pwd_video_3";
866
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867// Content name
868static const char kAudioContentName[] = "audio_content_name";
869static const char kVideoContentName[] = "video_content_name";
870static const char kDataContentName[] = "data_content_name";
871
deadbeef9d3584c2016-02-16 17:54:10 -0800872// Extra content names for extra unified plan m= sections.
873static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700874static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800875static const char kVideoContentName2[] = "video_content_name_2";
876static const char kVideoContentName3[] = "video_content_name_3";
877
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800879static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880static const char kStream1Cname[] = "stream_1_cname";
881static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200882static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800884static const uint32_t kVideoTrack1Ssrc1 = 2;
885static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886
887// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800888static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889static const char kStream2Cname[] = "stream_2_cname";
890static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200891static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800892static const char kVideoTrackId2[] = "video_track_id_2";
893static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800895static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700896static const char kAudioTrackId3[] = "audio_track_id_3";
897static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899// DataChannel
900static const char kDataChannelLabel[] = "data_channel";
901static const char kDataChannelMsid[] = "data_channeld0";
902static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200903static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
905// Candidate
906static const char kDummyMid[] = "dummy_mid";
907static const int kDummyIndex = 123;
908
909// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800910static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
912// Helper functions
913
914static bool SdpDeserialize(const std::string& message,
915 JsepSessionDescription* jdesc) {
916 return webrtc::SdpDeserialize(message, jdesc, NULL);
917}
918
919static bool SdpDeserializeCandidate(const std::string& message,
920 JsepIceCandidate* candidate) {
921 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
922}
923
924// Add some extra |newlines| to the |message| after |line|.
925static void InjectAfter(const std::string& line,
926 const std::string& newlines,
927 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800928 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929}
930
931static void Replace(const std::string& line,
932 const std::string& newlines,
933 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800934 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935}
936
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000937// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
938// message.
939static void ExpectParseFailure(const std::string& bad_sdp,
940 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800941 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000943 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000945 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
946}
947
948// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
949static void ExpectParseFailure(const char* good_part, const char* bad_part) {
950 std::string bad_sdp = kSdpFullString;
951 Replace(good_part, bad_part, &bad_sdp);
952 ExpectParseFailure(bad_sdp, bad_part);
953}
954
955// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
956static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
957 const std::string& newlines,
958 const std::string& bad_part) {
959 std::string bad_sdp = kSdpFullString;
960 InjectAfter(injectpoint, newlines, &bad_sdp);
961 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962}
963
Steve Anton4e70a722017-11-28 14:57:10 -0800964static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 std::string* message) {
966 std::string new_direction;
967 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800968 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 new_direction = "a=inactive";
970 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800971 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 new_direction = "a=sendonly";
973 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800974 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 new_direction = "a=recvonly";
976 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800977 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 default:
979 new_direction = "a=sendrecv";
980 break;
981 }
982 Replace("a=sendrecv", new_direction, message);
983}
984
Yves Gerey665174f2018-06-19 15:03:05 +0200985static void ReplaceRejected(bool audio_rejected,
986 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 std::string* message) {
988 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800989 Replace("m=audio 9", "m=audio 0", message);
990 Replace(kAttributeIceUfragVoice, "", message);
991 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 }
993 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800994 Replace("m=video 9", "m=video 0", message);
995 Replace(kAttributeIceUfragVideo, "", message);
996 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 }
998}
999
1000// WebRtcSdpTest
1001
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001002class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001004 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001005#ifdef WEBRTC_ANDROID
1006 webrtc::InitializeAndroidObjects();
1007#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 // AudioContentDescription
1009 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001010 StreamParams audio_stream;
1011 audio_stream.id = kAudioTrackId1;
1012 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001013 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001014 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1015 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001016 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1017 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001018 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019
1020 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001021 video_desc_ = CreateVideoContentDescription();
1022 StreamParams video_stream;
1023 video_stream.id = kVideoTrackId1;
1024 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001025 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001026 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1027 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1028 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1029 video_stream.ssrc_groups.push_back(ssrc_group);
1030 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001031 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1032 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001033 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034
1035 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001036 desc_.AddTransportInfo(TransportInfo(
1037 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1038 desc_.AddTransportInfo(TransportInfo(
1039 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
1041 // v4 host
1042 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001043 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001044 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001045 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1046 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001048 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001049 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1050 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001052 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001053 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1054 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001056 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001057 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1058 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059
1060 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001062 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1063 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001064 cricket::LOCAL_PORT_TYPE,
1065 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001067 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1068 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001069 cricket::LOCAL_PORT_TYPE,
1070 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001072 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1073 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001074 cricket::LOCAL_PORT_TYPE,
1075 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001077 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1078 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001079 cricket::LOCAL_PORT_TYPE,
1080 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081
1082 // stun
1083 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001084 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1085 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001086 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1087 address_stun, kCandidatePriority, "", "",
1088 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001089 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 candidate9.set_related_address(rel_address_stun);
1091
1092 address_stun.SetPort(port_stun++);
1093 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001094 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1095 address_stun, kCandidatePriority, "", "",
1096 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001097 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 candidate10.set_related_address(rel_address_stun);
1099
1100 // relay
1101 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001102 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001103 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1104 address_relay, kCandidatePriority, "", "",
1105 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001106 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001108 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1109 address_relay, kCandidatePriority, "", "",
1110 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001111 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112
1113 // voice
1114 candidates_.push_back(candidate1);
1115 candidates_.push_back(candidate2);
1116 candidates_.push_back(candidate5);
1117 candidates_.push_back(candidate6);
1118 candidates_.push_back(candidate9);
1119 candidates_.push_back(candidate10);
1120
1121 // video
1122 candidates_.push_back(candidate3);
1123 candidates_.push_back(candidate4);
1124 candidates_.push_back(candidate7);
1125 candidates_.push_back(candidate8);
1126 candidates_.push_back(candidate11);
1127 candidates_.push_back(candidate12);
1128
Yves Gerey665174f2018-06-19 15:03:05 +02001129 jcandidate_.reset(
1130 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131
1132 // Set up JsepSessionDescription.
1133 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1134 std::string mline_id;
1135 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001136 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 // In this test, the audio m line index will be 0, and the video m line
1138 // will be 1.
1139 bool is_video = (i > 5);
1140 mline_id = is_video ? "video_content_name" : "audio_content_name";
1141 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001142 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143 jdesc_.AddCandidate(&jice);
1144 }
1145 }
1146
Seth Hampson5b4f0752018-04-02 16:31:36 -07001147 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001148 const IceCandidateCollection* video_candidates_collection =
1149 jdesc_.candidates(1);
1150 ASSERT_NE(nullptr, video_candidates_collection);
1151 std::vector<cricket::Candidate> video_candidates;
1152 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1153 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1154 c.set_transport_name("video_content_name");
1155 video_candidates.push_back(c);
1156 }
1157 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001158 }
1159
1160 // Turns the existing reference description into a description using
1161 // a=bundle-only. This means no transport attributes and a 0 port value on
1162 // the m= sections not associated with the BUNDLE-tag.
1163 void MakeBundleOnlyDescription() {
1164 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001165
1166 // And the rest of the transport attributes.
1167 desc_.transport_infos()[1].description.ice_ufrag.clear();
1168 desc_.transport_infos()[1].description.ice_pwd.clear();
1169 desc_.transport_infos()[1].description.connection_role =
1170 cricket::CONNECTIONROLE_NONE;
1171
1172 // Set bundle-only flag.
1173 desc_.contents()[1].bundle_only = true;
1174
1175 // Add BUNDLE group.
1176 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1177 group.AddContentName(kAudioContentName);
1178 group.AddContentName(kVideoContentName);
1179 desc_.AddGroup(group);
1180
1181 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1182 jdesc_.session_version()));
1183 }
1184
deadbeef9d3584c2016-02-16 17:54:10 -08001185 // Turns the existing reference description into a plan B description,
1186 // with 2 audio tracks and 3 video tracks.
1187 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001188 audio_desc_ = audio_desc_->Copy();
1189 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001190
1191 StreamParams audio_track_2;
1192 audio_track_2.id = kAudioTrackId2;
1193 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001194 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001195 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1196 audio_desc_->AddStream(audio_track_2);
1197
1198 StreamParams video_track_2;
1199 video_track_2.id = kVideoTrackId2;
1200 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001201 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001202 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1203 video_desc_->AddStream(video_track_2);
1204
1205 StreamParams video_track_3;
1206 video_track_3.id = kVideoTrackId3;
1207 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001208 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001209 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1210 video_desc_->AddStream(video_track_3);
1211
1212 desc_.RemoveContentByName(kAudioContentName);
1213 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001214 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1215 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001216
1217 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1218 jdesc_.session_version()));
1219 }
1220
1221 // Turns the existing reference description into a unified plan description,
1222 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001223 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001224 // Audio track 2.
1225 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1226 StreamParams audio_track_2;
1227 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001228 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001229 if (use_ssrcs) {
1230 audio_track_2.cname = kStream2Cname;
1231 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1232 }
deadbeef9d3584c2016-02-16 17:54:10 -08001233 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001234 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001235 desc_.AddTransportInfo(TransportInfo(
1236 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001237 // Video track 2, in stream 2.
1238 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1239 StreamParams video_track_2;
1240 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001241 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001242 if (use_ssrcs) {
1243 video_track_2.cname = kStream2Cname;
1244 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1245 }
deadbeef9d3584c2016-02-16 17:54:10 -08001246 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001247 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001248 desc_.AddTransportInfo(TransportInfo(
1249 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001250
1251 // Video track 3, in stream 2.
1252 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1253 StreamParams video_track_3;
1254 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001255 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001256 if (use_ssrcs) {
1257 video_track_3.cname = kStream2Cname;
1258 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1259 }
deadbeef9d3584c2016-02-16 17:54:10 -08001260 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001261 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001262 desc_.AddTransportInfo(TransportInfo(
1263 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001264 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001265
1266 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1267 jdesc_.session_version()));
1268 }
1269
1270 // Creates an audio content description with no streams, and some default
1271 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 AudioContentDescription* CreateAudioContentDescription() {
1273 AudioContentDescription* audio = new AudioContentDescription();
1274 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001275 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001276 audio->AddCrypto(CryptoParams(
1277 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1279 "dummy_session_params"));
1280 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001281 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001282 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001283 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1284 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 return audio;
1286 }
1287
Seth Hampson5b4f0752018-04-02 16:31:36 -07001288 // Turns the existing reference description into a unified plan description,
1289 // with 3 audio MediaContentDescriptions with special StreamParams that
1290 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1291 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001292 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001293 desc_.RemoveContentByName(kVideoContentName);
1294 desc_.RemoveTransportInfoByName(kVideoContentName);
1295 RemoveVideoCandidates();
1296
1297 // Audio track 2 has 2 media stream ids.
1298 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1299 StreamParams audio_track_2;
1300 audio_track_2.id = kAudioTrackId2;
1301 audio_track_2.cname = kStream1Cname;
1302 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1303 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1304 audio_desc_2->AddStream(audio_track_2);
1305 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001306 desc_.AddTransportInfo(TransportInfo(
1307 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001308
1309 // Audio track 3 has no stream ids.
1310 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1311 StreamParams audio_track_3;
1312 audio_track_3.id = kAudioTrackId3;
1313 audio_track_3.cname = kStream2Cname;
1314 audio_track_3.set_stream_ids({});
1315 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1316 audio_desc_3->AddStream(audio_track_3);
1317 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001318 desc_.AddTransportInfo(TransportInfo(
1319 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001320 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001321 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1322 jdesc_.session_version()));
1323 }
1324
Seth Hampson5897a6e2018-04-03 11:16:33 -07001325 // Turns the existing reference description into a unified plan description
1326 // with one audio MediaContentDescription that contains one StreamParams with
1327 // 0 ssrcs.
1328 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1329 desc_.RemoveContentByName(kVideoContentName);
1330 desc_.RemoveContentByName(kAudioContentName);
1331 desc_.RemoveTransportInfoByName(kVideoContentName);
1332 RemoveVideoCandidates();
1333
1334 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1335 StreamParams audio_track;
1336 audio_track.id = kAudioTrackId1;
1337 audio_track.set_stream_ids({kStreamId1});
1338 audio_desc->AddStream(audio_track);
1339 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1340
1341 // Enable signaling a=msid lines.
1342 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1343 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1344 jdesc_.session_version()));
1345 }
1346
deadbeef9d3584c2016-02-16 17:54:10 -08001347 // Creates a video content description with no streams, and some default
1348 // configuration.
1349 VideoContentDescription* CreateVideoContentDescription() {
1350 VideoContentDescription* video = new VideoContentDescription();
1351 video->AddCrypto(CryptoParams(
1352 1, "AES_CM_128_HMAC_SHA1_80",
1353 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1354 video->set_protocol(cricket::kMediaProtocolSavpf);
1355 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001356 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001357 return video;
1358 }
1359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001361 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 // type
1363 EXPECT_EQ(cd1->type(), cd1->type());
1364
1365 // content direction
1366 EXPECT_EQ(cd1->direction(), cd2->direction());
1367
1368 // rtcp_mux
1369 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1370
deadbeef13871492015-12-09 12:37:51 -08001371 // rtcp_reduced_size
1372 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1373
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 // cryptos
1375 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1376 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1377 ADD_FAILURE();
1378 return;
1379 }
Yves Gerey665174f2018-06-19 15:03:05 +02001380 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 const CryptoParams c1 = cd1->cryptos().at(i);
1382 const CryptoParams c2 = cd2->cryptos().at(i);
1383 EXPECT_TRUE(c1.Matches(c2));
1384 EXPECT_EQ(c1.key_params, c2.key_params);
1385 EXPECT_EQ(c1.session_params, c2.session_params);
1386 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001389 // Use an equivalence class here, for old and new versions of the
1390 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001391 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1392 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1393 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001394 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001395 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1396 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1397 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001398 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001399 } else {
1400 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1401 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402
1403 // codecs
1404 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1405
1406 // bandwidth
1407 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1408
1409 // streams
1410 EXPECT_EQ(cd1->streams(), cd2->streams());
1411
Johannes Kron0854eb62018-10-10 22:33:20 +02001412 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001413 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 // extmap
1416 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1417 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001418 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001419 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1420 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_EQ(ext1.uri, ext2.uri);
1422 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001423 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 }
1426
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001427 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1428 const std::vector<std::string>& ids) {
1429 // Order of elements does not matter, only equivalence of sets.
1430 EXPECT_EQ(rids.size(), ids.size());
1431 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001432 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1433 return rid.rid == id;
1434 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001435 }
1436 }
1437
Amit Hilbucha2012042018-12-03 11:35:05 -08001438 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1439 const SimulcastDescription& simulcast2) {
1440 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1441 EXPECT_EQ(simulcast1.receive_layers().size(),
1442 simulcast2.receive_layers().size());
1443 }
1444
zstein4b2e0822017-02-17 19:48:38 -08001445 void CompareDataContentDescription(const DataContentDescription* dcd1,
1446 const DataContentDescription* dcd2) {
1447 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1448 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1449 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
1451 void CompareSessionDescription(const SessionDescription& desc1,
1452 const SessionDescription& desc2) {
1453 // Compare content descriptions.
1454 if (desc1.contents().size() != desc2.contents().size()) {
1455 ADD_FAILURE();
1456 return;
1457 }
Yves Gerey665174f2018-06-19 15:03:05 +02001458 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1460 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001461 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001463 EXPECT_EQ(c1.type, c2.type);
1464 EXPECT_EQ(c1.rejected, c2.rejected);
1465 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466
1467 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1468 if (IsAudioContent(&c1)) {
1469 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001470 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001472 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1474 }
1475
1476 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1477 if (IsVideoContent(&c1)) {
1478 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001479 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001481 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1483 }
1484
1485 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1486 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001487 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1488 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001489 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001491
1492 CompareSimulcastDescription(
1493 c1.media_description()->simulcast_description(),
1494 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 }
1496
1497 // group
1498 const cricket::ContentGroups groups1 = desc1.groups();
1499 const cricket::ContentGroups groups2 = desc2.groups();
1500 EXPECT_EQ(groups1.size(), groups1.size());
1501 if (groups1.size() != groups2.size()) {
1502 ADD_FAILURE();
1503 return;
1504 }
1505 for (size_t i = 0; i < groups1.size(); ++i) {
1506 const cricket::ContentGroup group1 = groups1.at(i);
1507 const cricket::ContentGroup group2 = groups2.at(i);
1508 EXPECT_EQ(group1.semantics(), group2.semantics());
1509 const cricket::ContentNames names1 = group1.content_names();
1510 const cricket::ContentNames names2 = group2.content_names();
1511 EXPECT_EQ(names1.size(), names2.size());
1512 if (names1.size() != names2.size()) {
1513 ADD_FAILURE();
1514 return;
1515 }
1516 cricket::ContentNames::const_iterator iter1 = names1.begin();
1517 cricket::ContentNames::const_iterator iter2 = names2.begin();
1518 while (iter1 != names1.end()) {
1519 EXPECT_EQ(*iter1++, *iter2++);
1520 }
1521 }
1522
1523 // transport info
1524 const cricket::TransportInfos transports1 = desc1.transport_infos();
1525 const cricket::TransportInfos transports2 = desc2.transport_infos();
1526 EXPECT_EQ(transports1.size(), transports2.size());
1527 if (transports1.size() != transports2.size()) {
1528 ADD_FAILURE();
1529 return;
1530 }
1531 for (size_t i = 0; i < transports1.size(); ++i) {
1532 const cricket::TransportInfo transport1 = transports1.at(i);
1533 const cricket::TransportInfo transport2 = transports2.at(i);
1534 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 EXPECT_EQ(transport1.description.ice_ufrag,
1536 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001537 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001538 EXPECT_EQ(transport1.description.ice_mode,
1539 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 if (transport1.description.identity_fingerprint) {
1541 EXPECT_EQ(*transport1.description.identity_fingerprint,
1542 *transport2.description.identity_fingerprint);
1543 } else {
1544 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1545 transport2.description.identity_fingerprint.get());
1546 }
1547 EXPECT_EQ(transport1.description.transport_options,
1548 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 }
deadbeefc80741f2015-10-22 13:14:45 -07001550
1551 // global attributes
1552 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001553 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 }
1555
Yves Gerey665174f2018-06-19 15:03:05 +02001556 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1557 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1559 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1560 CompareSessionDescription(*desc1.description(), *desc2.description());
1561 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1562 return false;
1563 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1564 const IceCandidateCollection* cc1 = desc1.candidates(i);
1565 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001566 if (cc1->count() != cc2->count()) {
1567 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001569 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 for (size_t j = 0; j < cc1->count(); ++j) {
1571 const IceCandidateInterface* c1 = cc1->at(j);
1572 const IceCandidateInterface* c2 = cc2->at(j);
1573 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1574 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1575 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1576 }
1577 }
1578 return true;
1579 }
1580
1581 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1582 // them with invalid keywords so that the parser will just ignore them.
1583 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001584 absl::StrReplaceAll(
1585 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 return true;
1587 }
1588
1589 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001590 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1591 int mline_index,
1592 const std::string& ufrag,
1593 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 std::string content_name;
1595 if (mline_index == 0) {
1596 content_name = kAudioContentName;
1597 } else if (mline_index == 1) {
1598 content_name = kVideoContentName;
1599 } else {
nissec80e7412017-01-11 05:56:46 -08001600 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 }
Yves Gerey665174f2018-06-19 15:03:05 +02001602 TransportInfo transport_info(content_name,
1603 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 SessionDescription* desc =
1605 const_cast<SessionDescription*>(jdesc->description());
1606 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001607 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1609 const IceCandidateCollection* cc = jdesc_.candidates(i);
1610 for (size_t j = 0; j < cc->count(); ++j) {
1611 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001612 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1613 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 }
1615 }
1616 }
1617 return true;
1618 }
1619
1620 void AddIceOptions(const std::string& content_name,
1621 const std::vector<std::string>& transport_options) {
1622 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1623 cricket::TransportInfo transport_info =
1624 *(desc_.GetTransportInfoByName(content_name));
1625 desc_.RemoveTransportInfoByName(content_name);
1626 transport_info.description.transport_options = transport_options;
1627 desc_.AddTransportInfo(transport_info);
1628 }
1629
deadbeef3f7219b2015-12-28 15:17:14 -08001630 void SetIceUfragPwd(const std::string& content_name,
1631 const std::string& ice_ufrag,
1632 const std::string& ice_pwd) {
1633 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1634 cricket::TransportInfo transport_info =
1635 *(desc_.GetTransportInfoByName(content_name));
1636 desc_.RemoveTransportInfoByName(content_name);
1637 transport_info.description.ice_ufrag = ice_ufrag;
1638 transport_info.description.ice_pwd = ice_pwd;
1639 desc_.AddTransportInfo(transport_info);
1640 }
1641
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 void AddFingerprint() {
1643 desc_.RemoveTransportInfoByName(kAudioContentName);
1644 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001645 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001646 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001647 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001648 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1649 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001650 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1651 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001652 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001653 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1654 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001655 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 }
1657
jbauch5869f502017-06-29 12:31:36 -07001658 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001659 audio_desc_ = audio_desc_->Copy();
1660 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001661 audio_desc_->AddRtpHeaderExtension(
1662 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1663 video_desc_->AddRtpHeaderExtension(
1664 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 desc_.RemoveContentByName(kAudioContentName);
1666 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001667 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1668 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 }
1670
1671 void RemoveCryptos() {
1672 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1673 video_desc_->set_cryptos(std::vector<CryptoParams>());
1674 }
1675
Seth Hampson5897a6e2018-04-03 11:16:33 -07001676 // Removes everything in StreamParams from the session description that is
1677 // used for a=ssrc lines.
1678 void RemoveSsrcSignalingFromStreamParams() {
1679 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1680 // With Unified Plan there should be one StreamParams per m= section.
1681 StreamParams& stream =
1682 content_info.media_description()->mutable_streams()[0];
1683 stream.ssrcs.clear();
1684 stream.ssrc_groups.clear();
1685 stream.cname.clear();
1686 }
1687 }
1688
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001689 // Removes all a=ssrc lines from the SDP string, except for the
1690 // "a=ssrc:... cname:..." lines.
1691 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1692 const char kAttributeSsrc[] = "a=ssrc";
1693 const char kAttributeCname[] = "cname";
1694 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1695 while (ssrc_line_pos != std::string::npos) {
1696 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1697 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1698 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1699 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1700 // Only erase a=ssrc lines that don't contain "cname".
1701 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1702 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1703 } else {
1704 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1705 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1706 }
1707 }
1708 }
1709
Seth Hampson5897a6e2018-04-03 11:16:33 -07001710 // Removes all a=ssrc lines from the SDP string.
1711 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1712 const char kAttributeSsrc[] = "a=ssrc";
1713 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1714 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1715 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1716 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1717 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1718 }
1719 }
1720
Steve Anton4e70a722017-11-28 14:57:10 -08001721 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 audio_desc_->set_direction(direction);
1723 video_desc_->set_direction(direction);
1724 std::string new_sdp = kSdpFullString;
1725 ReplaceDirection(direction, &new_sdp);
1726
Yves Gerey665174f2018-06-19 15:03:05 +02001727 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 jdesc_.session_version())) {
1729 return false;
1730 }
Steve Antone831b8c2018-02-01 12:22:16 -08001731 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 EXPECT_EQ(new_sdp, message);
1733 return true;
1734 }
1735
1736 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001737 audio_desc_ = audio_desc_->Copy();
1738 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001739
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 desc_.RemoveContentByName(kAudioContentName);
1741 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001742 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001744 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001746 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1747 audio_rejected ? "" : kPwdVoice);
1748 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1749 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001750
1751 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1753
Steve Antona3a92c22017-12-07 10:27:41 -08001754 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001755 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001756 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 EXPECT_EQ(new_sdp, message);
1758 return true;
1759 }
1760
zstein4b2e0822017-02-17 19:48:38 -08001761 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001762 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001764 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001766 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001767 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001768 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1769 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001770 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1771 data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001772 desc_.AddTransportInfo(TransportInfo(
1773 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 }
1775
1776 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001777 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 data_desc_ = data.get();
1779
deadbeef67cf2c12016-04-13 10:07:16 -07001780 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 StreamParams data_stream;
1782 data_stream.id = kDataChannelMsid;
1783 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001784 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 data_stream.ssrcs.push_back(kDataChannelSsrc);
1786 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001787 data_desc_->AddCrypto(
1788 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1789 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001791 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001792 desc_.AddTransportInfo(TransportInfo(
1793 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 }
1795
Steve Anton4e70a722017-11-28 14:57:10 -08001796 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 std::string new_sdp = kSdpFullString;
1798 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001799 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800
1801 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1802
1803 audio_desc_->set_direction(direction);
1804 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001805 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 jdesc_.session_version())) {
1807 return false;
1808 }
1809 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1810 return true;
1811 }
1812
1813 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001814 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001816 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001818
Steve Antonb1c1de12017-12-21 15:14:30 -08001819 audio_desc_ = audio_desc_->Copy();
1820 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 desc_.RemoveContentByName(kAudioContentName);
1822 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001823 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001825 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001827 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1828 audio_rejected ? "" : kPwdVoice);
1829 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1830 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001831 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001832 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1833 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 return false;
1835 }
deadbeef3f7219b2015-12-28 15:17:14 -08001836 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 return true;
1838 }
1839
Yves Gerey665174f2018-06-19 15:03:05 +02001840 void TestDeserializeExtmap(bool session_level,
1841 bool media_level,
1842 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001843 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001844 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001845 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001847 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 std::string sdp_with_extmap = kSdpString;
1849 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001850 InjectAfter(kSessionTime,
1851 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1852 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 &sdp_with_extmap);
1854 }
1855 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001856 InjectAfter(kAttributeIcePwdVoice,
1857 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1858 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001860 InjectAfter(kAttributeIcePwdVideo,
1861 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1862 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 &sdp_with_extmap);
1864 }
1865 // The extmap can't be present at the same time in both session level and
1866 // media level.
1867 if (session_level && media_level) {
1868 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001869 EXPECT_FALSE(
1870 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1872 } else {
1873 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1874 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1875 }
1876 }
1877
1878 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001879 const std::string& name,
1880 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 cricket::CodecParameterMap::const_iterator found = params.find(name);
1882 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001883 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 }
1885
1886 void TestDeserializeCodecParams(const CodecParams& params,
1887 JsepSessionDescription* jdesc_output) {
1888 std::string sdp =
1889 "v=0\r\n"
1890 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1891 "s=-\r\n"
1892 "t=0 0\r\n"
1893 // Include semantics for WebRTC Media Streams since it is supported by
1894 // this parser, and will be added to the SDP when serializing a session
1895 // description.
1896 "a=msid-semantic: WMS\r\n"
1897 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001898 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 // Pltype 111 listed before 103 and 104 in the map.
1900 "a=rtpmap:111 opus/48000/2\r\n"
1901 // Pltype 103 listed before 104.
1902 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001903 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001904 "a=fmtp:111 0-15,66,70\r\n"
1905 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001907 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001908 << "; sprop-stereo=" << params.sprop_stereo
1909 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001910 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 << "a=ptime:" << params.ptime << "\r\n"
1912 << "a=maxptime:" << params.max_ptime << "\r\n";
1913 sdp += os.str();
1914
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001915 os.clear();
1916 os.str("");
1917 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001918 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001919 << "a=rtpmap:99 VP8/90000\r\n"
1920 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001921 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001922 sdp += os.str();
1923
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 // Deserialize
1925 SdpParseError error;
1926 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1927
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001929 GetFirstAudioContentDescription(jdesc_output->description());
1930 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 ASSERT_FALSE(acd->codecs().empty());
1932 cricket::AudioCodec opus = acd->codecs()[0];
1933 EXPECT_EQ("opus", opus.name);
1934 EXPECT_EQ(111, opus.id);
1935 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1936 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1937 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1938 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001939 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1940 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1942 cricket::AudioCodec codec = acd->codecs()[i];
1943 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1944 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001946
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001947 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001948 GetFirstVideoContentDescription(jdesc_output->description());
1949 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001950 ASSERT_FALSE(vcd->codecs().empty());
1951 cricket::VideoCodec vp8 = vcd->codecs()[0];
1952 EXPECT_EQ("VP8", vp8.name);
1953 EXPECT_EQ(99, vp8.id);
1954 cricket::VideoCodec rtx = vcd->codecs()[1];
1955 EXPECT_EQ("RTX", rtx.name);
1956 EXPECT_EQ(95, rtx.id);
1957 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 }
1959
1960 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1961 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001962 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 "v=0\r\n"
1964 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1965 "s=-\r\n"
1966 "t=0 0\r\n"
1967 // Include semantics for WebRTC Media Streams since it is supported by
1968 // this parser, and will be added to the SDP when serializing a session
1969 // description.
1970 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001971 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001972 "a=rtpmap:111 opus/48000/2\r\n";
1973 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 "m=video 3457 RTP/SAVPF 101\r\n"
1975 "a=rtpmap:101 VP8/90000\r\n"
1976 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001977 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001978 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001980 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001981 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001982 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001983 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001984 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 // Deserialize
1986 SdpParseError error;
1987 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001989 GetFirstAudioContentDescription(jdesc_output->description());
1990 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 ASSERT_FALSE(acd->codecs().empty());
1992 cricket::AudioCodec opus = acd->codecs()[0];
1993 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001994 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1995 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001998 GetFirstVideoContentDescription(jdesc_output->description());
1999 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 ASSERT_FALSE(vcd->codecs().empty());
2001 cricket::VideoCodec vp8 = vcd->codecs()[0];
2002 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2003 vp8.name.c_str());
2004 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002005 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2006 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2007 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2008 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2009 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2010 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2011 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2012 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 }
2014
2015 // Two SDP messages can mean the same thing but be different strings, e.g.
2016 // some of the lines can be serialized in different order.
2017 // However, a deserialized description can be compared field by field and has
2018 // no order. If deserializer has already been tested, serializing then
2019 // deserializing and comparing JsepSessionDescription will test
2020 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002021 void TestSerialize(const JsepSessionDescription& jdesc) {
2022 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002023 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 SdpParseError error;
2025 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2026 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2027 }
2028
zhihuang38989e52017-03-21 11:04:53 -07002029 // Calling 'Initialize' with a copy of the inner SessionDescription will
2030 // create a copy of the JsepSessionDescription without candidates. The
2031 // 'connection address' field, previously set from the candidates, must also
2032 // be reset.
2033 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2034 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2035 rtc::SocketAddress video_addr("0.0.0.0", 9);
2036 audio_desc_->set_connection_address(audio_addr);
2037 video_desc_->set_connection_address(video_addr);
2038 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2039 }
2040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 protected:
2042 SessionDescription desc_;
2043 AudioContentDescription* audio_desc_;
2044 VideoContentDescription* video_desc_;
2045 DataContentDescription* data_desc_;
2046 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002047 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 JsepSessionDescription jdesc_;
2049};
2050
2051void TestMismatch(const std::string& string1, const std::string& string2) {
2052 int position = 0;
2053 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2054 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002055 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 break;
2057 }
2058 }
2059 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2060 << " character\n"
2061 << " 1: " << string1.substr(position, 20) << "\n"
2062 << " 2: " << string2.substr(position, 20) << "\n";
2063}
2064
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2066 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002067 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 TestMismatch(std::string(kSdpFullString), message);
2069}
2070
2071TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002072 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002073 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074}
2075
2076// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2077// the case in a DTLS offer.
2078TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2079 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002080 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002081 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002082 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083
2084 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002085 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2086 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087
2088 EXPECT_EQ(sdp_with_fingerprint, message);
2089}
2090
2091// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2092// be the case in a DTLS answer.
2093TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2094 AddFingerprint();
2095 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002096 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002097 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002098 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
2100 std::string sdp_with_fingerprint = kSdpString;
2101 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2102 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002103 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2104 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105
2106 EXPECT_EQ(sdp_with_fingerprint, message);
2107}
2108
2109TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2110 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002111 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002112 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002113 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 EXPECT_EQ(std::string(kSdpString), message);
2115}
2116
2117TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2118 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2119 group.AddContentName(kAudioContentName);
2120 group.AddContentName(kVideoContentName);
2121 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002122 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002124 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 std::string sdp_with_bundle = kSdpFullString;
2126 InjectAfter(kSessionTime,
2127 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2128 &sdp_with_bundle);
2129 EXPECT_EQ(sdp_with_bundle, message);
2130}
2131
2132TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002133 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002135 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002137 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002139 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002141 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002143 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 &sdp_with_bandwidth);
2145 EXPECT_EQ(sdp_with_bandwidth, message);
2146}
2147
2148TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2149 std::vector<std::string> transport_options;
2150 transport_options.push_back(kIceOption1);
2151 transport_options.push_back(kIceOption3);
2152 AddIceOptions(kAudioContentName, transport_options);
2153 transport_options.clear();
2154 transport_options.push_back(kIceOption2);
2155 transport_options.push_back(kIceOption3);
2156 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002157 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002159 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002161 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002163 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 &sdp_with_ice_options);
2165 EXPECT_EQ(sdp_with_ice_options, message);
2166}
2167
2168TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002169 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170}
2171
2172TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002173 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174}
2175
2176TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002177 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178}
2179
2180TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2181 EXPECT_TRUE(TestSerializeRejected(true, false));
2182}
2183
2184TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2185 EXPECT_TRUE(TestSerializeRejected(false, true));
2186}
2187
2188TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2189 EXPECT_TRUE(TestSerializeRejected(true, true));
2190}
2191
2192TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2193 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002194 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195
zhihuang38989e52017-03-21 11:04:53 -07002196 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002197 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198
2199 std::string expected_sdp = kSdpString;
2200 expected_sdp.append(kSdpRtpDataChannelString);
2201 EXPECT_EQ(expected_sdp, message);
2202}
2203
2204TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002205 bool use_sctpmap = true;
2206 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002207 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208
zhihuang38989e52017-03-21 11:04:53 -07002209 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002210 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
2212 std::string expected_sdp = kSdpString;
2213 expected_sdp.append(kSdpSctpDataChannelString);
2214 EXPECT_EQ(message, expected_sdp);
2215}
2216
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002217TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002218 bool use_sctpmap = true;
2219 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002220 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002221 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002222 DataContentDescription* dcdesc =
2223 jsep_desc.description()
2224 ->GetContentDescriptionByName(kDataContentName)
2225 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002226
2227 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002228 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002229 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002230 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2231 dcdesc->AddOrReplaceCodec(codec);
2232
Steve Antone831b8c2018-02-01 12:22:16 -08002233 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002234
2235 std::string expected_sdp = kSdpString;
2236 expected_sdp.append(kSdpSctpDataChannelString);
2237
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002238 absl::StrReplaceAll(
2239 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2240 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002241
2242 EXPECT_EQ(expected_sdp, message);
2243}
2244
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002245TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002246 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002247 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002248 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002249 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002250 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002251
2252 std::string expected_sdp = kSdpString;
2253 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002254 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002255 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002256 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002257 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002258}
2259
Johannes Kron0854eb62018-10-10 22:33:20 +02002260TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002261 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002262 TestSerialize(jdesc_);
2263}
2264
2265TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2266 cricket::MediaContentDescription* video_desc =
2267 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2268 ASSERT_TRUE(video_desc);
2269 cricket::MediaContentDescription* audio_desc =
2270 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2271 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002272 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002273 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002274 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002275 cricket::MediaContentDescription::kMedia);
2276 TestSerialize(jdesc_);
2277}
2278
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002280 bool encrypted = false;
2281 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002282 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002283 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002284 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285
2286 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002287 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2288 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
2290 EXPECT_EQ(sdp_with_extmap, message);
2291}
2292
jbauch5869f502017-06-29 12:31:36 -07002293TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2294 bool encrypted = true;
2295 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002296 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002297 ASSERT_TRUE(
2298 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002299 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002300}
2301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302TEST_F(WebRtcSdpTest, SerializeCandidates) {
2303 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002304 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002305
2306 Candidate candidate_with_ufrag(candidates_.front());
2307 candidate_with_ufrag.set_username("ABC");
2308 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2309 candidate_with_ufrag));
2310 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2311 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002312
2313 Candidate candidate_with_network_info(candidates_.front());
2314 candidate_with_network_info.set_network_id(1);
2315 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2316 candidate_with_network_info));
2317 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2318 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2319 candidate_with_network_info.set_network_cost(999);
2320 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2321 candidate_with_network_info));
2322 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2323 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2324 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325}
2326
Zach Steinb336c272018-08-09 01:16:13 -07002327TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2328 rtc::SocketAddress address("a.test", 1234);
2329 cricket::Candidate candidate(
2330 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2331 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2332 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2333 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2334 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2335}
2336
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002337// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2338// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002339TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002340 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002341 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2342 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2343 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002344 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002345 std::unique_ptr<IceCandidateInterface> jcandidate(
2346 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002347
2348 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2349 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2350}
2351
htaa6b99442016-04-12 10:29:17 -07002352TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002353 cricket::VideoCodec h264_codec("H264");
2354 h264_codec.SetParam("profile-level-id", "42e01f");
2355 h264_codec.SetParam("level-asymmetry-allowed", "1");
2356 h264_codec.SetParam("packetization-mode", "1");
2357 video_desc_->AddCodec(h264_codec);
2358
htaa6b99442016-04-12 10:29:17 -07002359 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2360
Steve Antone831b8c2018-02-01 12:22:16 -08002361 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002362 size_t after_pt = message.find(" H264/90000");
2363 ASSERT_NE(after_pt, std::string::npos);
2364 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2365 ASSERT_NE(before_pt, std::string::npos);
2366 before_pt += strlen("a=rtpmap:");
2367 std::string pt = message.substr(before_pt, after_pt - before_pt);
2368 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2369 std::string to_find = "a=fmtp:" + pt + " ";
2370 size_t fmtp_pos = message.find(to_find);
2371 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002372 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002373 ASSERT_NE(std::string::npos, fmtp_endpos);
2374 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2375 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2376 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2377 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002378 // Check that there are no spaces after semicolons.
2379 // https://bugs.webrtc.org/5793
2380 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002381}
2382
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002384 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 // Deserialize
2386 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2387 // Verify
2388 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2389}
2390
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002391TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002392 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002393 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002394 "v=0\r\n"
2395 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2396 "s=-\r\n"
2397 "t=0 0\r\n"
2398 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002399 // Deserialize
2400 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2401 EXPECT_EQ(0u, jdesc.description()->contents().size());
2402}
2403
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002405 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 std::string sdp_without_carriage_return = kSdpFullString;
2407 Replace("\r\n", "\n", &sdp_without_carriage_return);
2408 // Deserialize
2409 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2410 // Verify
2411 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2412}
2413
2414TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2415 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002416 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002417 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2418 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002419 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2421 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2422}
2423
2424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2425 static const char kSdpNoRtpmapString[] =
2426 "v=0\r\n"
2427 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2428 "s=-\r\n"
2429 "t=0 0\r\n"
2430 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2431 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002432 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 // The rtpmap line for static payload codec is optional.
2434 "a=rtpmap:18 G729/16000\r\n"
2435 "a=rtpmap:103 ISAC/16000\r\n";
2436
Steve Antona3a92c22017-12-07 10:27:41 -08002437 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2439 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002440 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002442 // The codecs in the AudioContentDescription should be in the same order as
2443 // the payload types (<fmt>s) on the m= line.
2444 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2445 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002446 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 EXPECT_EQ(ref_codecs, audio->codecs());
2448}
2449
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002450TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2451 static const char kSdpNoRtpmapString[] =
2452 "v=0\r\n"
2453 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2454 "s=-\r\n"
2455 "t=0 0\r\n"
2456 "m=audio 49232 RTP/AVP 18 103\r\n"
2457 "a=fmtp:18 annexb=yes\r\n"
2458 "a=rtpmap:103 ISAC/16000\r\n";
2459
Steve Antona3a92c22017-12-07 10:27:41 -08002460 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002461 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2462 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002463 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002464
2465 cricket::AudioCodec g729 = audio->codecs()[0];
2466 EXPECT_EQ("G729", g729.name);
2467 EXPECT_EQ(8000, g729.clockrate);
2468 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002469 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002470 ASSERT_TRUE(found != g729.params.end());
2471 EXPECT_EQ(found->second, "yes");
2472
2473 cricket::AudioCodec isac = audio->codecs()[1];
2474 EXPECT_EQ("ISAC", isac.name);
2475 EXPECT_EQ(103, isac.id);
2476 EXPECT_EQ(16000, isac.clockrate);
2477}
2478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479// Ensure that we can deserialize SDP with a=fingerprint properly.
2480TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2481 // Add a DTLS a=fingerprint attribute to our session description.
2482 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002483 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002484 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 jdesc_.session_version()));
2486
Steve Antona3a92c22017-12-07 10:27:41 -08002487 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488 std::string sdp_with_fingerprint = kSdpString;
2489 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2490 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2491 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2492 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2493}
2494
2495TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002496 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 std::string sdp_with_bundle = kSdpFullString;
2498 InjectAfter(kSessionTime,
2499 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2500 &sdp_with_bundle);
2501 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2502 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2503 group.AddContentName(kAudioContentName);
2504 group.AddContentName(kVideoContentName);
2505 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002506 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 jdesc_.session_version()));
2508 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2509}
2510
2511TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002512 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002514 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002516 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002518 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002519 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002521 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002523 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 jdesc_.session_version()));
2525 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2526}
2527
2528TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002529 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002531 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002533 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002535 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 &sdp_with_ice_options);
2537 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2538 std::vector<std::string> transport_options;
2539 transport_options.push_back(kIceOption3);
2540 transport_options.push_back(kIceOption1);
2541 AddIceOptions(kAudioContentName, transport_options);
2542 transport_options.clear();
2543 transport_options.push_back(kIceOption3);
2544 transport_options.push_back(kIceOption2);
2545 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002546 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 jdesc_.session_version()));
2548 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2549}
2550
2551TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2552 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002553 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 std::string sdp_with_ufrag_pwd = kSdpFullString;
2555 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2556 // Add session level ufrag and pwd
2557 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002558 "a=ice-pwd:session+level+icepwd\r\n"
2559 "a=ice-ufrag:session+level+iceufrag\r\n",
2560 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002562 InjectAfter(
2563 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2565 &sdp_with_ufrag_pwd);
2566 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002567 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2568 "media+level+icepwd"));
2569 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2570 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2572 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2573}
2574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002576 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577}
2578
2579TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002580 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581}
2582
2583TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002584 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585}
2586
2587TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2588 EXPECT_TRUE(TestDeserializeRejected(true, false));
2589}
2590
2591TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2592 EXPECT_TRUE(TestDeserializeRejected(false, true));
2593}
2594
2595TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2596 EXPECT_TRUE(TestDeserializeRejected(true, true));
2597}
2598
2599// Tests that we can still handle the sdp uses mslabel and label instead of
2600// msid for backward compatibility.
2601TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002602 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002603 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 std::string sdp_without_msid = kSdpFullString;
2605 Replace("msid", "xmsid", &sdp_without_msid);
2606 // Deserialize
2607 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2608 // Verify
2609 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002610 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2611 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612}
2613
Johannes Kron0854eb62018-10-10 22:33:20 +02002614TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002615 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002616 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2617 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2618 // Deserialize
2619 JsepSessionDescription jdesc_deserialized(kDummyType);
2620 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2621 // Verify
2622 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2623}
2624
2625TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002626 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002627 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2628 // Deserialize
2629 JsepSessionDescription jdesc_deserialized(kDummyType);
2630 EXPECT_TRUE(
2631 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2632 // Verify
2633 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2634}
2635
2636TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2637 cricket::MediaContentDescription* video_desc =
2638 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2639 ASSERT_TRUE(video_desc);
2640 cricket::MediaContentDescription* audio_desc =
2641 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2642 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002643 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002644 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002645 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002646 cricket::MediaContentDescription::kMedia);
2647
2648 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2649 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2650 &sdp_with_extmap_allow_mixed);
2651 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2652 &sdp_with_extmap_allow_mixed);
2653
2654 // Deserialize
2655 JsepSessionDescription jdesc_deserialized(kDummyType);
2656 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2657 // Verify
2658 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2659}
2660
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2662 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2663
2664 std::string sdp = kSdpOneCandidate;
2665 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2666 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2667 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2668 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002669 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670
2671 // Candidate line without generation extension.
2672 sdp = kSdpOneCandidate;
2673 Replace(" generation 2", "", &sdp);
2674 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2675 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2676 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2677 Candidate expected = jcandidate_->candidate();
2678 expected.set_generation(0);
2679 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2680
honghaiza0c44ea2016-03-23 16:07:48 -07002681 // Candidate with network id and/or cost.
2682 sdp = kSdpOneCandidate;
2683 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2684 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2685 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2686 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2687 expected = jcandidate_->candidate();
2688 expected.set_network_id(2);
2689 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2690 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2691 // Add network cost
2692 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2693 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2694 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2695 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2696
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002697 sdp = kSdpTcpActiveCandidate;
2698 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2699 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002700 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002701 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2702 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2703 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002704 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2705 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002706 EXPECT_TRUE(
2707 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002708 sdp = kSdpTcpPassiveCandidate;
2709 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2710 sdp = kSdpTcpSOCandidate;
2711 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712}
2713
2714// This test verifies the deserialization of candidate-attribute
2715// as per RFC 5245. Candiate-attribute will be of the format
2716// candidate:<blah>. This format will be used when candidates
2717// are trickled.
2718TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2719 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2720
2721 std::string candidate_attribute = kRawCandidate;
2722 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2723 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2724 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2725 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2726 EXPECT_EQ(2u, jcandidate.candidate().generation());
2727
2728 // Candidate line without generation extension.
2729 candidate_attribute = kRawCandidate;
2730 Replace(" generation 2", "", &candidate_attribute);
2731 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2732 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2733 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2734 Candidate expected = jcandidate_->candidate();
2735 expected.set_generation(0);
2736 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2737
2738 // Candidate line without candidate:
2739 candidate_attribute = kRawCandidate;
2740 Replace("candidate:", "", &candidate_attribute);
2741 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2742
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002743 // Candidate line with IPV6 address.
2744 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002745
2746 // Candidate line with hostname address.
2747 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002748}
2749
2750// This test verifies that the deserialization of an invalid candidate string
2751// fails.
2752TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002753 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002754
2755 std::string candidate_attribute = kRawCandidate;
2756 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002758
2759 candidate_attribute = kSdpOneCandidate;
2760 candidate_attribute.replace(0, 1, "x");
2761 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2762
2763 candidate_attribute = kRawCandidate;
2764 candidate_attribute.append("\r\n");
2765 candidate_attribute.append(kRawCandidate);
2766 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2767
2768 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769}
2770
2771TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2772 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002773 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2775
2776 std::string sdp_with_data = kSdpString;
2777 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002778 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779
2780 // Deserialize
2781 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2782 // Verify
2783 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2784}
2785
2786TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002787 bool use_sctpmap = true;
2788 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002789 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2791
2792 std::string sdp_with_data = kSdpString;
2793 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002794 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795
lally@webrtc.org36300852015-02-24 20:19:35 +00002796 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2797 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2798 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2799
2800 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002801 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2802 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002803 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2804 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2805
2806 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002807 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2808 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2810 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2811}
2812
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002813TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002814 bool use_sctpmap = false;
2815 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002816 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002817 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2818
2819 std::string sdp_with_data = kSdpString;
2820 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002821 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002822
lally@webrtc.org36300852015-02-24 20:19:35 +00002823 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002824 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2825 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002826
lally@webrtc.org36300852015-02-24 20:19:35 +00002827 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002828 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2829 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002830 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2831 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002832
lally@webrtc.org36300852015-02-24 20:19:35 +00002833 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002834 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2835 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002836 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2837 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2838}
2839
lally69f57602015-10-08 10:15:04 -07002840TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002841 bool use_sctpmap = false;
2842 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002843 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002844 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2845
2846 std::string sdp_with_data = kSdpString;
2847 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002848 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002849
2850 // Verify with DTLS/SCTP.
2851 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2852 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2853
2854 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002855 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2856 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002857 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2858 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2859
2860 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002861 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2862 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002863 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2864 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2865}
2866
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002867// Helper function to set the max-message-size parameter in the
2868// SCTP data codec.
2869void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
2870 const std::string& new_value,
2871 JsepSessionDescription* jdesc) {
2872 cricket::SessionDescription* mutant = desc.Copy();
2873 DataContentDescription* dcdesc =
2874 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
2875 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2876 codecs[0].SetParam(cricket::kCodecParamMaxMessageSize, new_value);
2877 dcdesc->set_codecs(codecs);
2878 jdesc->Initialize(mutant, kSessionId, kSessionVersion);
2879}
2880
2881TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2882 bool use_sctpmap = false;
2883 AddSctpDataChannel(use_sctpmap);
2884 JsepSessionDescription jdesc(kDummyType);
2885 std::string sdp_with_data = kSdpString;
2886
2887 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2888 sdp_with_data.append("a=max-message-size:12345\r\n");
2889 MutateJsepSctpMaxMessageSize(desc_, "12345", &jdesc);
2890 JsepSessionDescription jdesc_output(kDummyType);
2891
2892 // Verify with DTLS/SCTP.
2893 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2894 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2895
2896 // Verify with UDP/DTLS/SCTP.
2897 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2898 kUdpDtlsSctp);
2899 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2900 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2901
2902 // Verify with TCP/DTLS/SCTP.
2903 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2904 kTcpDtlsSctp);
2905 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2906 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2907}
2908
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002909// Test to check the behaviour if sctp-port is specified
2910// on the m= line and in a=sctp-port.
2911TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002912 bool use_sctpmap = true;
2913 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002914 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002915 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2916
2917 std::string sdp_with_data = kSdpString;
2918 // Append m= attributes
2919 sdp_with_data.append(kSdpSctpDataChannelString);
2920 // Append a=sctp-port attribute
2921 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002922 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002923
2924 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2925}
2926
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002927// For crbug/344475.
2928TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2929 std::string sdp_with_data = kSdpString;
2930 sdp_with_data.append(kSdpSctpDataChannelString);
2931 // Remove the "\n" at the end.
2932 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002933 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002934
2935 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2936 // No crash is a pass.
2937}
2938
Steve Anton36b29d12017-10-30 09:57:42 -07002939void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002940 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002941 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002942 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002943 DataContentDescription* dcdesc =
2944 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002945 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002946 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002947 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002948 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002949 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002950
2951 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002952 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002953 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002954}
2955
2956TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2957 bool use_sctpmap = true;
2958 AddSctpDataChannel(use_sctpmap);
2959
2960 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002961 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002962 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002963
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002964 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002965 std::string sdp_with_data = kSdpString;
2966 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002967 absl::StrReplaceAll(
2968 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2969 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002970 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002971
2972 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2973 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002974}
2975
2976TEST_F(WebRtcSdpTest,
2977 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2978 bool use_sctpmap = false;
2979 AddSctpDataChannel(use_sctpmap);
2980
Steve Antona3a92c22017-12-07 10:27:41 -08002981 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002982 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002983
2984 // We need to test the deserialized JsepSessionDescription from
2985 // kSdpSctpDataChannelStringWithSctpPort for
2986 // draft-ietf-mmusic-sctp-sdp-07
2987 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002988 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002989 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002990 absl::StrReplaceAll(
2991 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2992 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002993 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002994
2995 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2996 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002997}
2998
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002999TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003000 // We want to test that deserializing data content limits bandwidth
3001 // settings (it should never be greater than the default).
3002 // This should prevent someone from using unlimited data bandwidth through
3003 // JS and "breaking the Internet".
3004 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003005 std::string sdp_with_bandwidth = kSdpString;
3006 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003007 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003008 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003009 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003010
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003011 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3012}
3013
3014TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003015 bool use_sctpmap = true;
3016 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003017 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08003018 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003019 dcd->set_bandwidth(100 * 1000);
3020 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
3021
3022 std::string sdp_with_bandwidth = kSdpString;
3023 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003024 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003025 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003026 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003027
3028 // SCTP has congestion control, so we shouldn't limit the bandwidth
3029 // as we do for RTP.
3030 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003031 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3032}
3033
Yves Gerey665174f2018-06-19 15:03:05 +02003034class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003035 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003036
3037TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003038 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003039 bool encrypted = GetParam();
3040 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003041}
3042
Yves Gerey665174f2018-06-19 15:03:05 +02003043TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003044 bool encrypted = GetParam();
3045 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046}
3047
Yves Gerey665174f2018-06-19 15:03:05 +02003048TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003049 bool encrypted = GetParam();
3050 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051}
3052
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003053INSTANTIATE_TEST_SUITE_P(Encrypted,
3054 WebRtcSdpExtmapTest,
3055 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003056
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003057TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003058 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003059 std::string sdp = kSdpFullString;
3060 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3061 // Deserialize
3062 SdpParseError error;
3063 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003064 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003065 EXPECT_EQ(lastline, error.line);
3066 EXPECT_EQ("Invalid SDP line.", error.description);
3067}
3068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3070 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3071 std::string new_sdp = kSdpOneCandidate;
3072 Replace("udp", "unsupported_transport", &new_sdp);
3073 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3074 new_sdp = kSdpOneCandidate;
3075 Replace("udp", "uDP", &new_sdp);
3076 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3077 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3078 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3079 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3080}
3081
honghaiza54a0802015-12-16 18:37:23 -08003082TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003084 EXPECT_TRUE(
3085 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003086 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3087 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3088 Candidate ref_candidate = jcandidate_->candidate();
3089 ref_candidate.set_username("user_rtp");
3090 ref_candidate.set_password("password_rtp");
3091 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3092}
3093
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003094TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003095 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003096
3097 // Deserialize
3098 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3099
3100 // Verify
3101 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003102 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003103 EXPECT_TRUE(audio->conference_mode());
3104
3105 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003106 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003107 EXPECT_TRUE(video->conference_mode());
3108}
3109
deadbeefd45aea82017-09-16 01:24:29 -07003110TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003111 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003112
3113 // We tested deserialization already above, so just test that if we serialize
3114 // and deserialize the flag doesn't disappear.
3115 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003116 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003117 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3118
3119 // Verify.
3120 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003121 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003122 EXPECT_TRUE(audio->conference_mode());
3123
3124 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003125 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003126 EXPECT_TRUE(video->conference_mode());
3127}
3128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3130 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003131 const char kSdpEmptyType[] = " =candidate";
3132 const char kSdpEqualAsPlus[] = "a+candidate";
3133 const char kSdpSpaceAfterEqual[] = "a= candidate";
3134 const char kSdpUpperType[] = "A=candidate";
3135 const char kSdpEmptyLine[] = "";
3136 const char kSdpMissingValue[] = "a=";
3137
Yves Gerey665174f2018-06-19 15:03:05 +02003138 const char kSdpBrokenFingerprint[] =
3139 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003140 "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 +02003141 const char kSdpExtraField[] =
3142 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 "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 +02003144 const char kSdpMissingSpace[] =
3145 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 "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 +00003147 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003148 const char kSdpMd5[] =
3149 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003150 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151
3152 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003153 ExpectParseFailure("v=", kSdpDestroyer);
3154 ExpectParseFailure("o=", kSdpDestroyer);
3155 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003157 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003158
3159 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003160 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3161 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162
3163 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003164 ExpectParseFailure("a=candidate", kSdpEmptyType);
3165 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3166 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3167 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003168
3169 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3170 // because it's orthogonal to what we are replacing and hence
3171 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003172 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3173 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3174 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3175 ExpectParseFailure("a=sendrecv", kSdpMd5);
3176
3177 // Empty Line
3178 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3179 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003180}
3181
3182TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3183 // ssrc
3184 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003185 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003186 // crypto
3187 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3188 // rtpmap
3189 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3190 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3191 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3192 // candidate
3193 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3194 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3195 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3196 ExpectParseFailure("rport 2346", "rport badvalue");
3197 ExpectParseFailure("rport 2346 generation 2",
3198 "rport 2346 generation badvalue");
3199 // m line
3200 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3201 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3202
3203 // bandwidth
3204 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003205 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003206 // rtcp-fb
3207 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3208 "a=rtcp-fb:badvalue nack\r\n",
3209 "a=rtcp-fb:badvalue nack");
3210 // extmap
3211 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3212 "a=extmap:badvalue http://example.com\r\n",
3213 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214}
3215
3216TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003217 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218
3219 const char kSdpWithReorderedPlTypesString[] =
3220 "v=0\r\n"
3221 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3222 "s=-\r\n"
3223 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003224 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003225 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3226 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003228 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
3230 // Deserialize
3231 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003234 GetFirstAudioContentDescription(jdesc_output.description());
3235 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003237 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3238 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003239 EXPECT_EQ(104, acd->codecs()[0].id);
3240}
3241
3242TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003243 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244 CodecParams params;
3245 params.max_ptime = 40;
3246 params.ptime = 30;
3247 params.min_ptime = 10;
3248 params.sprop_stereo = 1;
3249 params.stereo = 1;
3250 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003251 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003253 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254}
3255
3256TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3257 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003258 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003260 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261}
3262
3263TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3264 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003265 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003267 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268}
3269
3270TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003271 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272
3273 const char kSdpWithFmtpString[] =
3274 "v=0\r\n"
3275 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3276 "s=-\r\n"
3277 "t=0 0\r\n"
3278 "m=video 3457 RTP/SAVPF 120\r\n"
3279 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003280 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3281
3282 // Deserialize
3283 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003284 EXPECT_TRUE(
3285 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003286
Donald Curtis0e07f922015-05-15 09:21:23 -07003287 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003288 GetFirstVideoContentDescription(jdesc_output.description());
3289 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003290 ASSERT_FALSE(vcd->codecs().empty());
3291 cricket::VideoCodec vp8 = vcd->codecs()[0];
3292 EXPECT_EQ("VP8", vp8.name);
3293 EXPECT_EQ(120, vp8.id);
3294 cricket::CodecParameterMap::iterator found =
3295 vp8.params.find("x-google-min-bitrate");
3296 ASSERT_TRUE(found != vp8.params.end());
3297 EXPECT_EQ(found->second, "10");
3298 found = vp8.params.find("x-google-max-quantization");
3299 ASSERT_TRUE(found != vp8.params.end());
3300 EXPECT_EQ(found->second, "40");
3301}
3302
johan2d8d23e2016-06-03 01:22:42 -07003303TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003304 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003305
3306 const char kSdpWithFmtpString[] =
3307 "v=0\r\n"
3308 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3309 "s=-\r\n"
3310 "t=0 0\r\n"
3311 "m=video 49170 RTP/AVP 98\r\n"
3312 "a=rtpmap:98 H264/90000\r\n"
3313 "a=fmtp:98 profile-level-id=42A01E; "
3314 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3315
3316 // Deserialize.
3317 SdpParseError error;
3318 EXPECT_TRUE(
3319 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3320
johan2d8d23e2016-06-03 01:22:42 -07003321 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003322 GetFirstVideoContentDescription(jdesc_output.description());
3323 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003324 ASSERT_FALSE(vcd->codecs().empty());
3325 cricket::VideoCodec h264 = vcd->codecs()[0];
3326 EXPECT_EQ("H264", h264.name);
3327 EXPECT_EQ(98, h264.id);
3328 cricket::CodecParameterMap::const_iterator found =
3329 h264.params.find("profile-level-id");
3330 ASSERT_TRUE(found != h264.params.end());
3331 EXPECT_EQ(found->second, "42A01E");
3332 found = h264.params.find("sprop-parameter-sets");
3333 ASSERT_TRUE(found != h264.params.end());
3334 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3335}
3336
Donald Curtis0e07f922015-05-15 09:21:23 -07003337TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003338 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003339
3340 const char kSdpWithFmtpString[] =
3341 "v=0\r\n"
3342 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3343 "s=-\r\n"
3344 "t=0 0\r\n"
3345 "m=video 3457 RTP/SAVPF 120\r\n"
3346 "a=rtpmap:120 VP8/90000\r\n"
3347 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348
3349 // Deserialize
3350 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003351 EXPECT_TRUE(
3352 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003355 GetFirstVideoContentDescription(jdesc_output.description());
3356 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357 ASSERT_FALSE(vcd->codecs().empty());
3358 cricket::VideoCodec vp8 = vcd->codecs()[0];
3359 EXPECT_EQ("VP8", vp8.name);
3360 EXPECT_EQ(120, vp8.id);
3361 cricket::CodecParameterMap::iterator found =
3362 vp8.params.find("x-google-min-bitrate");
3363 ASSERT_TRUE(found != vp8.params.end());
3364 EXPECT_EQ(found->second, "10");
3365 found = vp8.params.find("x-google-max-quantization");
3366 ASSERT_TRUE(found != vp8.params.end());
3367 EXPECT_EQ(found->second, "40");
3368}
3369
ossuaa4b0772017-01-30 07:41:18 -08003370TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003371 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003372
3373 cricket::AudioCodecs codecs = acd->codecs();
3374 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3375 acd->set_codecs(codecs);
3376
Yves Gerey665174f2018-06-19 15:03:05 +02003377 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003378 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003379 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003380 std::string sdp_with_fmtp = kSdpFullString;
3381 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3382 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3383 &sdp_with_fmtp);
3384 EXPECT_EQ(sdp_with_fmtp, message);
3385}
3386
3387TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003388 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003389
3390 cricket::AudioCodecs codecs = acd->codecs();
3391 codecs[0].params["stereo"] = "1";
3392 acd->set_codecs(codecs);
3393
Yves Gerey665174f2018-06-19 15:03:05 +02003394 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003395 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003396 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003397 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003398 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003399 &sdp_with_fmtp);
3400 EXPECT_EQ(sdp_with_fmtp, message);
3401}
3402
3403TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003404 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003405
3406 cricket::AudioCodecs codecs = acd->codecs();
3407 codecs[0].params["ptime"] = "20";
3408 codecs[0].params["maxptime"] = "120";
3409 acd->set_codecs(codecs);
3410
Yves Gerey665174f2018-06-19 15:03:05 +02003411 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003412 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003413 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003414 std::string sdp_with_fmtp = kSdpFullString;
3415 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3416 "a=maxptime:120\r\n" // No comma here. String merging!
3417 "a=ptime:20\r\n",
3418 &sdp_with_fmtp);
3419 EXPECT_EQ(sdp_with_fmtp, message);
3420}
3421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003423 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424
3425 cricket::VideoCodecs codecs = vcd->codecs();
3426 codecs[0].params["x-google-min-bitrate"] = "10";
3427 vcd->set_codecs(codecs);
3428
Yves Gerey665174f2018-06-19 15:03:05 +02003429 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003431 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 std::string sdp_with_fmtp = kSdpFullString;
3433 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003434 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 EXPECT_EQ(sdp_with_fmtp, message);
3436}
3437
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003438TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3439 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003440 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 std::string sdp_with_icelite = kSdpFullString;
3442 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3443 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3444 const cricket::TransportInfo* tinfo1 =
3445 desc->GetTransportInfoByName("audio_content_name");
3446 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3447 const cricket::TransportInfo* tinfo2 =
3448 desc->GetTransportInfoByName("video_content_name");
3449 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003450
3451 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003452 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3454 desc = jdesc_with_icelite.description();
3455 const cricket::TransportInfo* atinfo =
3456 desc->GetTransportInfoByName("audio_content_name");
3457 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3458 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003459 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003461
3462 // Now that we know deserialization works, we can use TestSerialize to test
3463 // serialization.
3464 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465}
3466
3467// Verifies that the candidates in the input SDP are parsed and serialized
3468// correctly in the output SDP.
3469TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3470 std::string sdp_with_data = kSdpString;
3471 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003472 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473
3474 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003475 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003477
3478TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3479 AddFingerprint();
3480 TransportInfo audio_transport_info =
3481 *(desc_.GetTransportInfoByName(kAudioContentName));
3482 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3483 audio_transport_info.description.connection_role);
3484 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003485 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003486
3487 TransportInfo video_transport_info =
3488 *(desc_.GetTransportInfoByName(kVideoContentName));
3489 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3490 video_transport_info.description.connection_role);
3491 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003492 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003493
3494 desc_.RemoveTransportInfoByName(kAudioContentName);
3495 desc_.RemoveTransportInfoByName(kVideoContentName);
3496
3497 desc_.AddTransportInfo(audio_transport_info);
3498 desc_.AddTransportInfo(video_transport_info);
3499
Yves Gerey665174f2018-06-19 15:03:05 +02003500 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003501 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003502 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003503 std::string sdp_with_dtlssetup = kSdpFullString;
3504
3505 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003506 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3507 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003508 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003509 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003510 EXPECT_EQ(sdp_with_dtlssetup, message);
3511}
3512
3513TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003514 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003515 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003516 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003517 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3518 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3519 const cricket::TransportInfo* atinfo =
3520 desc->GetTransportInfoByName("audio_content_name");
3521 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3522 atinfo->description.connection_role);
3523 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003524 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003525 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3526 vtinfo->description.connection_role);
3527}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003528
3529// Verifies that the order of the serialized m-lines follows the order of the
3530// ContentInfo in SessionDescription, and vise versa for deserialization.
3531TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003532 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003533 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3534 kSdpSctpDataChannelString};
3535 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3536 cricket::MEDIA_TYPE_VIDEO,
3537 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003538
3539 // Verifies all 6 permutations.
3540 for (size_t i = 0; i < 6; ++i) {
3541 size_t media_content_in_sdp[3];
3542 // The index of the first media content.
3543 media_content_in_sdp[0] = i / 2;
3544 // The index of the second media content.
3545 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3546 // The index of the third media content.
3547 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3548
3549 std::string sdp_string = kSdpSessionString;
3550 for (size_t i = 0; i < 3; ++i)
3551 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3552
3553 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3554 cricket::SessionDescription* desc = jdesc.description();
3555 EXPECT_EQ(3u, desc->contents().size());
3556
3557 for (size_t i = 0; i < 3; ++i) {
3558 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003559 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003560 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3561 }
3562
Steve Antone831b8c2018-02-01 12:22:16 -08003563 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003564 EXPECT_EQ(sdp_string, serialized_sdp);
3565 }
3566}
deadbeef9d3584c2016-02-16 17:54:10 -08003567
deadbeef25ed4352016-12-12 18:37:36 -08003568TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3569 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003570 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003571 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003572 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3573 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3574}
3575
deadbeef12771a12017-01-03 13:53:47 -08003576// The semantics of "a=bundle-only" are only defined when it's used in
3577// combination with a 0 port on the m= line. We should ignore it if used with a
3578// nonzero port.
3579TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3580 // Make the base bundle-only description but unset the bundle-only flag.
3581 MakeBundleOnlyDescription();
3582 jdesc_.description()->contents()[1].bundle_only = false;
3583
3584 std::string modified_sdp = kBundleOnlySdpFullString;
3585 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003586 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003587 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3588 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003589}
3590
3591TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3592 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003593 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003594}
3595
deadbeef9d3584c2016-02-16 17:54:10 -08003596TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3597 MakePlanBDescription();
3598
Steve Antona3a92c22017-12-07 10:27:41 -08003599 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003600 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3601
3602 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3603}
3604
3605TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3606 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003607 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003608}
3609
3610TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3611 MakeUnifiedPlanDescription();
3612
Steve Antona3a92c22017-12-07 10:27:41 -08003613 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003614 EXPECT_TRUE(
3615 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3616
3617 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3618}
3619
3620TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3621 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003622 TestSerialize(jdesc_);
3623}
3624
Seth Hampson5b4f0752018-04-02 16:31:36 -07003625// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003626// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3627// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003628// with no stream ids and multiple stream ids. For parsing this, the Unified
3629// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3630// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003631TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3632 // Create both msid lines for Plan B and Unified Plan support.
3633 MakeUnifiedPlanDescriptionMultipleStreamIds(
3634 cricket::kMsidSignalingMediaSection |
3635 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003636
3637 JsepSessionDescription deserialized_description(kDummyType);
3638 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3639 &deserialized_description));
3640
3641 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003642 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3643 cricket::kMsidSignalingSsrcAttribute,
3644 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003645}
3646
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003647// Tests the serialization of a Unified Plan SDP that is compatible for both
3648// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3649// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3650// multiple stream ids.
3651TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3652 // Create both msid lines for Plan B and Unified Plan support.
3653 MakeUnifiedPlanDescriptionMultipleStreamIds(
3654 cricket::kMsidSignalingMediaSection |
3655 cricket::kMsidSignalingSsrcAttribute);
3656 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3657 // We explicitly test that the serialized SDP string is equal to the hard
3658 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3659 // take priority over "a=ssrc msid" lines. This means if we just used
3660 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3661 // and still pass, because the deserialized version would be the same.
3662 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3663}
3664
3665// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3666// that signal stream IDs) is deserialized appropriately. It tests the case for
3667// no stream ids and multiple stream ids.
3668TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3669 // Only create a=msid lines for strictly Unified Plan stream ID support.
3670 MakeUnifiedPlanDescriptionMultipleStreamIds(
3671 cricket::kMsidSignalingMediaSection);
3672
3673 JsepSessionDescription deserialized_description(kDummyType);
3674 std::string unified_plan_sdp_string =
3675 kUnifiedPlanSdpFullStringWithSpecialMsid;
3676 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3677 EXPECT_TRUE(
3678 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3679
3680 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3681}
3682
3683// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3684// that signal stream IDs) is serialized appropriately. It tests the case for no
3685// stream ids and multiple stream ids.
3686TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3687 // Only create a=msid lines for strictly Unified Plan stream ID support.
3688 MakeUnifiedPlanDescriptionMultipleStreamIds(
3689 cricket::kMsidSignalingMediaSection);
3690
Seth Hampson5b4f0752018-04-02 16:31:36 -07003691 TestSerialize(jdesc_);
3692}
3693
Seth Hampson5897a6e2018-04-03 11:16:33 -07003694// This tests that a Unified Plan SDP with no a=ssrc lines is
3695// serialized/deserialized appropriately. In this case the
3696// MediaContentDescription will contain a StreamParams object that doesn't have
3697// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3698// SSRC lines.
3699TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3700 MakeUnifiedPlanDescription();
3701 RemoveSsrcSignalingFromStreamParams();
3702 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3703 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3704
3705 JsepSessionDescription deserialized_description(kDummyType);
3706 EXPECT_TRUE(
3707 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3708 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3709}
3710
3711TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3712 MakeUnifiedPlanDescription();
3713 RemoveSsrcSignalingFromStreamParams();
3714
3715 TestSerialize(jdesc_);
3716}
3717
Steve Antone831b8c2018-02-01 12:22:16 -08003718TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3719 JsepSessionDescription jsep_desc(kDummyType);
3720 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3721 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3722}
3723
3724TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3725 JsepSessionDescription jsep_desc(kDummyType);
3726 std::string sdp = kSdpSessionString;
3727 sdp += kSdpSctpDataChannelString;
3728 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3729 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3730}
3731
3732TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3733 JsepSessionDescription jsep_desc(kDummyType);
3734 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3735 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3736 jsep_desc.description()->msid_signaling());
3737}
3738
3739TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3740 JsepSessionDescription jsep_desc(kDummyType);
3741 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3742 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3743 jsep_desc.description()->msid_signaling());
3744}
3745
3746const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3747const char kSsrcAttributeMsidLine[] =
3748 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3749
3750TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3751 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3752 std::string sdp = webrtc::SdpSerialize(jdesc_);
3753
3754 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3755 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3756}
3757
3758TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3759 jdesc_.description()->set_msid_signaling(
3760 cricket::kMsidSignalingSsrcAttribute);
3761 std::string sdp = webrtc::SdpSerialize(jdesc_);
3762
3763 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3764 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3765}
3766
3767TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3768 jdesc_.description()->set_msid_signaling(
3769 cricket::kMsidSignalingMediaSection |
3770 cricket::kMsidSignalingSsrcAttribute);
3771 std::string sdp = webrtc::SdpSerialize(jdesc_);
3772
3773 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3774 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003775}
deadbeef7e146cb2016-09-28 10:04:34 -07003776
3777// Regression test for heap overflow bug:
3778// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3779TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003780 // The issue occurs when the sctp-port attribute is found in a video
3781 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003782 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003783 "v=0\r\n"
3784 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3785 "s=-\r\n"
3786 "t=0 0\r\n"
3787 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3788 "a=sctp-port 5000\r\n"
3789 "a=fmtp:108 foo=10\r\n";
3790
3791 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3792 "sctp-port");
3793}
deadbeefb2362572016-12-13 16:37:06 -08003794
3795// Regression test for integer overflow bug:
3796// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3797TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003798 // Bandwidth attribute is the max signed 32-bit int, which will get
3799 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003800 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003801 "v=0\r\n"
3802 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3803 "s=-\r\n"
3804 "t=0 0\r\n"
3805 "m=video 3457 RTP/SAVPF 120\r\n"
3806 "b=AS:2147483647\r\n"
3807 "foo=fail\r\n";
3808
3809 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3810}
deadbeef7bcdb692017-01-20 12:43:58 -08003811
deadbeefbc88c6b2017-08-02 11:26:34 -07003812// Similar to the above, except that negative values are illegal, not just
3813// error-prone as large values are.
3814// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3815TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3816 static const char kSdpWithNegativeBandwidth[] =
3817 "v=0\r\n"
3818 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3819 "s=-\r\n"
3820 "t=0 0\r\n"
3821 "m=video 3457 RTP/SAVPF 120\r\n"
3822 "b=AS:-1000\r\n";
3823
3824 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3825}
3826
deadbeef3e8016e2017-08-03 17:49:30 -07003827// An exception to the above rule: a value of -1 for b=AS should just be
3828// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3829// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3830// limit", but this is now what ommitting the attribute entirely will do, so
3831// ignoring it will have the intended effect.
3832TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3833 static const char kSdpWithBandwidthOfNegativeOne[] =
3834 "v=0\r\n"
3835 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3836 "s=-\r\n"
3837 "t=0 0\r\n"
3838 "m=video 3457 RTP/SAVPF 120\r\n"
3839 "b=AS:-1\r\n";
3840
Steve Antona3a92c22017-12-07 10:27:41 -08003841 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003842 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003843 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003844 GetFirstVideoContentDescription(jdesc_output.description());
3845 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003846 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3847}
3848
deadbeef7bcdb692017-01-20 12:43:58 -08003849// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3850// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3851// Regression test for:
3852// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3853TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3854 // Important piece is "ufrag foo pwd bar".
3855 static const char kSdpWithIceCredentialsInCandidateString[] =
3856 "v=0\r\n"
3857 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3858 "s=-\r\n"
3859 "t=0 0\r\n"
3860 "m=audio 9 RTP/SAVPF 111\r\n"
3861 "c=IN IP4 0.0.0.0\r\n"
3862 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3863 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3864 "a=rtpmap:111 opus/48000/2\r\n"
3865 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3866 "generation 2 ufrag foo pwd bar\r\n";
3867
Steve Antona3a92c22017-12-07 10:27:41 -08003868 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003869 EXPECT_TRUE(
3870 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3871 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3872 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003873 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003874 cricket::Candidate c = candidates->at(0)->candidate();
3875 EXPECT_EQ("ufrag_voice", c.username());
3876 EXPECT_EQ("pwd_voice", c.password());
3877}
deadbeef90f1e1e2017-02-10 12:35:05 -08003878
Johannes Kron211856b2018-09-06 12:12:28 +02003879// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3880// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3881// Regression test for:
3882// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3883TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3884 static const char kSdpWithFooIceCredentials[] =
3885 "v=0\r\n"
3886 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3887 "s=-\r\n"
3888 "t=0 0\r\n"
3889 "m=audio 9 RTP/SAVPF 111\r\n"
3890 "c=IN IP4 0.0.0.0\r\n"
3891 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3892 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3893 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3894 "a=rtpmap:111 opus/48000/2\r\n"
3895 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3896 "generation 2\r\n";
3897
3898 JsepSessionDescription jdesc_output(kDummyType);
3899 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3900 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3901 ASSERT_NE(nullptr, candidates);
3902 ASSERT_EQ(1U, candidates->count());
3903 cricket::Candidate c = candidates->at(0)->candidate();
3904 EXPECT_EQ("ufrag_voice", c.username());
3905 EXPECT_EQ("pwd_voice", c.password());
3906}
3907
deadbeef90f1e1e2017-02-10 12:35:05 -08003908// Test that SDP with an invalid port number in "a=candidate" lines is
3909// rejected, without crashing.
3910// Regression test for:
3911// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3912TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3913 static const char kSdpWithInvalidCandidatePort[] =
3914 "v=0\r\n"
3915 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3916 "s=-\r\n"
3917 "t=0 0\r\n"
3918 "m=audio 9 RTP/SAVPF 111\r\n"
3919 "c=IN IP4 0.0.0.0\r\n"
3920 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3921 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3922 "a=rtpmap:111 opus/48000/2\r\n"
3923 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3924 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3925
Steve Antona3a92c22017-12-07 10:27:41 -08003926 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003927 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3928}
deadbeefa4549d62017-02-10 17:26:22 -08003929
3930// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3931// Regression test for:
3932// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3933TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3934 static const char kSdpWithMissingTrackId[] =
3935 "v=0\r\n"
3936 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3937 "s=-\r\n"
3938 "t=0 0\r\n"
3939 "m=audio 9 RTP/SAVPF 111\r\n"
3940 "c=IN IP4 0.0.0.0\r\n"
3941 "a=rtpmap:111 opus/48000/2\r\n"
3942 "a=msid:stream_id \r\n";
3943
Steve Antona3a92c22017-12-07 10:27:41 -08003944 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003945 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3946}
3947
3948TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3949 static const char kSdpWithMissingStreamId[] =
3950 "v=0\r\n"
3951 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3952 "s=-\r\n"
3953 "t=0 0\r\n"
3954 "m=audio 9 RTP/SAVPF 111\r\n"
3955 "c=IN IP4 0.0.0.0\r\n"
3956 "a=rtpmap:111 opus/48000/2\r\n"
3957 "a=msid: track_id\r\n";
3958
Steve Antona3a92c22017-12-07 10:27:41 -08003959 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003960 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3961}
zhihuang38989e52017-03-21 11:04:53 -07003962
3963// Tests that if both session-level address and media-level address exist, use
3964// the media-level address.
3965TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003966 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003967
3968 // Sesssion-level address.
3969 std::string sdp = kSdpFullString;
3970 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3971 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3972
3973 const auto& content1 = jsep_desc.description()->contents()[0];
3974 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003975 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003976 const auto& content2 = jsep_desc.description()->contents()[1];
3977 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003978 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003979}
3980
3981// Tests that the session-level connection address will be used if the media
3982// level-addresses are not specified.
3983TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003984 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003985
3986 // Sesssion-level address.
3987 std::string sdp = kSdpString;
3988 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3989 // Remove the media level addresses.
3990 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3991 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3992 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3993
3994 const auto& content1 = jsep_desc.description()->contents()[0];
3995 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003996 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003997 const auto& content2 = jsep_desc.description()->contents()[1];
3998 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003999 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004000}
4001
4002TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004003 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004004
4005 std::string sdp = kSdpString;
4006 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4007 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4008 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4009 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4010 &sdp);
4011 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4012 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4013 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4014 &sdp);
4015 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4016 const auto& content1 = jsep_desc.description()->contents()[0];
4017 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004018 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004019 const auto& content2 = jsep_desc.description()->contents()[1];
4020 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004021 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004022}
4023
Qingsi Wang56991422019-02-08 12:53:06 -08004024// Test that a c= line that contains a hostname connection address can be
4025// parsed.
4026TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4027 JsepSessionDescription jsep_desc(kDummyType);
4028 std::string sdp = kSdpString;
4029 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4030
4031 sdp = kSdpString;
4032 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4033 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4034 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4035
4036 ASSERT_NE(nullptr, jsep_desc.description());
4037 const auto& content1 = jsep_desc.description()->contents()[0];
4038 EXPECT_EQ("example.local:9",
4039 content1.media_description()->connection_address().ToString());
4040 const auto& content2 = jsep_desc.description()->contents()[1];
4041 EXPECT_EQ("example.local:9",
4042 content2.media_description()->connection_address().ToString());
4043}
4044
4045// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004046TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004047 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004048 std::string sdp = kSdpString;
4049 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4050
4051 // Unsupported multicast IPv4 address.
4052 sdp = kSdpFullString;
4053 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4054 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4055
4056 // Unsupported multicast IPv6 address.
4057 sdp = kSdpFullString;
4058 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4059 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4060
4061 // Mismatched address type.
4062 sdp = kSdpFullString;
4063 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4064 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4065
4066 sdp = kSdpFullString;
4067 Replace("c=IN IP4 74.125.224.39\r\n",
4068 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4069 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4070}
4071
4072TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004073 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004074 MakeDescriptionWithoutCandidates(&expected_jsep);
4075 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004076 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004077 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004078 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004079 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004080 auto audio_desc = jdesc.description()
4081 ->GetContentByName(kAudioContentName)
4082 ->media_description();
4083 auto video_desc = jdesc.description()
4084 ->GetContentByName(kVideoContentName)
4085 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004086 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4087 audio_desc->connection_address().ToString());
4088 EXPECT_EQ(video_desc_->connection_address().ToString(),
4089 video_desc->connection_address().ToString());
4090}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004091
Qingsi Wang56991422019-02-08 12:53:06 -08004092// Test that a media description that contains a hostname connection address can
4093// be correctly serialized.
4094TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4095 JsepSessionDescription expected_jsep(kDummyType);
4096 cricket::Candidate c;
4097 const rtc::SocketAddress hostname_addr("example.local", 1234);
4098 audio_desc_->set_connection_address(hostname_addr);
4099 video_desc_->set_connection_address(hostname_addr);
4100 ASSERT_TRUE(
4101 expected_jsep.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
4102 // Serialization.
4103 std::string message = webrtc::SdpSerialize(expected_jsep);
4104 // Deserialization.
4105 JsepSessionDescription jdesc(kDummyType);
4106 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4107 auto audio_desc = jdesc.description()
4108 ->GetContentByName(kAudioContentName)
4109 ->media_description();
4110 auto video_desc = jdesc.description()
4111 ->GetContentByName(kVideoContentName)
4112 ->media_description();
4113 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4114 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4115}
4116
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004117// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4118// used (i.e., a single space as the session name)." So we should accept that.
4119TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4120 JsepSessionDescription jsep_desc(kDummyType);
4121 std::string sdp = kSdpString;
4122 Replace("s=-\r\n", "s= \r\n", &sdp);
4123 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4124}
Amit Hilbucha2012042018-12-03 11:35:05 -08004125
4126// Simulcast malformed input test for invalid format.
4127TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4128 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4129 "a=simulcast:\r\n", "a=simulcast:");
4130}
4131
4132// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4133TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4134 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4135 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4136 "a=simulcast:");
4137}
4138
4139// Validates that deserialization uses the a=simulcast: attribute
4140TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004141 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4142 sdp += "a=rid:1 send\r\n";
4143 sdp += "a=rid:2 send\r\n";
4144 sdp += "a=rid:3 send\r\n";
4145 sdp += "a=rid:4 recv\r\n";
4146 sdp += "a=rid:5 recv\r\n";
4147 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004148 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4149 JsepSessionDescription output(kDummyType);
4150 SdpParseError error;
4151 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4152 const cricket::ContentInfos& contents = output.description()->contents();
4153 const cricket::MediaContentDescription* media =
4154 contents.back().media_description();
4155 EXPECT_TRUE(media->HasSimulcast());
4156 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4157 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004158 EXPECT_FALSE(media->streams().empty());
4159 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4160 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004161}
4162
4163// Validates that deserialization removes rids that do not appear in SDP
4164TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4165 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4166 sdp += "a=rid:1 send\r\n";
4167 sdp += "a=rid:3 send\r\n";
4168 sdp += "a=rid:4 recv\r\n";
4169 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4170 JsepSessionDescription output(kDummyType);
4171 SdpParseError error;
4172 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4173 const cricket::ContentInfos& contents = output.description()->contents();
4174 const cricket::MediaContentDescription* media =
4175 contents.back().media_description();
4176 EXPECT_TRUE(media->HasSimulcast());
4177 const SimulcastDescription& simulcast = media->simulcast_description();
4178 EXPECT_EQ(2ul, simulcast.send_layers().size());
4179 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4180
4181 std::vector<SimulcastLayer> all_send_layers =
4182 simulcast.send_layers().GetAllLayers();
4183 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004184 EXPECT_EQ(0,
4185 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4186 return layer.rid == "2";
4187 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004188
4189 std::vector<SimulcastLayer> all_receive_layers =
4190 simulcast.receive_layers().GetAllLayers();
4191 ASSERT_EQ(1ul, all_receive_layers.size());
4192 EXPECT_EQ("4", all_receive_layers[0].rid);
4193
4194 EXPECT_FALSE(media->streams().empty());
4195 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4196 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004197}
4198
4199// Validates that Simulcast removes rids that appear in both send and receive.
4200TEST_F(WebRtcSdpTest,
4201 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4202 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4203 sdp += "a=rid:1 send\r\n";
4204 sdp += "a=rid:2 send\r\n";
4205 sdp += "a=rid:3 send\r\n";
4206 sdp += "a=rid:4 recv\r\n";
4207 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4208 JsepSessionDescription output(kDummyType);
4209 SdpParseError error;
4210 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4211 const cricket::ContentInfos& contents = output.description()->contents();
4212 const cricket::MediaContentDescription* media =
4213 contents.back().media_description();
4214 EXPECT_TRUE(media->HasSimulcast());
4215 const SimulcastDescription& simulcast = media->simulcast_description();
4216 EXPECT_EQ(2ul, simulcast.send_layers().size());
4217 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4218 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4219 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4220
4221 EXPECT_FALSE(media->streams().empty());
4222 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4223 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004224}
4225
4226// Ignores empty rid line.
4227TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4228 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4229 sdp += "a=rid:1 send\r\n";
4230 sdp += "a=rid:2 send\r\n";
4231 sdp += "a=rid\r\n"; // Should ignore this line.
4232 sdp += "a=rid:\r\n"; // Should ignore this line.
4233 sdp += "a=simulcast:send 1;2\r\n";
4234 JsepSessionDescription output(kDummyType);
4235 SdpParseError error;
4236 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4237 const cricket::ContentInfos& contents = output.description()->contents();
4238 const cricket::MediaContentDescription* media =
4239 contents.back().media_description();
4240 EXPECT_TRUE(media->HasSimulcast());
4241 const SimulcastDescription& simulcast = media->simulcast_description();
4242 EXPECT_TRUE(simulcast.receive_layers().empty());
4243 EXPECT_EQ(2ul, simulcast.send_layers().size());
4244 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4245
4246 EXPECT_FALSE(media->streams().empty());
4247 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4248 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004249}
4250
4251// Ignores malformed rid lines.
4252TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4253 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4254 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4255 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4256 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4257 sdp += "a=rid:4\r\n"; // Should ignore this line.
4258 sdp += "a=rid:5 send\r\n";
4259 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4260 JsepSessionDescription output(kDummyType);
4261 SdpParseError error;
4262 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4263 const cricket::ContentInfos& contents = output.description()->contents();
4264 const cricket::MediaContentDescription* media =
4265 contents.back().media_description();
4266 EXPECT_TRUE(media->HasSimulcast());
4267 const SimulcastDescription& simulcast = media->simulcast_description();
4268 EXPECT_TRUE(simulcast.receive_layers().empty());
4269 EXPECT_EQ(1ul, simulcast.send_layers().size());
4270 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4271
4272 EXPECT_FALSE(media->streams().empty());
4273 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4274 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004275}
4276
4277// Removes RIDs that specify a different format than the m= section.
4278TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4279 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4280 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4281 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4282 sdp += "a=simulcast:send 1;2\r\n";
4283 JsepSessionDescription output(kDummyType);
4284 SdpParseError error;
4285 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4286 const cricket::ContentInfos& contents = output.description()->contents();
4287 const cricket::MediaContentDescription* media =
4288 contents.back().media_description();
4289 EXPECT_TRUE(media->HasSimulcast());
4290 const SimulcastDescription& simulcast = media->simulcast_description();
4291 EXPECT_TRUE(simulcast.receive_layers().empty());
4292 EXPECT_EQ(1ul, simulcast.send_layers().size());
4293 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4294 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4295 EXPECT_EQ(1ul, media->streams().size());
4296 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4297 EXPECT_EQ(1ul, rids.size());
4298 EXPECT_EQ("1", rids[0].rid);
4299 EXPECT_EQ(1ul, rids[0].payload_types.size());
4300 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004301}
4302
4303// Ignores duplicate rid lines
4304TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4305 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4306 sdp += "a=rid:1 send\r\n";
4307 sdp += "a=rid:2 send\r\n";
4308 sdp += "a=rid:2 send\r\n";
4309 sdp += "a=rid:3 send\r\n";
4310 sdp += "a=rid:4 recv\r\n";
4311 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4312 JsepSessionDescription output(kDummyType);
4313 SdpParseError error;
4314 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4315 const cricket::ContentInfos& contents = output.description()->contents();
4316 const cricket::MediaContentDescription* media =
4317 contents.back().media_description();
4318 EXPECT_TRUE(media->HasSimulcast());
4319 const SimulcastDescription& simulcast = media->simulcast_description();
4320 EXPECT_EQ(2ul, simulcast.send_layers().size());
4321 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4322 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4323 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4324
4325 EXPECT_FALSE(media->streams().empty());
4326 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4327 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004328}
4329
4330// Simulcast serialization integration test.
4331// This test will serialize and deserialize the description and compare.
4332// More detailed tests for parsing simulcast can be found in
4333// unit tests for SdpSerializer.
4334TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004335 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004336 auto description = jdesc_.description();
4337 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004338 ASSERT_EQ(media->streams().size(), 1ul);
4339 StreamParams& send_stream = media->mutable_streams()[0];
4340 std::vector<RidDescription> send_rids;
4341 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4342 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4343 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4344 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4345 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004346
Amit Hilbucha2012042018-12-03 11:35:05 -08004347 SimulcastDescription& simulcast = media->simulcast_description();
4348 simulcast.send_layers().AddLayerWithAlternatives(
4349 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4350 simulcast.send_layers().AddLayerWithAlternatives(
4351 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4352
Amit Hilbucha2012042018-12-03 11:35:05 -08004353 TestSerialize(jdesc_);
4354}
Steve Anton06817cd2018-12-18 15:55:30 -08004355
4356// Test that the content name is empty if the media section does not have an
4357// a=mid line.
4358TEST_F(WebRtcSdpTest, ParseNoMid) {
4359 std::string sdp = kSdpString;
4360 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4361 Replace("a=mid:video_content_name\r\n", "", &sdp);
4362
4363 JsepSessionDescription output(kDummyType);
4364 SdpParseError error;
4365 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4366
4367 EXPECT_THAT(output.description()->contents(),
4368 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4369 Field("name", &cricket::ContentInfo::name, "")));
4370}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004371
4372// Test that the media transport name and base64-decoded setting is parsed from
4373// an a=x-mt line.
4374TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4375 JsepSessionDescription output(kDummyType);
4376 std::string sdp = kSdpSessionString;
4377 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4378 SdpParseError error;
4379
4380 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4381 << error.description;
4382 const auto& settings = output.description()->MediaTransportSettings();
4383 ASSERT_EQ(1u, settings.size());
4384 EXPECT_EQ("rtp", settings[0].transport_name);
4385 EXPECT_EQ("test64", settings[0].transport_setting);
4386}
4387
4388// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4389TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4390 JsepSessionDescription output(kDummyType);
4391 std::string sdp = kSdpSessionString;
4392 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4393 SdpParseError error;
4394
4395 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4396}
4397
4398// Test that multiple a=x-mt lines are parsed in the order of preference (the
4399// order of the lines in the SDP).
4400TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4401 JsepSessionDescription output(kDummyType);
4402 std::string sdp = kSdpSessionString;
4403 sdp +=
4404 "a=x-mt:rtp:dGVzdDY0\r\n"
4405 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4406 SdpParseError error;
4407
4408 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4409 << error.description;
4410 const auto& settings = output.description()->MediaTransportSettings();
4411 ASSERT_EQ(2u, settings.size());
4412 EXPECT_EQ("rtp", settings[0].transport_name);
4413 EXPECT_EQ("test64", settings[0].transport_setting);
4414 EXPECT_EQ("generic", settings[1].transport_name);
4415 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4416}
4417
4418// Test that only the first a=x-mt line associated with a transport name is
4419// parsed and the rest ignored.
4420TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4421 JsepSessionDescription output(kDummyType);
4422 std::string sdp = kSdpSessionString;
4423 sdp +=
4424 "a=x-mt:rtp:dGVzdDY0\r\n"
4425 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4426 SdpParseError error;
4427
4428 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4429 // but ignore the repeated transport.
4430 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4431 const auto& settings = output.description()->MediaTransportSettings();
4432 EXPECT_EQ("test64", settings[0].transport_setting);
4433}
4434
4435// Test that an a=x-mt line fails to parse if it is missing a setting.
4436TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4437 JsepSessionDescription output(kDummyType);
4438 std::string sdp = kSdpSessionString;
4439 sdp += "a=x-mt:rtp\r\n";
4440 SdpParseError error;
4441
4442 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4443}
4444
4445// Test that an a=x-mt line fails to parse if its missing a name and setting.
4446TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4447 JsepSessionDescription output(kDummyType);
4448 std::string sdp = kSdpSessionString;
4449 sdp += "a=x-mt\r\n";
4450 SdpParseError error;
4451
4452 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4453}
4454
4455TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4456 JsepSessionDescription output(kDummyType);
4457 std::string sdp = kSdpSessionString;
4458 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4459 SdpParseError error;
4460
4461 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4462 << error.description;
4463 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4464}
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004465
4466TEST_F(WebRtcSdpTest, SerializeMediaTransportSettings) {
4467 cricket::SessionDescription* description = new cricket::SessionDescription();
4468
4469 JsepSessionDescription output(SdpType::kOffer);
4470 // JsepSessionDescription takes ownership of the description.
4471 output.Initialize(description, "session_id", "session_version");
4472 output.description()->AddMediaTransportSetting("foo", "bar");
4473 std::string serialized_out;
4474 output.ToString(&serialized_out);
4475 ASSERT_THAT(serialized_out, ::testing::HasSubstr("\r\na=x-mt:foo:YmFy\r\n"));
4476}
4477
4478TEST_F(WebRtcSdpTest, SerializeMediaTransportSettingsTestCopy) {
4479 cricket::SessionDescription description;
4480 description.AddMediaTransportSetting("name", "setting");
4481 std::unique_ptr<cricket::SessionDescription> copy =
4482 absl::WrapUnique(description.Copy());
4483 ASSERT_EQ(1u, copy->MediaTransportSettings().size());
4484 EXPECT_EQ("name", copy->MediaTransportSettings()[0].transport_name);
4485 EXPECT_EQ("setting", copy->MediaTransportSettings()[0].transport_setting);
4486}