blob: 117269a80ae7874b4330b324610a05964298b204 [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"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080021#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/crypto_params.h"
24#include "api/jsep_session_description.h"
25#include "api/media_types.h"
26#include "api/rtp_parameters.h"
27#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "media/base/media_constants.h"
30#include "media/base/stream_params.h"
31#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020032#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "p2p/base/transport_description.h"
34#include "p2p/base/transport_info.h"
35#include "pc/media_session.h"
36#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "rtc_base/message_digest.h"
39#include "rtc_base/socket_address.h"
40#include "rtc_base/ssl_fingerprint.h"
41#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080042#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010043#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020044
ossu7bb87ee2017-01-23 04:56:25 -080045#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080046#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080047#endif
Steve Anton10542f22019-01-11 09:11:00 -080048#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50using cricket::AudioCodec;
51using cricket::AudioContentDescription;
52using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080053using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054using cricket::ContentInfo;
55using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::DataCodec;
57using cricket::DataContentDescription;
58using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
59using cricket::ICE_CANDIDATE_COMPONENT_RTP;
60using cricket::kFecSsrcGroupSemantics;
61using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080062using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080063using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080064using cricket::RidDescription;
65using cricket::RidDirection;
Steve Anton06817cd2018-12-18 15:55:30 -080066using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080067using cricket::SimulcastDescription;
68using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using cricket::StreamParams;
70using cricket::STUN_PORT_TYPE;
71using cricket::TransportDescription;
72using cricket::TransportInfo;
73using cricket::VideoCodec;
74using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080075using ::testing::ElementsAre;
76using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::IceCandidateCollection;
78using webrtc::IceCandidateInterface;
79using webrtc::JsepIceCandidate;
80using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070081using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080082using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080084using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::SessionDescriptionInterface;
86
87typedef std::vector<AudioCodec> AudioCodecs;
88typedef std::vector<Candidate> Candidates;
89
Peter Boström0c4e06b2015-10-07 12:23:21 +020090static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080091static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020093static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080094static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080096static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020098static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kCandidateFoundation1[] = "a0+B/1";
100static const char kCandidateFoundation2[] = "a0+B/2";
101static const char kCandidateFoundation3[] = "a0+B/3";
102static const char kCandidateFoundation4[] = "a0+B/4";
103static const char kAttributeCryptoVoice[] =
104 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
105 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
106 "dummy_session_params\r\n";
107static const char kAttributeCryptoVideo[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
109 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200110static const char kFingerprint[] =
111 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 "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 +0200113static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114static const int kExtmapId = 1;
115static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
116static const char kExtmap[] =
117 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
118static const char kExtmapWithDirectionAndAttribute[] =
119 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700120static const char kExtmapWithDirectionAndAttributeEncrypted[] =
121 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
122 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
Peter Boström0c4e06b2015-10-07 12:23:21 +0200124static const uint8_t kIdentityDigest[] = {
125 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
126 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
lally@webrtc.org34807282015-02-24 20:19:39 +0000128static const char kDtlsSctp[] = "DTLS/SCTP";
129static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
130static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000131
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132struct CodecParams {
133 int max_ptime;
134 int ptime;
135 int min_ptime;
136 int sprop_stereo;
137 int stereo;
138 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000139 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140};
141
deadbeef9d3584c2016-02-16 17:54:10 -0800142// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
143// instead of "a=crypto", and have an explicit test for adding "a=crypto".
144// Currently it's the other way around.
145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146// Reference sdp string
147static const char kSdpFullString[] =
148 "v=0\r\n"
149 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
150 "s=-\r\n"
151 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800152 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
154 "c=IN IP4 74.125.127.126\r\n"
155 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
156 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
165 "raddr 192.168.1.5 rport 2346 "
166 "generation 2\r\n"
167 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
168 "raddr 192.168.1.5 rport 2348 "
169 "generation 2\r\n"
170 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
171 "a=mid:audio_content_name\r\n"
172 "a=sendrecv\r\n"
173 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800174 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
176 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
177 "dummy_session_params\r\n"
178 "a=rtpmap:111 opus/48000/2\r\n"
179 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000180 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "a=ssrc:1 cname:stream_1_cname\r\n"
182 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
183 "a=ssrc:1 mslabel:local_stream_1\r\n"
184 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 "m=video 3457 RTP/SAVPF 120\r\n"
186 "c=IN IP4 74.125.224.39\r\n"
187 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
188 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
189 "generation 2\r\n"
190 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
191 "generation 2\r\n"
192 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
197 "generation 2\r\n"
198 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
199 "generation 2\r\n"
200 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
201 "a=mid:video_content_name\r\n"
202 "a=sendrecv\r\n"
203 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
204 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
205 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800206 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 "a=ssrc:2 cname:stream_1_cname\r\n"
208 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
209 "a=ssrc:2 mslabel:local_stream_1\r\n"
210 "a=ssrc:2 label:video_track_id_1\r\n"
211 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800212 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800214 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215
216// SDP reference string without the candidates.
217static const char kSdpString[] =
218 "v=0\r\n"
219 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
220 "s=-\r\n"
221 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800222 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000223 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000224 "c=IN IP4 0.0.0.0\r\n"
225 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
227 "a=mid:audio_content_name\r\n"
228 "a=sendrecv\r\n"
229 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800230 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
232 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
233 "dummy_session_params\r\n"
234 "a=rtpmap:111 opus/48000/2\r\n"
235 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000236 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:1 cname:stream_1_cname\r\n"
238 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
239 "a=ssrc:1 mslabel:local_stream_1\r\n"
240 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
245 "a=mid:video_content_name\r\n"
246 "a=sendrecv\r\n"
247 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
248 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
249 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800250 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 "a=ssrc:2 cname:stream_1_cname\r\n"
252 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
253 "a=ssrc:2 mslabel:local_stream_1\r\n"
254 "a=ssrc:2 label:video_track_id_1\r\n"
255 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800256 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800258 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259
260static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000261 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000262 "c=IN IP4 0.0.0.0\r\n"
263 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 "a=ice-ufrag:ufrag_data\r\n"
265 "a=ice-pwd:pwd_data\r\n"
266 "a=mid:data_content_name\r\n"
267 "a=sendrecv\r\n"
268 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
269 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
270 "a=rtpmap:101 google-data/90000\r\n"
271 "a=ssrc:10 cname:data_channel_cname\r\n"
272 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
273 "a=ssrc:10 mslabel:data_channel\r\n"
274 "a=ssrc:10 label:data_channeld0\r\n";
275
276static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000277 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000278 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000282 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000284// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000285static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000286 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
287 "a=max-message-size=100000\r\n"
288 "a=sctp-port 5000\r\n"
289 "c=IN IP4 0.0.0.0\r\n"
290 "a=ice-ufrag:ufrag_data\r\n"
291 "a=ice-pwd:pwd_data\r\n"
292 "a=mid:data_content_name\r\n";
293
lally69f57602015-10-08 10:15:04 -0700294static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
295 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
296 "a=max-message-size=100000\r\n"
297 "a=sctp-port:5000\r\n"
298 "c=IN IP4 0.0.0.0\r\n"
299 "a=ice-ufrag:ufrag_data\r\n"
300 "a=ice-pwd:pwd_data\r\n"
301 "a=mid:data_content_name\r\n";
302
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303static const char kSdpSctpDataChannelWithCandidatesString[] =
304 "m=application 2345 DTLS/SCTP 5000\r\n"
305 "c=IN IP4 74.125.127.126\r\n"
306 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
307 "generation 2\r\n"
308 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
309 "generation 2\r\n"
310 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
311 "raddr 192.168.1.5 rport 2346 "
312 "generation 2\r\n"
313 "a=ice-ufrag:ufrag_data\r\n"
314 "a=ice-pwd:pwd_data\r\n"
315 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000316 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000318static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000319 "v=0\r\n"
320 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
321 "s=-\r\n"
322 "t=0 0\r\n"
323 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000324 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000325 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000326 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000327 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000328 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000329 "a=x-google-flag:conference\r\n";
330
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000331static const char kSdpSessionString[] =
332 "v=0\r\n"
333 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
334 "s=-\r\n"
335 "t=0 0\r\n"
336 "a=msid-semantic: WMS local_stream\r\n";
337
338static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000339 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000340 "c=IN IP4 0.0.0.0\r\n"
341 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000342 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
343 "a=mid:audio_content_name\r\n"
344 "a=sendrecv\r\n"
345 "a=rtpmap:111 opus/48000/2\r\n"
346 "a=ssrc:1 cname:stream_1_cname\r\n"
347 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
348 "a=ssrc:1 mslabel:local_stream\r\n"
349 "a=ssrc:1 label:audio_track_id_1\r\n";
350
351static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000352 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000353 "c=IN IP4 0.0.0.0\r\n"
354 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000355 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
356 "a=mid:video_content_name\r\n"
357 "a=sendrecv\r\n"
358 "a=rtpmap:120 VP8/90000\r\n"
359 "a=ssrc:2 cname:stream_1_cname\r\n"
360 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
361 "a=ssrc:2 mslabel:local_stream\r\n"
362 "a=ssrc:2 label:video_track_id_1\r\n";
363
deadbeef25ed4352016-12-12 18:37:36 -0800364// Reference sdp string using bundle-only.
365static const char kBundleOnlySdpFullString[] =
366 "v=0\r\n"
367 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
368 "s=-\r\n"
369 "t=0 0\r\n"
370 "a=group:BUNDLE audio_content_name video_content_name\r\n"
371 "a=msid-semantic: WMS local_stream_1\r\n"
372 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
373 "c=IN IP4 74.125.127.126\r\n"
374 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
375 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
376 "generation 2\r\n"
377 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
378 "generation 2\r\n"
379 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
384 "raddr 192.168.1.5 rport 2346 "
385 "generation 2\r\n"
386 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
387 "raddr 192.168.1.5 rport 2348 "
388 "generation 2\r\n"
389 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
390 "a=mid:audio_content_name\r\n"
391 "a=sendrecv\r\n"
392 "a=rtcp-mux\r\n"
393 "a=rtcp-rsize\r\n"
394 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
395 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
396 "dummy_session_params\r\n"
397 "a=rtpmap:111 opus/48000/2\r\n"
398 "a=rtpmap:103 ISAC/16000\r\n"
399 "a=rtpmap:104 ISAC/32000\r\n"
400 "a=ssrc:1 cname:stream_1_cname\r\n"
401 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
402 "a=ssrc:1 mslabel:local_stream_1\r\n"
403 "a=ssrc:1 label:audio_track_id_1\r\n"
404 "m=video 0 RTP/SAVPF 120\r\n"
405 "c=IN IP4 0.0.0.0\r\n"
406 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
407 "a=bundle-only\r\n"
408 "a=mid:video_content_name\r\n"
409 "a=sendrecv\r\n"
410 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
411 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
412 "a=rtpmap:120 VP8/90000\r\n"
413 "a=ssrc-group:FEC 2 3\r\n"
414 "a=ssrc:2 cname:stream_1_cname\r\n"
415 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
416 "a=ssrc:2 mslabel:local_stream_1\r\n"
417 "a=ssrc:2 label:video_track_id_1\r\n"
418 "a=ssrc:3 cname:stream_1_cname\r\n"
419 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
420 "a=ssrc:3 mslabel:local_stream_1\r\n"
421 "a=ssrc:3 label:video_track_id_1\r\n";
422
deadbeef9d3584c2016-02-16 17:54:10 -0800423// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
424// tracks.
425static const char kPlanBSdpFullString[] =
426 "v=0\r\n"
427 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
428 "s=-\r\n"
429 "t=0 0\r\n"
430 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
431 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
432 "c=IN IP4 74.125.127.126\r\n"
433 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
434 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
437 "generation 2\r\n"
438 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
439 "generation 2\r\n"
440 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
443 "raddr 192.168.1.5 rport 2346 "
444 "generation 2\r\n"
445 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
446 "raddr 192.168.1.5 rport 2348 "
447 "generation 2\r\n"
448 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
449 "a=mid:audio_content_name\r\n"
450 "a=sendrecv\r\n"
451 "a=rtcp-mux\r\n"
452 "a=rtcp-rsize\r\n"
453 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
454 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
455 "dummy_session_params\r\n"
456 "a=rtpmap:111 opus/48000/2\r\n"
457 "a=rtpmap:103 ISAC/16000\r\n"
458 "a=rtpmap:104 ISAC/32000\r\n"
459 "a=ssrc:1 cname:stream_1_cname\r\n"
460 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
461 "a=ssrc:1 mslabel:local_stream_1\r\n"
462 "a=ssrc:1 label:audio_track_id_1\r\n"
463 "a=ssrc:4 cname:stream_2_cname\r\n"
464 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
465 "a=ssrc:4 mslabel:local_stream_2\r\n"
466 "a=ssrc:4 label:audio_track_id_2\r\n"
467 "m=video 3457 RTP/SAVPF 120\r\n"
468 "c=IN IP4 74.125.224.39\r\n"
469 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
470 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
471 "generation 2\r\n"
472 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
473 "generation 2\r\n"
474 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
475 "generation 2\r\n"
476 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
479 "generation 2\r\n"
480 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
481 "generation 2\r\n"
482 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
483 "a=mid:video_content_name\r\n"
484 "a=sendrecv\r\n"
485 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
486 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
487 "a=rtpmap:120 VP8/90000\r\n"
488 "a=ssrc-group:FEC 2 3\r\n"
489 "a=ssrc:2 cname:stream_1_cname\r\n"
490 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
491 "a=ssrc:2 mslabel:local_stream_1\r\n"
492 "a=ssrc:2 label:video_track_id_1\r\n"
493 "a=ssrc:3 cname:stream_1_cname\r\n"
494 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
495 "a=ssrc:3 mslabel:local_stream_1\r\n"
496 "a=ssrc:3 label:video_track_id_1\r\n"
497 "a=ssrc:5 cname:stream_2_cname\r\n"
498 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
499 "a=ssrc:5 mslabel:local_stream_2\r\n"
500 "a=ssrc:5 label:video_track_id_2\r\n"
501 "a=ssrc:6 cname:stream_2_cname\r\n"
502 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
503 "a=ssrc:6 mslabel:local_stream_2\r\n"
504 "a=ssrc:6 label:video_track_id_3\r\n";
505
506// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
507// tracks.
508static const char kUnifiedPlanSdpFullString[] =
509 "v=0\r\n"
510 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
511 "s=-\r\n"
512 "t=0 0\r\n"
513 "a=msid-semantic: WMS local_stream_1\r\n"
514 // Audio track 1, stream 1 (with candidates).
515 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
516 "c=IN IP4 74.125.127.126\r\n"
517 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
518 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
523 "generation 2\r\n"
524 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
527 "raddr 192.168.1.5 rport 2346 "
528 "generation 2\r\n"
529 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
530 "raddr 192.168.1.5 rport 2348 "
531 "generation 2\r\n"
532 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
533 "a=mid:audio_content_name\r\n"
534 "a=msid:local_stream_1 audio_track_id_1\r\n"
535 "a=sendrecv\r\n"
536 "a=rtcp-mux\r\n"
537 "a=rtcp-rsize\r\n"
538 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
539 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
540 "dummy_session_params\r\n"
541 "a=rtpmap:111 opus/48000/2\r\n"
542 "a=rtpmap:103 ISAC/16000\r\n"
543 "a=rtpmap:104 ISAC/32000\r\n"
544 "a=ssrc:1 cname:stream_1_cname\r\n"
545 // Video track 1, stream 1 (with candidates).
546 "m=video 3457 RTP/SAVPF 120\r\n"
547 "c=IN IP4 74.125.224.39\r\n"
548 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
549 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
554 "generation 2\r\n"
555 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
558 "generation 2\r\n"
559 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
560 "generation 2\r\n"
561 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
562 "a=mid:video_content_name\r\n"
563 "a=msid:local_stream_1 video_track_id_1\r\n"
564 "a=sendrecv\r\n"
565 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
566 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
567 "a=rtpmap:120 VP8/90000\r\n"
568 "a=ssrc-group:FEC 2 3\r\n"
569 "a=ssrc:2 cname:stream_1_cname\r\n"
570 "a=ssrc:3 cname:stream_1_cname\r\n"
571 // Audio track 2, stream 2.
572 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
573 "c=IN IP4 0.0.0.0\r\n"
574 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
575 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
576 "a=mid:audio_content_name_2\r\n"
577 "a=msid:local_stream_2 audio_track_id_2\r\n"
578 "a=sendrecv\r\n"
579 "a=rtcp-mux\r\n"
580 "a=rtcp-rsize\r\n"
581 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
582 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
583 "dummy_session_params\r\n"
584 "a=rtpmap:111 opus/48000/2\r\n"
585 "a=rtpmap:103 ISAC/16000\r\n"
586 "a=rtpmap:104 ISAC/32000\r\n"
587 "a=ssrc:4 cname:stream_2_cname\r\n"
588 // Video track 2, stream 2.
589 "m=video 9 RTP/SAVPF 120\r\n"
590 "c=IN IP4 0.0.0.0\r\n"
591 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
592 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
593 "a=mid:video_content_name_2\r\n"
594 "a=msid:local_stream_2 video_track_id_2\r\n"
595 "a=sendrecv\r\n"
596 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
597 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
598 "a=rtpmap:120 VP8/90000\r\n"
599 "a=ssrc:5 cname:stream_2_cname\r\n"
600 // Video track 3, stream 2.
601 "m=video 9 RTP/SAVPF 120\r\n"
602 "c=IN IP4 0.0.0.0\r\n"
603 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
604 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
605 "a=mid:video_content_name_3\r\n"
606 "a=msid:local_stream_2 video_track_id_3\r\n"
607 "a=sendrecv\r\n"
608 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
609 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
610 "a=rtpmap:120 VP8/90000\r\n"
611 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612
Seth Hampson5b4f0752018-04-02 16:31:36 -0700613// Unified Plan SDP reference string:
614// - audio track 1 has 1 a=msid lines
615// - audio track 2 has 2 a=msid lines
616// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
617// there are 0 media stream ids.
618// This Unified Plan SDP represents a SDP that signals the msid using both
619// a=msid and a=ssrc msid semantics.
620static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
621 "v=0\r\n"
622 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
623 "s=-\r\n"
624 "t=0 0\r\n"
625 "a=msid-semantic: WMS local_stream_1\r\n"
626 // Audio track 1, with 1 stream id.
627 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
628 "c=IN IP4 74.125.127.126\r\n"
629 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
630 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
631 "generation 2\r\n"
632 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
633 "generation 2\r\n"
634 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
635 "generation 2\r\n"
636 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
639 "raddr 192.168.1.5 rport 2346 "
640 "generation 2\r\n"
641 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
642 "raddr 192.168.1.5 rport 2348 "
643 "generation 2\r\n"
644 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
645 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700646 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700647 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700648 "a=rtcp-mux\r\n"
649 "a=rtcp-rsize\r\n"
650 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
651 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
652 "dummy_session_params\r\n"
653 "a=rtpmap:111 opus/48000/2\r\n"
654 "a=rtpmap:103 ISAC/16000\r\n"
655 "a=rtpmap:104 ISAC/32000\r\n"
656 "a=ssrc:1 cname:stream_1_cname\r\n"
657 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
658 "a=ssrc:1 mslabel:local_stream_1\r\n"
659 "a=ssrc:1 label:audio_track_id_1\r\n"
660 // Audio track 2, with two stream ids.
661 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
662 "c=IN IP4 0.0.0.0\r\n"
663 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
664 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
665 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700666 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700667 "a=msid:local_stream_1 audio_track_id_2\r\n"
668 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700669 "a=rtcp-mux\r\n"
670 "a=rtcp-rsize\r\n"
671 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
672 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
673 "dummy_session_params\r\n"
674 "a=rtpmap:111 opus/48000/2\r\n"
675 "a=rtpmap:103 ISAC/16000\r\n"
676 "a=rtpmap:104 ISAC/32000\r\n"
677 "a=ssrc:4 cname:stream_1_cname\r\n"
678 // The support for Plan B msid signaling only includes the
679 // first media stream id "local_stream_1."
680 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
681 "a=ssrc:4 mslabel:local_stream_1\r\n"
682 "a=ssrc:4 label:audio_track_id_2\r\n"
683 // Audio track 3, with no stream ids.
684 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
685 "c=IN IP4 0.0.0.0\r\n"
686 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
687 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
688 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700689 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700690 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700691 "a=rtcp-mux\r\n"
692 "a=rtcp-rsize\r\n"
693 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
694 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
695 "dummy_session_params\r\n"
696 "a=rtpmap:111 opus/48000/2\r\n"
697 "a=rtpmap:103 ISAC/16000\r\n"
698 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700699 "a=ssrc:7 cname:stream_2_cname\r\n"
700 "a=ssrc:7 msid:- audio_track_id_3\r\n"
701 "a=ssrc:7 mslabel:-\r\n"
702 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700703
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800704// SDP string for unified plan without SSRCs
705static const char kUnifiedPlanSdpFullStringNoSsrc[] =
706 "v=0\r\n"
707 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
708 "s=-\r\n"
709 "t=0 0\r\n"
710 "a=msid-semantic: WMS local_stream_1\r\n"
711 // Audio track 1, stream 1 (with candidates).
712 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
713 "c=IN IP4 74.125.127.126\r\n"
714 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
715 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
716 "generation 2\r\n"
717 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
718 "generation 2\r\n"
719 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
720 "generation 2\r\n"
721 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
724 "raddr 192.168.1.5 rport 2346 "
725 "generation 2\r\n"
726 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
727 "raddr 192.168.1.5 rport 2348 "
728 "generation 2\r\n"
729 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
730 "a=mid:audio_content_name\r\n"
731 "a=msid:local_stream_1 audio_track_id_1\r\n"
732 "a=sendrecv\r\n"
733 "a=rtcp-mux\r\n"
734 "a=rtcp-rsize\r\n"
735 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
736 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
737 "dummy_session_params\r\n"
738 "a=rtpmap:111 opus/48000/2\r\n"
739 "a=rtpmap:103 ISAC/16000\r\n"
740 "a=rtpmap:104 ISAC/32000\r\n"
741 // Video track 1, stream 1 (with candidates).
742 "m=video 3457 RTP/SAVPF 120\r\n"
743 "c=IN IP4 74.125.224.39\r\n"
744 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
745 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
746 "generation 2\r\n"
747 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
748 "generation 2\r\n"
749 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
750 "generation 2\r\n"
751 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
754 "generation 2\r\n"
755 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
756 "generation 2\r\n"
757 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
758 "a=mid:video_content_name\r\n"
759 "a=msid:local_stream_1 video_track_id_1\r\n"
760 "a=sendrecv\r\n"
761 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
762 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
763 "a=rtpmap:120 VP8/90000\r\n"
764 // Audio track 2, stream 2.
765 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
766 "c=IN IP4 0.0.0.0\r\n"
767 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
768 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
769 "a=mid:audio_content_name_2\r\n"
770 "a=msid:local_stream_2 audio_track_id_2\r\n"
771 "a=sendrecv\r\n"
772 "a=rtcp-mux\r\n"
773 "a=rtcp-rsize\r\n"
774 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
775 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
776 "dummy_session_params\r\n"
777 "a=rtpmap:111 opus/48000/2\r\n"
778 "a=rtpmap:103 ISAC/16000\r\n"
779 "a=rtpmap:104 ISAC/32000\r\n"
780 // Video track 2, stream 2.
781 "m=video 9 RTP/SAVPF 120\r\n"
782 "c=IN IP4 0.0.0.0\r\n"
783 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
784 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
785 "a=mid:video_content_name_2\r\n"
786 "a=msid:local_stream_2 video_track_id_2\r\n"
787 "a=sendrecv\r\n"
788 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
789 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
790 "a=rtpmap:120 VP8/90000\r\n"
791 // Video track 3, stream 2.
792 "m=video 9 RTP/SAVPF 120\r\n"
793 "c=IN IP4 0.0.0.0\r\n"
794 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
795 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
796 "a=mid:video_content_name_3\r\n"
797 "a=msid:local_stream_2 video_track_id_3\r\n"
798 "a=sendrecv\r\n"
799 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
800 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
801 "a=rtpmap:120 VP8/90000\r\n";
802
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803// One candidate reference string as per W3c spec.
804// candidate:<blah> not a=candidate:<blah>CRLF
805static const char kRawCandidate[] =
806 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
807// One candidate reference string.
808static const char kSdpOneCandidate[] =
809 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
810 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000811
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000812static const char kSdpTcpActiveCandidate[] =
813 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
814 "tcptype active generation 2";
815static const char kSdpTcpPassiveCandidate[] =
816 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
817 "tcptype passive generation 2";
818static const char kSdpTcpSOCandidate[] =
819 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
820 "tcptype so generation 2";
821static const char kSdpTcpInvalidCandidate[] =
822 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
823 "tcptype invalid generation 2";
824
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000825// One candidate reference string with IPV6 address.
826static const char kRawIPV6Candidate[] =
827 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700828 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829
830// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800831static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800833 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834
Zach Steinb336c272018-08-09 01:16:13 -0700835static const char kRawHostnameCandidate[] =
836 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
837
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838// Session id and version
839static const char kSessionId[] = "18446744069414584320";
840static const char kSessionVersion[] = "18446462598732840960";
841
deadbeef9d3584c2016-02-16 17:54:10 -0800842// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843static const char kIceOption1[] = "iceoption1";
844static const char kIceOption2[] = "iceoption2";
845static const char kIceOption3[] = "iceoption3";
846
deadbeef9d3584c2016-02-16 17:54:10 -0800847// ICE ufrags/passwords.
848static const char kUfragVoice[] = "ufrag_voice";
849static const char kPwdVoice[] = "pwd_voice";
850static const char kUfragVideo[] = "ufrag_video";
851static const char kPwdVideo[] = "pwd_video";
852static const char kUfragData[] = "ufrag_data";
853static const char kPwdData[] = "pwd_data";
854
855// Extra ufrags/passwords for extra unified plan m= sections.
856static const char kUfragVoice2[] = "ufrag_voice_2";
857static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700858static const char kUfragVoice3[] = "ufrag_voice_3";
859static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800860static const char kUfragVideo2[] = "ufrag_video_2";
861static const char kPwdVideo2[] = "pwd_video_2";
862static const char kUfragVideo3[] = "ufrag_video_3";
863static const char kPwdVideo3[] = "pwd_video_3";
864
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865// Content name
866static const char kAudioContentName[] = "audio_content_name";
867static const char kVideoContentName[] = "video_content_name";
868static const char kDataContentName[] = "data_content_name";
869
deadbeef9d3584c2016-02-16 17:54:10 -0800870// Extra content names for extra unified plan m= sections.
871static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700872static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800873static const char kVideoContentName2[] = "video_content_name_2";
874static const char kVideoContentName3[] = "video_content_name_3";
875
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800877static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878static const char kStream1Cname[] = "stream_1_cname";
879static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200880static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800882static const uint32_t kVideoTrack1Ssrc1 = 2;
883static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884
885// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800886static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887static const char kStream2Cname[] = "stream_2_cname";
888static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200889static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800890static const char kVideoTrackId2[] = "video_track_id_2";
891static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800893static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700894static const char kAudioTrackId3[] = "audio_track_id_3";
895static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897// DataChannel
898static const char kDataChannelLabel[] = "data_channel";
899static const char kDataChannelMsid[] = "data_channeld0";
900static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200901static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
903// Candidate
904static const char kDummyMid[] = "dummy_mid";
905static const int kDummyIndex = 123;
906
907// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800908static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909
910// Helper functions
911
912static bool SdpDeserialize(const std::string& message,
913 JsepSessionDescription* jdesc) {
914 return webrtc::SdpDeserialize(message, jdesc, NULL);
915}
916
917static bool SdpDeserializeCandidate(const std::string& message,
918 JsepIceCandidate* candidate) {
919 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
920}
921
922// Add some extra |newlines| to the |message| after |line|.
923static void InjectAfter(const std::string& line,
924 const std::string& newlines,
925 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800926 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927}
928
929static void Replace(const std::string& line,
930 const std::string& newlines,
931 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800932 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933}
934
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000935// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
936// message.
937static void ExpectParseFailure(const std::string& bad_sdp,
938 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800939 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000941 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000943 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
944}
945
946// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
947static void ExpectParseFailure(const char* good_part, const char* bad_part) {
948 std::string bad_sdp = kSdpFullString;
949 Replace(good_part, bad_part, &bad_sdp);
950 ExpectParseFailure(bad_sdp, bad_part);
951}
952
953// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
954static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
955 const std::string& newlines,
956 const std::string& bad_part) {
957 std::string bad_sdp = kSdpFullString;
958 InjectAfter(injectpoint, newlines, &bad_sdp);
959 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960}
961
Steve Anton4e70a722017-11-28 14:57:10 -0800962static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 std::string* message) {
964 std::string new_direction;
965 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800966 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 new_direction = "a=inactive";
968 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800969 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 new_direction = "a=sendonly";
971 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800972 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 new_direction = "a=recvonly";
974 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800975 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 default:
977 new_direction = "a=sendrecv";
978 break;
979 }
980 Replace("a=sendrecv", new_direction, message);
981}
982
Yves Gerey665174f2018-06-19 15:03:05 +0200983static void ReplaceRejected(bool audio_rejected,
984 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 std::string* message) {
986 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800987 Replace("m=audio 9", "m=audio 0", message);
988 Replace(kAttributeIceUfragVoice, "", message);
989 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 }
991 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800992 Replace("m=video 9", "m=video 0", message);
993 Replace(kAttributeIceUfragVideo, "", message);
994 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 }
996}
997
998// WebRtcSdpTest
999
1000class WebRtcSdpTest : public testing::Test {
1001 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001002 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001003#ifdef WEBRTC_ANDROID
1004 webrtc::InitializeAndroidObjects();
1005#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 // AudioContentDescription
1007 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001008 StreamParams audio_stream;
1009 audio_stream.id = kAudioTrackId1;
1010 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001011 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001012 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1013 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001014 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1015 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001016 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017
1018 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001019 video_desc_ = CreateVideoContentDescription();
1020 StreamParams video_stream;
1021 video_stream.id = kVideoTrackId1;
1022 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001023 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001024 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1025 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1026 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1027 video_stream.ssrc_groups.push_back(ssrc_group);
1028 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001029 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1030 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001031 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032
1033 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001034 desc_.AddTransportInfo(TransportInfo(
1035 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1036 desc_.AddTransportInfo(TransportInfo(
1037 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
1039 // v4 host
1040 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001041 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001042 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001043 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1044 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001046 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1048 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001050 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001051 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1052 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057
1058 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001059 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001060 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1061 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001062 cricket::LOCAL_PORT_TYPE,
1063 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001065 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1066 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001067 cricket::LOCAL_PORT_TYPE,
1068 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001070 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1071 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001072 cricket::LOCAL_PORT_TYPE,
1073 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001075 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1076 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001077 cricket::LOCAL_PORT_TYPE,
1078 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079
1080 // stun
1081 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001082 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1083 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001084 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1085 address_stun, kCandidatePriority, "", "",
1086 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001087 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 candidate9.set_related_address(rel_address_stun);
1089
1090 address_stun.SetPort(port_stun++);
1091 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001092 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1093 address_stun, kCandidatePriority, "", "",
1094 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001095 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 candidate10.set_related_address(rel_address_stun);
1097
1098 // relay
1099 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001100 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001101 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1102 address_relay, kCandidatePriority, "", "",
1103 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001104 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001106 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1107 address_relay, kCandidatePriority, "", "",
1108 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001109 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110
1111 // voice
1112 candidates_.push_back(candidate1);
1113 candidates_.push_back(candidate2);
1114 candidates_.push_back(candidate5);
1115 candidates_.push_back(candidate6);
1116 candidates_.push_back(candidate9);
1117 candidates_.push_back(candidate10);
1118
1119 // video
1120 candidates_.push_back(candidate3);
1121 candidates_.push_back(candidate4);
1122 candidates_.push_back(candidate7);
1123 candidates_.push_back(candidate8);
1124 candidates_.push_back(candidate11);
1125 candidates_.push_back(candidate12);
1126
Yves Gerey665174f2018-06-19 15:03:05 +02001127 jcandidate_.reset(
1128 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129
1130 // Set up JsepSessionDescription.
1131 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1132 std::string mline_id;
1133 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001134 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 // In this test, the audio m line index will be 0, and the video m line
1136 // will be 1.
1137 bool is_video = (i > 5);
1138 mline_id = is_video ? "video_content_name" : "audio_content_name";
1139 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001140 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 jdesc_.AddCandidate(&jice);
1142 }
1143 }
1144
Seth Hampson5b4f0752018-04-02 16:31:36 -07001145 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001146 const IceCandidateCollection* video_candidates_collection =
1147 jdesc_.candidates(1);
1148 ASSERT_NE(nullptr, video_candidates_collection);
1149 std::vector<cricket::Candidate> video_candidates;
1150 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1151 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1152 c.set_transport_name("video_content_name");
1153 video_candidates.push_back(c);
1154 }
1155 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001156 }
1157
1158 // Turns the existing reference description into a description using
1159 // a=bundle-only. This means no transport attributes and a 0 port value on
1160 // the m= sections not associated with the BUNDLE-tag.
1161 void MakeBundleOnlyDescription() {
1162 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001163
1164 // And the rest of the transport attributes.
1165 desc_.transport_infos()[1].description.ice_ufrag.clear();
1166 desc_.transport_infos()[1].description.ice_pwd.clear();
1167 desc_.transport_infos()[1].description.connection_role =
1168 cricket::CONNECTIONROLE_NONE;
1169
1170 // Set bundle-only flag.
1171 desc_.contents()[1].bundle_only = true;
1172
1173 // Add BUNDLE group.
1174 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1175 group.AddContentName(kAudioContentName);
1176 group.AddContentName(kVideoContentName);
1177 desc_.AddGroup(group);
1178
1179 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1180 jdesc_.session_version()));
1181 }
1182
deadbeef9d3584c2016-02-16 17:54:10 -08001183 // Turns the existing reference description into a plan B description,
1184 // with 2 audio tracks and 3 video tracks.
1185 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001186 audio_desc_ = audio_desc_->Copy();
1187 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001188
1189 StreamParams audio_track_2;
1190 audio_track_2.id = kAudioTrackId2;
1191 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001192 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001193 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1194 audio_desc_->AddStream(audio_track_2);
1195
1196 StreamParams video_track_2;
1197 video_track_2.id = kVideoTrackId2;
1198 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001199 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001200 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1201 video_desc_->AddStream(video_track_2);
1202
1203 StreamParams video_track_3;
1204 video_track_3.id = kVideoTrackId3;
1205 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001206 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001207 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1208 video_desc_->AddStream(video_track_3);
1209
1210 desc_.RemoveContentByName(kAudioContentName);
1211 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001212 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1213 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001214
1215 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1216 jdesc_.session_version()));
1217 }
1218
1219 // Turns the existing reference description into a unified plan description,
1220 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001221 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001222 // Audio track 2.
1223 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1224 StreamParams audio_track_2;
1225 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001226 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001227 if (use_ssrcs) {
1228 audio_track_2.cname = kStream2Cname;
1229 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1230 }
deadbeef9d3584c2016-02-16 17:54:10 -08001231 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001232 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001233 desc_.AddTransportInfo(TransportInfo(
1234 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001235 // Video track 2, in stream 2.
1236 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1237 StreamParams video_track_2;
1238 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001239 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001240 if (use_ssrcs) {
1241 video_track_2.cname = kStream2Cname;
1242 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1243 }
deadbeef9d3584c2016-02-16 17:54:10 -08001244 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001245 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001246 desc_.AddTransportInfo(TransportInfo(
1247 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001248
1249 // Video track 3, in stream 2.
1250 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1251 StreamParams video_track_3;
1252 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001253 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001254 if (use_ssrcs) {
1255 video_track_3.cname = kStream2Cname;
1256 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1257 }
deadbeef9d3584c2016-02-16 17:54:10 -08001258 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001259 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001260 desc_.AddTransportInfo(TransportInfo(
1261 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001262 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001263
1264 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1265 jdesc_.session_version()));
1266 }
1267
1268 // Creates an audio content description with no streams, and some default
1269 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 AudioContentDescription* CreateAudioContentDescription() {
1271 AudioContentDescription* audio = new AudioContentDescription();
1272 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001273 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001274 audio->AddCrypto(CryptoParams(
1275 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1277 "dummy_session_params"));
1278 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001279 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001280 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001281 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1282 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 return audio;
1284 }
1285
Seth Hampson5b4f0752018-04-02 16:31:36 -07001286 // Turns the existing reference description into a unified plan description,
1287 // with 3 audio MediaContentDescriptions with special StreamParams that
1288 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1289 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001290 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001291 desc_.RemoveContentByName(kVideoContentName);
1292 desc_.RemoveTransportInfoByName(kVideoContentName);
1293 RemoveVideoCandidates();
1294
1295 // Audio track 2 has 2 media stream ids.
1296 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1297 StreamParams audio_track_2;
1298 audio_track_2.id = kAudioTrackId2;
1299 audio_track_2.cname = kStream1Cname;
1300 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1301 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1302 audio_desc_2->AddStream(audio_track_2);
1303 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001304 desc_.AddTransportInfo(TransportInfo(
1305 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001306
1307 // Audio track 3 has no stream ids.
1308 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1309 StreamParams audio_track_3;
1310 audio_track_3.id = kAudioTrackId3;
1311 audio_track_3.cname = kStream2Cname;
1312 audio_track_3.set_stream_ids({});
1313 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1314 audio_desc_3->AddStream(audio_track_3);
1315 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001316 desc_.AddTransportInfo(TransportInfo(
1317 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001318 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001319 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1320 jdesc_.session_version()));
1321 }
1322
Seth Hampson5897a6e2018-04-03 11:16:33 -07001323 // Turns the existing reference description into a unified plan description
1324 // with one audio MediaContentDescription that contains one StreamParams with
1325 // 0 ssrcs.
1326 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1327 desc_.RemoveContentByName(kVideoContentName);
1328 desc_.RemoveContentByName(kAudioContentName);
1329 desc_.RemoveTransportInfoByName(kVideoContentName);
1330 RemoveVideoCandidates();
1331
1332 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1333 StreamParams audio_track;
1334 audio_track.id = kAudioTrackId1;
1335 audio_track.set_stream_ids({kStreamId1});
1336 audio_desc->AddStream(audio_track);
1337 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1338
1339 // Enable signaling a=msid lines.
1340 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1341 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1342 jdesc_.session_version()));
1343 }
1344
deadbeef9d3584c2016-02-16 17:54:10 -08001345 // Creates a video content description with no streams, and some default
1346 // configuration.
1347 VideoContentDescription* CreateVideoContentDescription() {
1348 VideoContentDescription* video = new VideoContentDescription();
1349 video->AddCrypto(CryptoParams(
1350 1, "AES_CM_128_HMAC_SHA1_80",
1351 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1352 video->set_protocol(cricket::kMediaProtocolSavpf);
1353 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001354 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001355 return video;
1356 }
1357
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001359 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 // type
1361 EXPECT_EQ(cd1->type(), cd1->type());
1362
1363 // content direction
1364 EXPECT_EQ(cd1->direction(), cd2->direction());
1365
1366 // rtcp_mux
1367 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1368
deadbeef13871492015-12-09 12:37:51 -08001369 // rtcp_reduced_size
1370 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1371
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 // cryptos
1373 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1374 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1375 ADD_FAILURE();
1376 return;
1377 }
Yves Gerey665174f2018-06-19 15:03:05 +02001378 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 const CryptoParams c1 = cd1->cryptos().at(i);
1380 const CryptoParams c2 = cd2->cryptos().at(i);
1381 EXPECT_TRUE(c1.Matches(c2));
1382 EXPECT_EQ(c1.key_params, c2.key_params);
1383 EXPECT_EQ(c1.session_params, c2.session_params);
1384 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001385
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001387 // Use an equivalence class here, for old and new versions of the
1388 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001389 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1390 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1391 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001392 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001393 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1394 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1395 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001396 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001397 } else {
1398 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1399 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400
1401 // codecs
1402 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1403
1404 // bandwidth
1405 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1406
1407 // streams
1408 EXPECT_EQ(cd1->streams(), cd2->streams());
1409
Johannes Kron0854eb62018-10-10 22:33:20 +02001410 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001411 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 // extmap
1414 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1415 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001416 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001417 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1418 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 EXPECT_EQ(ext1.uri, ext2.uri);
1420 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001421 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 }
1424
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001425 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1426 const std::vector<std::string>& ids) {
1427 // Order of elements does not matter, only equivalence of sets.
1428 EXPECT_EQ(rids.size(), ids.size());
1429 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001430 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1431 return rid.rid == id;
1432 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001433 }
1434 }
1435
Amit Hilbucha2012042018-12-03 11:35:05 -08001436 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1437 const SimulcastDescription& simulcast2) {
1438 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1439 EXPECT_EQ(simulcast1.receive_layers().size(),
1440 simulcast2.receive_layers().size());
1441 }
1442
zstein4b2e0822017-02-17 19:48:38 -08001443 void CompareDataContentDescription(const DataContentDescription* dcd1,
1444 const DataContentDescription* dcd2) {
1445 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1446 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1447 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448
1449 void CompareSessionDescription(const SessionDescription& desc1,
1450 const SessionDescription& desc2) {
1451 // Compare content descriptions.
1452 if (desc1.contents().size() != desc2.contents().size()) {
1453 ADD_FAILURE();
1454 return;
1455 }
Yves Gerey665174f2018-06-19 15:03:05 +02001456 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1458 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001459 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001461 EXPECT_EQ(c1.type, c2.type);
1462 EXPECT_EQ(c1.rejected, c2.rejected);
1463 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464
1465 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1466 if (IsAudioContent(&c1)) {
1467 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001468 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001470 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1472 }
1473
1474 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1475 if (IsVideoContent(&c1)) {
1476 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001477 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001479 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1481 }
1482
1483 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1484 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001485 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1486 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001487 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001489
1490 CompareSimulcastDescription(
1491 c1.media_description()->simulcast_description(),
1492 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 }
1494
1495 // group
1496 const cricket::ContentGroups groups1 = desc1.groups();
1497 const cricket::ContentGroups groups2 = desc2.groups();
1498 EXPECT_EQ(groups1.size(), groups1.size());
1499 if (groups1.size() != groups2.size()) {
1500 ADD_FAILURE();
1501 return;
1502 }
1503 for (size_t i = 0; i < groups1.size(); ++i) {
1504 const cricket::ContentGroup group1 = groups1.at(i);
1505 const cricket::ContentGroup group2 = groups2.at(i);
1506 EXPECT_EQ(group1.semantics(), group2.semantics());
1507 const cricket::ContentNames names1 = group1.content_names();
1508 const cricket::ContentNames names2 = group2.content_names();
1509 EXPECT_EQ(names1.size(), names2.size());
1510 if (names1.size() != names2.size()) {
1511 ADD_FAILURE();
1512 return;
1513 }
1514 cricket::ContentNames::const_iterator iter1 = names1.begin();
1515 cricket::ContentNames::const_iterator iter2 = names2.begin();
1516 while (iter1 != names1.end()) {
1517 EXPECT_EQ(*iter1++, *iter2++);
1518 }
1519 }
1520
1521 // transport info
1522 const cricket::TransportInfos transports1 = desc1.transport_infos();
1523 const cricket::TransportInfos transports2 = desc2.transport_infos();
1524 EXPECT_EQ(transports1.size(), transports2.size());
1525 if (transports1.size() != transports2.size()) {
1526 ADD_FAILURE();
1527 return;
1528 }
1529 for (size_t i = 0; i < transports1.size(); ++i) {
1530 const cricket::TransportInfo transport1 = transports1.at(i);
1531 const cricket::TransportInfo transport2 = transports2.at(i);
1532 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_EQ(transport1.description.ice_ufrag,
1534 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001535 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001536 EXPECT_EQ(transport1.description.ice_mode,
1537 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 if (transport1.description.identity_fingerprint) {
1539 EXPECT_EQ(*transport1.description.identity_fingerprint,
1540 *transport2.description.identity_fingerprint);
1541 } else {
1542 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1543 transport2.description.identity_fingerprint.get());
1544 }
1545 EXPECT_EQ(transport1.description.transport_options,
1546 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 }
deadbeefc80741f2015-10-22 13:14:45 -07001548
1549 // global attributes
1550 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001551 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 }
1553
Yves Gerey665174f2018-06-19 15:03:05 +02001554 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1555 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1557 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1558 CompareSessionDescription(*desc1.description(), *desc2.description());
1559 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1560 return false;
1561 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1562 const IceCandidateCollection* cc1 = desc1.candidates(i);
1563 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001564 if (cc1->count() != cc2->count()) {
1565 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001567 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 for (size_t j = 0; j < cc1->count(); ++j) {
1569 const IceCandidateInterface* c1 = cc1->at(j);
1570 const IceCandidateInterface* c2 = cc2->at(j);
1571 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1572 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1573 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1574 }
1575 }
1576 return true;
1577 }
1578
1579 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1580 // them with invalid keywords so that the parser will just ignore them.
1581 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001582 absl::StrReplaceAll(
1583 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 return true;
1585 }
1586
1587 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001588 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1589 int mline_index,
1590 const std::string& ufrag,
1591 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 std::string content_name;
1593 if (mline_index == 0) {
1594 content_name = kAudioContentName;
1595 } else if (mline_index == 1) {
1596 content_name = kVideoContentName;
1597 } else {
nissec80e7412017-01-11 05:56:46 -08001598 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 }
Yves Gerey665174f2018-06-19 15:03:05 +02001600 TransportInfo transport_info(content_name,
1601 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 SessionDescription* desc =
1603 const_cast<SessionDescription*>(jdesc->description());
1604 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001605 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1607 const IceCandidateCollection* cc = jdesc_.candidates(i);
1608 for (size_t j = 0; j < cc->count(); ++j) {
1609 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001610 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1611 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 }
1613 }
1614 }
1615 return true;
1616 }
1617
1618 void AddIceOptions(const std::string& content_name,
1619 const std::vector<std::string>& transport_options) {
1620 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1621 cricket::TransportInfo transport_info =
1622 *(desc_.GetTransportInfoByName(content_name));
1623 desc_.RemoveTransportInfoByName(content_name);
1624 transport_info.description.transport_options = transport_options;
1625 desc_.AddTransportInfo(transport_info);
1626 }
1627
deadbeef3f7219b2015-12-28 15:17:14 -08001628 void SetIceUfragPwd(const std::string& content_name,
1629 const std::string& ice_ufrag,
1630 const std::string& ice_pwd) {
1631 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1632 cricket::TransportInfo transport_info =
1633 *(desc_.GetTransportInfoByName(content_name));
1634 desc_.RemoveTransportInfoByName(content_name);
1635 transport_info.description.ice_ufrag = ice_ufrag;
1636 transport_info.description.ice_pwd = ice_pwd;
1637 desc_.AddTransportInfo(transport_info);
1638 }
1639
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 void AddFingerprint() {
1641 desc_.RemoveTransportInfoByName(kAudioContentName);
1642 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001643 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001644 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001645 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001646 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1647 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001648 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1649 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001650 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001651 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1652 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001653 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 }
1655
jbauch5869f502017-06-29 12:31:36 -07001656 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001657 audio_desc_ = audio_desc_->Copy();
1658 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001659 audio_desc_->AddRtpHeaderExtension(
1660 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1661 video_desc_->AddRtpHeaderExtension(
1662 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 desc_.RemoveContentByName(kAudioContentName);
1664 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001665 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1666 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 }
1668
1669 void RemoveCryptos() {
1670 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1671 video_desc_->set_cryptos(std::vector<CryptoParams>());
1672 }
1673
Seth Hampson5897a6e2018-04-03 11:16:33 -07001674 // Removes everything in StreamParams from the session description that is
1675 // used for a=ssrc lines.
1676 void RemoveSsrcSignalingFromStreamParams() {
1677 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1678 // With Unified Plan there should be one StreamParams per m= section.
1679 StreamParams& stream =
1680 content_info.media_description()->mutable_streams()[0];
1681 stream.ssrcs.clear();
1682 stream.ssrc_groups.clear();
1683 stream.cname.clear();
1684 }
1685 }
1686
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001687 // Removes all a=ssrc lines from the SDP string, except for the
1688 // "a=ssrc:... cname:..." lines.
1689 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1690 const char kAttributeSsrc[] = "a=ssrc";
1691 const char kAttributeCname[] = "cname";
1692 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1693 while (ssrc_line_pos != std::string::npos) {
1694 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1695 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1696 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1697 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1698 // Only erase a=ssrc lines that don't contain "cname".
1699 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1700 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1701 } else {
1702 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1703 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1704 }
1705 }
1706 }
1707
Seth Hampson5897a6e2018-04-03 11:16:33 -07001708 // Removes all a=ssrc lines from the SDP string.
1709 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1710 const char kAttributeSsrc[] = "a=ssrc";
1711 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1712 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1713 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1714 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1715 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1716 }
1717 }
1718
Steve Anton4e70a722017-11-28 14:57:10 -08001719 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 audio_desc_->set_direction(direction);
1721 video_desc_->set_direction(direction);
1722 std::string new_sdp = kSdpFullString;
1723 ReplaceDirection(direction, &new_sdp);
1724
Yves Gerey665174f2018-06-19 15:03:05 +02001725 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 jdesc_.session_version())) {
1727 return false;
1728 }
Steve Antone831b8c2018-02-01 12:22:16 -08001729 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 EXPECT_EQ(new_sdp, message);
1731 return true;
1732 }
1733
1734 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001735 audio_desc_ = audio_desc_->Copy();
1736 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001737
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 desc_.RemoveContentByName(kAudioContentName);
1739 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001740 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001742 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001744 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1745 audio_rejected ? "" : kPwdVoice);
1746 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1747 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001748
1749 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1751
Steve Antona3a92c22017-12-07 10:27:41 -08001752 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001753 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001754 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 EXPECT_EQ(new_sdp, message);
1756 return true;
1757 }
1758
zstein4b2e0822017-02-17 19:48:38 -08001759 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001760 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001762 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001764 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001765 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001766 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1767 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001768 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1769 data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001770 desc_.AddTransportInfo(TransportInfo(
1771 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 }
1773
1774 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001775 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 data_desc_ = data.get();
1777
deadbeef67cf2c12016-04-13 10:07:16 -07001778 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 StreamParams data_stream;
1780 data_stream.id = kDataChannelMsid;
1781 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001782 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 data_stream.ssrcs.push_back(kDataChannelSsrc);
1784 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001785 data_desc_->AddCrypto(
1786 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1787 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001789 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001790 desc_.AddTransportInfo(TransportInfo(
1791 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 }
1793
Steve Anton4e70a722017-11-28 14:57:10 -08001794 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 std::string new_sdp = kSdpFullString;
1796 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001797 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798
1799 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1800
1801 audio_desc_->set_direction(direction);
1802 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001803 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 jdesc_.session_version())) {
1805 return false;
1806 }
1807 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1808 return true;
1809 }
1810
1811 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001812 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001814 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001816
Steve Antonb1c1de12017-12-21 15:14:30 -08001817 audio_desc_ = audio_desc_->Copy();
1818 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 desc_.RemoveContentByName(kAudioContentName);
1820 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001821 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001823 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001825 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1826 audio_rejected ? "" : kPwdVoice);
1827 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1828 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001829 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001830 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1831 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 return false;
1833 }
deadbeef3f7219b2015-12-28 15:17:14 -08001834 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 return true;
1836 }
1837
Yves Gerey665174f2018-06-19 15:03:05 +02001838 void TestDeserializeExtmap(bool session_level,
1839 bool media_level,
1840 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001841 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001842 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001843 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001845 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 std::string sdp_with_extmap = kSdpString;
1847 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001848 InjectAfter(kSessionTime,
1849 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1850 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 &sdp_with_extmap);
1852 }
1853 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001854 InjectAfter(kAttributeIcePwdVoice,
1855 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1856 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001858 InjectAfter(kAttributeIcePwdVideo,
1859 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1860 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 &sdp_with_extmap);
1862 }
1863 // The extmap can't be present at the same time in both session level and
1864 // media level.
1865 if (session_level && media_level) {
1866 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001867 EXPECT_FALSE(
1868 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1870 } else {
1871 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1872 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1873 }
1874 }
1875
1876 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001877 const std::string& name,
1878 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 cricket::CodecParameterMap::const_iterator found = params.find(name);
1880 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001881 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 }
1883
1884 void TestDeserializeCodecParams(const CodecParams& params,
1885 JsepSessionDescription* jdesc_output) {
1886 std::string sdp =
1887 "v=0\r\n"
1888 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1889 "s=-\r\n"
1890 "t=0 0\r\n"
1891 // Include semantics for WebRTC Media Streams since it is supported by
1892 // this parser, and will be added to the SDP when serializing a session
1893 // description.
1894 "a=msid-semantic: WMS\r\n"
1895 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001896 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 // Pltype 111 listed before 103 and 104 in the map.
1898 "a=rtpmap:111 opus/48000/2\r\n"
1899 // Pltype 103 listed before 104.
1900 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001901 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001902 "a=fmtp:111 0-15,66,70\r\n"
1903 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001905 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001906 << "; sprop-stereo=" << params.sprop_stereo
1907 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001908 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 << "a=ptime:" << params.ptime << "\r\n"
1910 << "a=maxptime:" << params.max_ptime << "\r\n";
1911 sdp += os.str();
1912
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001913 os.clear();
1914 os.str("");
1915 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001916 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001917 << "a=rtpmap:99 VP8/90000\r\n"
1918 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001919 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001920 sdp += os.str();
1921
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 // Deserialize
1923 SdpParseError error;
1924 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1925
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001927 GetFirstAudioContentDescription(jdesc_output->description());
1928 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 ASSERT_FALSE(acd->codecs().empty());
1930 cricket::AudioCodec opus = acd->codecs()[0];
1931 EXPECT_EQ("opus", opus.name);
1932 EXPECT_EQ(111, opus.id);
1933 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1934 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1935 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1936 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001937 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1938 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1940 cricket::AudioCodec codec = acd->codecs()[i];
1941 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1942 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001944
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001945 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001946 GetFirstVideoContentDescription(jdesc_output->description());
1947 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001948 ASSERT_FALSE(vcd->codecs().empty());
1949 cricket::VideoCodec vp8 = vcd->codecs()[0];
1950 EXPECT_EQ("VP8", vp8.name);
1951 EXPECT_EQ(99, vp8.id);
1952 cricket::VideoCodec rtx = vcd->codecs()[1];
1953 EXPECT_EQ("RTX", rtx.name);
1954 EXPECT_EQ(95, rtx.id);
1955 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 }
1957
1958 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1959 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001960 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 "v=0\r\n"
1962 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1963 "s=-\r\n"
1964 "t=0 0\r\n"
1965 // Include semantics for WebRTC Media Streams since it is supported by
1966 // this parser, and will be added to the SDP when serializing a session
1967 // description.
1968 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001969 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001970 "a=rtpmap:111 opus/48000/2\r\n";
1971 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 "m=video 3457 RTP/SAVPF 101\r\n"
1973 "a=rtpmap:101 VP8/90000\r\n"
1974 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001975 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001976 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001978 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001979 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001980 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001981 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001982 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 // Deserialize
1984 SdpParseError error;
1985 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001987 GetFirstAudioContentDescription(jdesc_output->description());
1988 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 ASSERT_FALSE(acd->codecs().empty());
1990 cricket::AudioCodec opus = acd->codecs()[0];
1991 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001992 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1993 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001996 GetFirstVideoContentDescription(jdesc_output->description());
1997 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 ASSERT_FALSE(vcd->codecs().empty());
1999 cricket::VideoCodec vp8 = vcd->codecs()[0];
2000 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2001 vp8.name.c_str());
2002 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002003 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2004 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2005 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2006 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2007 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2008 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2009 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2010 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 }
2012
2013 // Two SDP messages can mean the same thing but be different strings, e.g.
2014 // some of the lines can be serialized in different order.
2015 // However, a deserialized description can be compared field by field and has
2016 // no order. If deserializer has already been tested, serializing then
2017 // deserializing and comparing JsepSessionDescription will test
2018 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002019 void TestSerialize(const JsepSessionDescription& jdesc) {
2020 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002021 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 SdpParseError error;
2023 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2024 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2025 }
2026
zhihuang38989e52017-03-21 11:04:53 -07002027 // Calling 'Initialize' with a copy of the inner SessionDescription will
2028 // create a copy of the JsepSessionDescription without candidates. The
2029 // 'connection address' field, previously set from the candidates, must also
2030 // be reset.
2031 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2032 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2033 rtc::SocketAddress video_addr("0.0.0.0", 9);
2034 audio_desc_->set_connection_address(audio_addr);
2035 video_desc_->set_connection_address(video_addr);
2036 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2037 }
2038
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 protected:
2040 SessionDescription desc_;
2041 AudioContentDescription* audio_desc_;
2042 VideoContentDescription* video_desc_;
2043 DataContentDescription* data_desc_;
2044 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002045 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 JsepSessionDescription jdesc_;
2047};
2048
2049void TestMismatch(const std::string& string1, const std::string& string2) {
2050 int position = 0;
2051 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2052 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002053 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054 break;
2055 }
2056 }
2057 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2058 << " character\n"
2059 << " 1: " << string1.substr(position, 20) << "\n"
2060 << " 2: " << string2.substr(position, 20) << "\n";
2061}
2062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2064 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002065 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 TestMismatch(std::string(kSdpFullString), message);
2067}
2068
2069TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002070 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002071 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
2074// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2075// the case in a DTLS offer.
2076TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2077 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002078 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002079 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002080 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081
2082 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002083 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2084 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085
2086 EXPECT_EQ(sdp_with_fingerprint, message);
2087}
2088
2089// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2090// be the case in a DTLS answer.
2091TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2092 AddFingerprint();
2093 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002094 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002095 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002096 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
2098 std::string sdp_with_fingerprint = kSdpString;
2099 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2100 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002101 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2102 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
2104 EXPECT_EQ(sdp_with_fingerprint, message);
2105}
2106
2107TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2108 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002109 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002110 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002111 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 EXPECT_EQ(std::string(kSdpString), message);
2113}
2114
2115TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2116 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2117 group.AddContentName(kAudioContentName);
2118 group.AddContentName(kVideoContentName);
2119 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002120 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002122 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 std::string sdp_with_bundle = kSdpFullString;
2124 InjectAfter(kSessionTime,
2125 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2126 &sdp_with_bundle);
2127 EXPECT_EQ(sdp_with_bundle, message);
2128}
2129
2130TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002131 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002133 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002135 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002137 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002139 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002141 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 &sdp_with_bandwidth);
2143 EXPECT_EQ(sdp_with_bandwidth, message);
2144}
2145
2146TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2147 std::vector<std::string> transport_options;
2148 transport_options.push_back(kIceOption1);
2149 transport_options.push_back(kIceOption3);
2150 AddIceOptions(kAudioContentName, transport_options);
2151 transport_options.clear();
2152 transport_options.push_back(kIceOption2);
2153 transport_options.push_back(kIceOption3);
2154 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002155 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002157 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002159 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002161 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 &sdp_with_ice_options);
2163 EXPECT_EQ(sdp_with_ice_options, message);
2164}
2165
2166TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002167 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168}
2169
2170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002171 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172}
2173
2174TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002175 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176}
2177
2178TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2179 EXPECT_TRUE(TestSerializeRejected(true, false));
2180}
2181
2182TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2183 EXPECT_TRUE(TestSerializeRejected(false, true));
2184}
2185
2186TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2187 EXPECT_TRUE(TestSerializeRejected(true, true));
2188}
2189
2190TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2191 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002192 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193
zhihuang38989e52017-03-21 11:04:53 -07002194 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002195 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196
2197 std::string expected_sdp = kSdpString;
2198 expected_sdp.append(kSdpRtpDataChannelString);
2199 EXPECT_EQ(expected_sdp, message);
2200}
2201
2202TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002203 bool use_sctpmap = true;
2204 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002205 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206
zhihuang38989e52017-03-21 11:04:53 -07002207 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002208 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209
2210 std::string expected_sdp = kSdpString;
2211 expected_sdp.append(kSdpSctpDataChannelString);
2212 EXPECT_EQ(message, expected_sdp);
2213}
2214
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002215TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002216 bool use_sctpmap = true;
2217 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002218 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002219 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002220 DataContentDescription* dcdesc =
2221 jsep_desc.description()
2222 ->GetContentDescriptionByName(kDataContentName)
2223 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002224
2225 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002226 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002227 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002228 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2229 dcdesc->AddOrReplaceCodec(codec);
2230
Steve Antone831b8c2018-02-01 12:22:16 -08002231 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002232
2233 std::string expected_sdp = kSdpString;
2234 expected_sdp.append(kSdpSctpDataChannelString);
2235
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002236 absl::StrReplaceAll(
2237 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2238 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002239
2240 EXPECT_EQ(expected_sdp, message);
2241}
2242
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002243TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002244 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002245 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002246 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002247 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002248 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002249
2250 std::string expected_sdp = kSdpString;
2251 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002252 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002253 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002254 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002255 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002256}
2257
Johannes Kron0854eb62018-10-10 22:33:20 +02002258TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002259 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002260 TestSerialize(jdesc_);
2261}
2262
2263TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2264 cricket::MediaContentDescription* video_desc =
2265 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2266 ASSERT_TRUE(video_desc);
2267 cricket::MediaContentDescription* audio_desc =
2268 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2269 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002270 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002271 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002272 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002273 cricket::MediaContentDescription::kMedia);
2274 TestSerialize(jdesc_);
2275}
2276
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002278 bool encrypted = false;
2279 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002280 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002281 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002282 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283
2284 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002285 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2286 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287
2288 EXPECT_EQ(sdp_with_extmap, message);
2289}
2290
jbauch5869f502017-06-29 12:31:36 -07002291TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2292 bool encrypted = true;
2293 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002294 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002295 ASSERT_TRUE(
2296 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002297 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002298}
2299
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300TEST_F(WebRtcSdpTest, SerializeCandidates) {
2301 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002302 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002303
2304 Candidate candidate_with_ufrag(candidates_.front());
2305 candidate_with_ufrag.set_username("ABC");
2306 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2307 candidate_with_ufrag));
2308 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2309 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002310
2311 Candidate candidate_with_network_info(candidates_.front());
2312 candidate_with_network_info.set_network_id(1);
2313 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2314 candidate_with_network_info));
2315 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2316 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2317 candidate_with_network_info.set_network_cost(999);
2318 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2319 candidate_with_network_info));
2320 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2321 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2322 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323}
2324
Zach Steinb336c272018-08-09 01:16:13 -07002325TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2326 rtc::SocketAddress address("a.test", 1234);
2327 cricket::Candidate candidate(
2328 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2329 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2330 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2331 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2332 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2333}
2334
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002335// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2336// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002337TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002338 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002339 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2340 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2341 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002342 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002343 std::unique_ptr<IceCandidateInterface> jcandidate(
2344 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002345
2346 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2347 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2348}
2349
htaa6b99442016-04-12 10:29:17 -07002350TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002351 cricket::VideoCodec h264_codec("H264");
2352 h264_codec.SetParam("profile-level-id", "42e01f");
2353 h264_codec.SetParam("level-asymmetry-allowed", "1");
2354 h264_codec.SetParam("packetization-mode", "1");
2355 video_desc_->AddCodec(h264_codec);
2356
htaa6b99442016-04-12 10:29:17 -07002357 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2358
Steve Antone831b8c2018-02-01 12:22:16 -08002359 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002360 size_t after_pt = message.find(" H264/90000");
2361 ASSERT_NE(after_pt, std::string::npos);
2362 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2363 ASSERT_NE(before_pt, std::string::npos);
2364 before_pt += strlen("a=rtpmap:");
2365 std::string pt = message.substr(before_pt, after_pt - before_pt);
2366 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2367 std::string to_find = "a=fmtp:" + pt + " ";
2368 size_t fmtp_pos = message.find(to_find);
2369 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002370 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002371 ASSERT_NE(std::string::npos, fmtp_endpos);
2372 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2373 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2374 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2375 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002376 // Check that there are no spaces after semicolons.
2377 // https://bugs.webrtc.org/5793
2378 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002379}
2380
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002382 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 // Deserialize
2384 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2385 // Verify
2386 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2387}
2388
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002389TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002390 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002391 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002392 "v=0\r\n"
2393 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2394 "s=-\r\n"
2395 "t=0 0\r\n"
2396 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002397 // Deserialize
2398 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2399 EXPECT_EQ(0u, jdesc.description()->contents().size());
2400}
2401
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002403 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 std::string sdp_without_carriage_return = kSdpFullString;
2405 Replace("\r\n", "\n", &sdp_without_carriage_return);
2406 // Deserialize
2407 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2408 // Verify
2409 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2410}
2411
2412TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2413 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002414 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002415 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2416 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002417 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2419 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2420}
2421
2422TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2423 static const char kSdpNoRtpmapString[] =
2424 "v=0\r\n"
2425 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2426 "s=-\r\n"
2427 "t=0 0\r\n"
2428 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2429 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002430 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 // The rtpmap line for static payload codec is optional.
2432 "a=rtpmap:18 G729/16000\r\n"
2433 "a=rtpmap:103 ISAC/16000\r\n";
2434
Steve Antona3a92c22017-12-07 10:27:41 -08002435 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2437 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002438 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002440 // The codecs in the AudioContentDescription should be in the same order as
2441 // the payload types (<fmt>s) on the m= line.
2442 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2443 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002444 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 EXPECT_EQ(ref_codecs, audio->codecs());
2446}
2447
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002448TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2449 static const char kSdpNoRtpmapString[] =
2450 "v=0\r\n"
2451 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2452 "s=-\r\n"
2453 "t=0 0\r\n"
2454 "m=audio 49232 RTP/AVP 18 103\r\n"
2455 "a=fmtp:18 annexb=yes\r\n"
2456 "a=rtpmap:103 ISAC/16000\r\n";
2457
Steve Antona3a92c22017-12-07 10:27:41 -08002458 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002459 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2460 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002461 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002462
2463 cricket::AudioCodec g729 = audio->codecs()[0];
2464 EXPECT_EQ("G729", g729.name);
2465 EXPECT_EQ(8000, g729.clockrate);
2466 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002467 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002468 ASSERT_TRUE(found != g729.params.end());
2469 EXPECT_EQ(found->second, "yes");
2470
2471 cricket::AudioCodec isac = audio->codecs()[1];
2472 EXPECT_EQ("ISAC", isac.name);
2473 EXPECT_EQ(103, isac.id);
2474 EXPECT_EQ(16000, isac.clockrate);
2475}
2476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477// Ensure that we can deserialize SDP with a=fingerprint properly.
2478TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2479 // Add a DTLS a=fingerprint attribute to our session description.
2480 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002481 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002482 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 jdesc_.session_version()));
2484
Steve Antona3a92c22017-12-07 10:27:41 -08002485 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 std::string sdp_with_fingerprint = kSdpString;
2487 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2488 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2489 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2490 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2491}
2492
2493TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002494 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 std::string sdp_with_bundle = kSdpFullString;
2496 InjectAfter(kSessionTime,
2497 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2498 &sdp_with_bundle);
2499 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2500 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2501 group.AddContentName(kAudioContentName);
2502 group.AddContentName(kVideoContentName);
2503 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002504 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 jdesc_.session_version()));
2506 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2507}
2508
2509TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002510 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002512 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002514 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002516 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002517 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002519 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002521 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 jdesc_.session_version()));
2523 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2524}
2525
2526TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002527 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002529 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002531 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002533 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 &sdp_with_ice_options);
2535 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2536 std::vector<std::string> transport_options;
2537 transport_options.push_back(kIceOption3);
2538 transport_options.push_back(kIceOption1);
2539 AddIceOptions(kAudioContentName, transport_options);
2540 transport_options.clear();
2541 transport_options.push_back(kIceOption3);
2542 transport_options.push_back(kIceOption2);
2543 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002544 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 jdesc_.session_version()));
2546 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2547}
2548
2549TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2550 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002551 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 std::string sdp_with_ufrag_pwd = kSdpFullString;
2553 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2554 // Add session level ufrag and pwd
2555 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002556 "a=ice-pwd:session+level+icepwd\r\n"
2557 "a=ice-ufrag:session+level+iceufrag\r\n",
2558 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002560 InjectAfter(
2561 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2563 &sdp_with_ufrag_pwd);
2564 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002565 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2566 "media+level+icepwd"));
2567 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2568 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2570 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2571}
2572
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002574 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575}
2576
2577TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002578 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579}
2580
2581TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002582 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583}
2584
2585TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2586 EXPECT_TRUE(TestDeserializeRejected(true, false));
2587}
2588
2589TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2590 EXPECT_TRUE(TestDeserializeRejected(false, true));
2591}
2592
2593TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2594 EXPECT_TRUE(TestDeserializeRejected(true, true));
2595}
2596
2597// Tests that we can still handle the sdp uses mslabel and label instead of
2598// msid for backward compatibility.
2599TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002600 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002601 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 std::string sdp_without_msid = kSdpFullString;
2603 Replace("msid", "xmsid", &sdp_without_msid);
2604 // Deserialize
2605 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2606 // Verify
2607 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002608 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2609 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610}
2611
Johannes Kron0854eb62018-10-10 22:33:20 +02002612TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002613 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002614 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2615 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2616 // Deserialize
2617 JsepSessionDescription jdesc_deserialized(kDummyType);
2618 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2619 // Verify
2620 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2621}
2622
2623TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002624 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002625 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2626 // Deserialize
2627 JsepSessionDescription jdesc_deserialized(kDummyType);
2628 EXPECT_TRUE(
2629 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2630 // Verify
2631 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2632}
2633
2634TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2635 cricket::MediaContentDescription* video_desc =
2636 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2637 ASSERT_TRUE(video_desc);
2638 cricket::MediaContentDescription* audio_desc =
2639 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2640 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002641 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002642 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002643 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002644 cricket::MediaContentDescription::kMedia);
2645
2646 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2647 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2648 &sdp_with_extmap_allow_mixed);
2649 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2650 &sdp_with_extmap_allow_mixed);
2651
2652 // Deserialize
2653 JsepSessionDescription jdesc_deserialized(kDummyType);
2654 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2655 // Verify
2656 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2657}
2658
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2660 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2661
2662 std::string sdp = kSdpOneCandidate;
2663 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2664 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2665 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2666 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002667 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668
2669 // Candidate line without generation extension.
2670 sdp = kSdpOneCandidate;
2671 Replace(" generation 2", "", &sdp);
2672 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2673 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2674 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2675 Candidate expected = jcandidate_->candidate();
2676 expected.set_generation(0);
2677 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2678
honghaiza0c44ea2016-03-23 16:07:48 -07002679 // Candidate with network id and/or cost.
2680 sdp = kSdpOneCandidate;
2681 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2682 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2683 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2684 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2685 expected = jcandidate_->candidate();
2686 expected.set_network_id(2);
2687 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2688 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2689 // Add network cost
2690 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2691 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2692 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2693 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2694
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002695 sdp = kSdpTcpActiveCandidate;
2696 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2697 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002698 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002699 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2700 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2701 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002702 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2703 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002704 EXPECT_TRUE(
2705 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002706 sdp = kSdpTcpPassiveCandidate;
2707 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2708 sdp = kSdpTcpSOCandidate;
2709 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710}
2711
2712// This test verifies the deserialization of candidate-attribute
2713// as per RFC 5245. Candiate-attribute will be of the format
2714// candidate:<blah>. This format will be used when candidates
2715// are trickled.
2716TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2717 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2718
2719 std::string candidate_attribute = kRawCandidate;
2720 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2721 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2722 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2723 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2724 EXPECT_EQ(2u, jcandidate.candidate().generation());
2725
2726 // Candidate line without generation extension.
2727 candidate_attribute = kRawCandidate;
2728 Replace(" generation 2", "", &candidate_attribute);
2729 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2730 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2731 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2732 Candidate expected = jcandidate_->candidate();
2733 expected.set_generation(0);
2734 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2735
2736 // Candidate line without candidate:
2737 candidate_attribute = kRawCandidate;
2738 Replace("candidate:", "", &candidate_attribute);
2739 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2740
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002741 // Candidate line with IPV6 address.
2742 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002743
2744 // Candidate line with hostname address.
2745 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002746}
2747
2748// This test verifies that the deserialization of an invalid candidate string
2749// fails.
2750TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002751 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002752
2753 std::string candidate_attribute = kRawCandidate;
2754 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002756
2757 candidate_attribute = kSdpOneCandidate;
2758 candidate_attribute.replace(0, 1, "x");
2759 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2760
2761 candidate_attribute = kRawCandidate;
2762 candidate_attribute.append("\r\n");
2763 candidate_attribute.append(kRawCandidate);
2764 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2765
2766 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767}
2768
2769TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2770 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002771 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2773
2774 std::string sdp_with_data = kSdpString;
2775 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002776 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777
2778 // Deserialize
2779 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2780 // Verify
2781 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2782}
2783
2784TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002785 bool use_sctpmap = true;
2786 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002787 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2789
2790 std::string sdp_with_data = kSdpString;
2791 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002792 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793
lally@webrtc.org36300852015-02-24 20:19:35 +00002794 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2795 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2796 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2797
2798 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002799 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2800 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002801 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2802 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2803
2804 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002805 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2806 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2808 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2809}
2810
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002811TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002812 bool use_sctpmap = false;
2813 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002814 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002815 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2816
2817 std::string sdp_with_data = kSdpString;
2818 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002819 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002820
lally@webrtc.org36300852015-02-24 20:19:35 +00002821 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002822 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2823 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002824
lally@webrtc.org36300852015-02-24 20:19:35 +00002825 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002826 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2827 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002828 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2829 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002830
lally@webrtc.org36300852015-02-24 20:19:35 +00002831 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002832 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2833 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002834 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2835 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2836}
2837
lally69f57602015-10-08 10:15:04 -07002838TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002839 bool use_sctpmap = false;
2840 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002841 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002842 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2843
2844 std::string sdp_with_data = kSdpString;
2845 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002846 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002847
2848 // Verify with DTLS/SCTP.
2849 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2850 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2851
2852 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002853 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2854 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002855 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2856 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2857
2858 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002859 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2860 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002861 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2862 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2863}
2864
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002865// Test to check the behaviour if sctp-port is specified
2866// on the m= line and in a=sctp-port.
2867TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002868 bool use_sctpmap = true;
2869 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002870 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002871 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2872
2873 std::string sdp_with_data = kSdpString;
2874 // Append m= attributes
2875 sdp_with_data.append(kSdpSctpDataChannelString);
2876 // Append a=sctp-port attribute
2877 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002878 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002879
2880 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2881}
2882
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002883// For crbug/344475.
2884TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2885 std::string sdp_with_data = kSdpString;
2886 sdp_with_data.append(kSdpSctpDataChannelString);
2887 // Remove the "\n" at the end.
2888 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002889 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002890
2891 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2892 // No crash is a pass.
2893}
2894
Steve Anton36b29d12017-10-30 09:57:42 -07002895void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002896 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002897 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002898 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002899 DataContentDescription* dcdesc =
2900 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002901 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002902 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002903 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002904 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002905 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002906
2907 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002908 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002909 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002910}
2911
2912TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2913 bool use_sctpmap = true;
2914 AddSctpDataChannel(use_sctpmap);
2915
2916 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002917 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002918 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002919
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002920 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002921 std::string sdp_with_data = kSdpString;
2922 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002923 absl::StrReplaceAll(
2924 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2925 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002926 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002927
2928 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2929 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002930}
2931
2932TEST_F(WebRtcSdpTest,
2933 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2934 bool use_sctpmap = false;
2935 AddSctpDataChannel(use_sctpmap);
2936
Steve Antona3a92c22017-12-07 10:27:41 -08002937 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002938 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002939
2940 // We need to test the deserialized JsepSessionDescription from
2941 // kSdpSctpDataChannelStringWithSctpPort for
2942 // draft-ietf-mmusic-sctp-sdp-07
2943 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002944 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002945 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002946 absl::StrReplaceAll(
2947 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
2948 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002949 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002950
2951 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2952 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002953}
2954
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002955TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002956 // We want to test that deserializing data content limits bandwidth
2957 // settings (it should never be greater than the default).
2958 // This should prevent someone from using unlimited data bandwidth through
2959 // JS and "breaking the Internet".
2960 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002961 std::string sdp_with_bandwidth = kSdpString;
2962 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002963 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002964 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002965 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002966
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002967 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2968}
2969
2970TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002971 bool use_sctpmap = true;
2972 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002973 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002974 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002975 dcd->set_bandwidth(100 * 1000);
2976 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2977
2978 std::string sdp_with_bandwidth = kSdpString;
2979 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002980 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002981 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002982 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002983
2984 // SCTP has congestion control, so we shouldn't limit the bandwidth
2985 // as we do for RTP.
2986 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002987 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2988}
2989
Yves Gerey665174f2018-06-19 15:03:05 +02002990class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2991 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002992
2993TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002994 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002995 bool encrypted = GetParam();
2996 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997}
2998
Yves Gerey665174f2018-06-19 15:03:05 +02002999TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003000 bool encrypted = GetParam();
3001 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002}
3003
Yves Gerey665174f2018-06-19 15:03:05 +02003004TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003005 bool encrypted = GetParam();
3006 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003007}
3008
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003009INSTANTIATE_TEST_SUITE_P(Encrypted,
3010 WebRtcSdpExtmapTest,
3011 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003012
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003013TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003014 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003015 std::string sdp = kSdpFullString;
3016 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3017 // Deserialize
3018 SdpParseError error;
3019 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003020 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003021 EXPECT_EQ(lastline, error.line);
3022 EXPECT_EQ("Invalid SDP line.", error.description);
3023}
3024
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3026 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3027 std::string new_sdp = kSdpOneCandidate;
3028 Replace("udp", "unsupported_transport", &new_sdp);
3029 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3030 new_sdp = kSdpOneCandidate;
3031 Replace("udp", "uDP", &new_sdp);
3032 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3033 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3034 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3035 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3036}
3037
honghaiza54a0802015-12-16 18:37:23 -08003038TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003039 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003040 EXPECT_TRUE(
3041 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003042 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3043 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3044 Candidate ref_candidate = jcandidate_->candidate();
3045 ref_candidate.set_username("user_rtp");
3046 ref_candidate.set_password("password_rtp");
3047 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3048}
3049
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003050TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003051 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003052
3053 // Deserialize
3054 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3055
3056 // Verify
3057 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003058 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003059 EXPECT_TRUE(audio->conference_mode());
3060
3061 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003062 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003063 EXPECT_TRUE(video->conference_mode());
3064}
3065
deadbeefd45aea82017-09-16 01:24:29 -07003066TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003067 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003068
3069 // We tested deserialization already above, so just test that if we serialize
3070 // and deserialize the flag doesn't disappear.
3071 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003072 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003073 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3074
3075 // Verify.
3076 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003077 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003078 EXPECT_TRUE(audio->conference_mode());
3079
3080 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003081 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003082 EXPECT_TRUE(video->conference_mode());
3083}
3084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3086 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003087 const char kSdpEmptyType[] = " =candidate";
3088 const char kSdpEqualAsPlus[] = "a+candidate";
3089 const char kSdpSpaceAfterEqual[] = "a= candidate";
3090 const char kSdpUpperType[] = "A=candidate";
3091 const char kSdpEmptyLine[] = "";
3092 const char kSdpMissingValue[] = "a=";
3093
Yves Gerey665174f2018-06-19 15:03:05 +02003094 const char kSdpBrokenFingerprint[] =
3095 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 "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 +02003097 const char kSdpExtraField[] =
3098 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099 "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 +02003100 const char kSdpMissingSpace[] =
3101 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003102 "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 +00003103 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003104 const char kSdpMd5[] =
3105 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003106 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003107
3108 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003109 ExpectParseFailure("v=", kSdpDestroyer);
3110 ExpectParseFailure("o=", kSdpDestroyer);
3111 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003113 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114
3115 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003116 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3117 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118
3119 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003120 ExpectParseFailure("a=candidate", kSdpEmptyType);
3121 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3122 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3123 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003124
3125 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3126 // because it's orthogonal to what we are replacing and hence
3127 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003128 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3129 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3130 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3131 ExpectParseFailure("a=sendrecv", kSdpMd5);
3132
3133 // Empty Line
3134 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3135 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003136}
3137
3138TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3139 // ssrc
3140 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003141 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003142 // crypto
3143 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3144 // rtpmap
3145 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3146 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3147 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3148 // candidate
3149 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3150 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3151 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3152 ExpectParseFailure("rport 2346", "rport badvalue");
3153 ExpectParseFailure("rport 2346 generation 2",
3154 "rport 2346 generation badvalue");
3155 // m line
3156 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3157 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3158
3159 // bandwidth
3160 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003161 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003162 // rtcp-fb
3163 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3164 "a=rtcp-fb:badvalue nack\r\n",
3165 "a=rtcp-fb:badvalue nack");
3166 // extmap
3167 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3168 "a=extmap:badvalue http://example.com\r\n",
3169 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003170}
3171
3172TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003173 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174
3175 const char kSdpWithReorderedPlTypesString[] =
3176 "v=0\r\n"
3177 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3178 "s=-\r\n"
3179 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003180 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003181 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3182 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003184 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185
3186 // Deserialize
3187 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003190 GetFirstAudioContentDescription(jdesc_output.description());
3191 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003193 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3194 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003195 EXPECT_EQ(104, acd->codecs()[0].id);
3196}
3197
3198TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003199 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200 CodecParams params;
3201 params.max_ptime = 40;
3202 params.ptime = 30;
3203 params.min_ptime = 10;
3204 params.sprop_stereo = 1;
3205 params.stereo = 1;
3206 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003207 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003209 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210}
3211
3212TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3213 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003214 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003215 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003216 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217}
3218
3219TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3220 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003221 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003223 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224}
3225
3226TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003227 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228
3229 const char kSdpWithFmtpString[] =
3230 "v=0\r\n"
3231 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3232 "s=-\r\n"
3233 "t=0 0\r\n"
3234 "m=video 3457 RTP/SAVPF 120\r\n"
3235 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003236 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3237
3238 // Deserialize
3239 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003240 EXPECT_TRUE(
3241 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003242
Donald Curtis0e07f922015-05-15 09:21:23 -07003243 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003244 GetFirstVideoContentDescription(jdesc_output.description());
3245 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003246 ASSERT_FALSE(vcd->codecs().empty());
3247 cricket::VideoCodec vp8 = vcd->codecs()[0];
3248 EXPECT_EQ("VP8", vp8.name);
3249 EXPECT_EQ(120, vp8.id);
3250 cricket::CodecParameterMap::iterator found =
3251 vp8.params.find("x-google-min-bitrate");
3252 ASSERT_TRUE(found != vp8.params.end());
3253 EXPECT_EQ(found->second, "10");
3254 found = vp8.params.find("x-google-max-quantization");
3255 ASSERT_TRUE(found != vp8.params.end());
3256 EXPECT_EQ(found->second, "40");
3257}
3258
johan2d8d23e2016-06-03 01:22:42 -07003259TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003260 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003261
3262 const char kSdpWithFmtpString[] =
3263 "v=0\r\n"
3264 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3265 "s=-\r\n"
3266 "t=0 0\r\n"
3267 "m=video 49170 RTP/AVP 98\r\n"
3268 "a=rtpmap:98 H264/90000\r\n"
3269 "a=fmtp:98 profile-level-id=42A01E; "
3270 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3271
3272 // Deserialize.
3273 SdpParseError error;
3274 EXPECT_TRUE(
3275 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3276
johan2d8d23e2016-06-03 01:22:42 -07003277 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003278 GetFirstVideoContentDescription(jdesc_output.description());
3279 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003280 ASSERT_FALSE(vcd->codecs().empty());
3281 cricket::VideoCodec h264 = vcd->codecs()[0];
3282 EXPECT_EQ("H264", h264.name);
3283 EXPECT_EQ(98, h264.id);
3284 cricket::CodecParameterMap::const_iterator found =
3285 h264.params.find("profile-level-id");
3286 ASSERT_TRUE(found != h264.params.end());
3287 EXPECT_EQ(found->second, "42A01E");
3288 found = h264.params.find("sprop-parameter-sets");
3289 ASSERT_TRUE(found != h264.params.end());
3290 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3291}
3292
Donald Curtis0e07f922015-05-15 09:21:23 -07003293TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003294 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003295
3296 const char kSdpWithFmtpString[] =
3297 "v=0\r\n"
3298 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3299 "s=-\r\n"
3300 "t=0 0\r\n"
3301 "m=video 3457 RTP/SAVPF 120\r\n"
3302 "a=rtpmap:120 VP8/90000\r\n"
3303 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304
3305 // Deserialize
3306 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003307 EXPECT_TRUE(
3308 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003310 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003311 GetFirstVideoContentDescription(jdesc_output.description());
3312 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 ASSERT_FALSE(vcd->codecs().empty());
3314 cricket::VideoCodec vp8 = vcd->codecs()[0];
3315 EXPECT_EQ("VP8", vp8.name);
3316 EXPECT_EQ(120, vp8.id);
3317 cricket::CodecParameterMap::iterator found =
3318 vp8.params.find("x-google-min-bitrate");
3319 ASSERT_TRUE(found != vp8.params.end());
3320 EXPECT_EQ(found->second, "10");
3321 found = vp8.params.find("x-google-max-quantization");
3322 ASSERT_TRUE(found != vp8.params.end());
3323 EXPECT_EQ(found->second, "40");
3324}
3325
ossuaa4b0772017-01-30 07:41:18 -08003326TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003327 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003328
3329 cricket::AudioCodecs codecs = acd->codecs();
3330 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3331 acd->set_codecs(codecs);
3332
Yves Gerey665174f2018-06-19 15:03:05 +02003333 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003334 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003335 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003336 std::string sdp_with_fmtp = kSdpFullString;
3337 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3338 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3339 &sdp_with_fmtp);
3340 EXPECT_EQ(sdp_with_fmtp, message);
3341}
3342
3343TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003344 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003345
3346 cricket::AudioCodecs codecs = acd->codecs();
3347 codecs[0].params["stereo"] = "1";
3348 acd->set_codecs(codecs);
3349
Yves Gerey665174f2018-06-19 15:03:05 +02003350 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003351 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003352 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003353 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003354 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003355 &sdp_with_fmtp);
3356 EXPECT_EQ(sdp_with_fmtp, message);
3357}
3358
3359TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003360 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003361
3362 cricket::AudioCodecs codecs = acd->codecs();
3363 codecs[0].params["ptime"] = "20";
3364 codecs[0].params["maxptime"] = "120";
3365 acd->set_codecs(codecs);
3366
Yves Gerey665174f2018-06-19 15:03:05 +02003367 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003368 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003369 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003370 std::string sdp_with_fmtp = kSdpFullString;
3371 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3372 "a=maxptime:120\r\n" // No comma here. String merging!
3373 "a=ptime:20\r\n",
3374 &sdp_with_fmtp);
3375 EXPECT_EQ(sdp_with_fmtp, message);
3376}
3377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003379 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380
3381 cricket::VideoCodecs codecs = vcd->codecs();
3382 codecs[0].params["x-google-min-bitrate"] = "10";
3383 vcd->set_codecs(codecs);
3384
Yves Gerey665174f2018-06-19 15:03:05 +02003385 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003387 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388 std::string sdp_with_fmtp = kSdpFullString;
3389 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003390 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 EXPECT_EQ(sdp_with_fmtp, message);
3392}
3393
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003394TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3395 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003396 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 std::string sdp_with_icelite = kSdpFullString;
3398 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3399 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3400 const cricket::TransportInfo* tinfo1 =
3401 desc->GetTransportInfoByName("audio_content_name");
3402 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3403 const cricket::TransportInfo* tinfo2 =
3404 desc->GetTransportInfoByName("video_content_name");
3405 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003406
3407 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003408 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3410 desc = jdesc_with_icelite.description();
3411 const cricket::TransportInfo* atinfo =
3412 desc->GetTransportInfoByName("audio_content_name");
3413 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3414 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003415 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003417
3418 // Now that we know deserialization works, we can use TestSerialize to test
3419 // serialization.
3420 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421}
3422
3423// Verifies that the candidates in the input SDP are parsed and serialized
3424// correctly in the output SDP.
3425TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3426 std::string sdp_with_data = kSdpString;
3427 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003428 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429
3430 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003431 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003433
3434TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3435 AddFingerprint();
3436 TransportInfo audio_transport_info =
3437 *(desc_.GetTransportInfoByName(kAudioContentName));
3438 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3439 audio_transport_info.description.connection_role);
3440 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003441 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003442
3443 TransportInfo video_transport_info =
3444 *(desc_.GetTransportInfoByName(kVideoContentName));
3445 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3446 video_transport_info.description.connection_role);
3447 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003448 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003449
3450 desc_.RemoveTransportInfoByName(kAudioContentName);
3451 desc_.RemoveTransportInfoByName(kVideoContentName);
3452
3453 desc_.AddTransportInfo(audio_transport_info);
3454 desc_.AddTransportInfo(video_transport_info);
3455
Yves Gerey665174f2018-06-19 15:03:05 +02003456 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003457 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003458 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003459 std::string sdp_with_dtlssetup = kSdpFullString;
3460
3461 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003462 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3463 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003464 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003465 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003466 EXPECT_EQ(sdp_with_dtlssetup, message);
3467}
3468
3469TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003470 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003471 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003472 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003473 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3474 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3475 const cricket::TransportInfo* atinfo =
3476 desc->GetTransportInfoByName("audio_content_name");
3477 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3478 atinfo->description.connection_role);
3479 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003480 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003481 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3482 vtinfo->description.connection_role);
3483}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003484
3485// Verifies that the order of the serialized m-lines follows the order of the
3486// ContentInfo in SessionDescription, and vise versa for deserialization.
3487TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003488 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003489 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3490 kSdpSctpDataChannelString};
3491 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3492 cricket::MEDIA_TYPE_VIDEO,
3493 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003494
3495 // Verifies all 6 permutations.
3496 for (size_t i = 0; i < 6; ++i) {
3497 size_t media_content_in_sdp[3];
3498 // The index of the first media content.
3499 media_content_in_sdp[0] = i / 2;
3500 // The index of the second media content.
3501 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3502 // The index of the third media content.
3503 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3504
3505 std::string sdp_string = kSdpSessionString;
3506 for (size_t i = 0; i < 3; ++i)
3507 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3508
3509 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3510 cricket::SessionDescription* desc = jdesc.description();
3511 EXPECT_EQ(3u, desc->contents().size());
3512
3513 for (size_t i = 0; i < 3; ++i) {
3514 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003515 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003516 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3517 }
3518
Steve Antone831b8c2018-02-01 12:22:16 -08003519 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003520 EXPECT_EQ(sdp_string, serialized_sdp);
3521 }
3522}
deadbeef9d3584c2016-02-16 17:54:10 -08003523
deadbeef25ed4352016-12-12 18:37:36 -08003524TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3525 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003526 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003527 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003528 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3529 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3530}
3531
deadbeef12771a12017-01-03 13:53:47 -08003532// The semantics of "a=bundle-only" are only defined when it's used in
3533// combination with a 0 port on the m= line. We should ignore it if used with a
3534// nonzero port.
3535TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3536 // Make the base bundle-only description but unset the bundle-only flag.
3537 MakeBundleOnlyDescription();
3538 jdesc_.description()->contents()[1].bundle_only = false;
3539
3540 std::string modified_sdp = kBundleOnlySdpFullString;
3541 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003542 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003543 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3544 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003545}
3546
3547TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3548 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003549 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003550}
3551
deadbeef9d3584c2016-02-16 17:54:10 -08003552TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3553 MakePlanBDescription();
3554
Steve Antona3a92c22017-12-07 10:27:41 -08003555 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003556 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3557
3558 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3559}
3560
3561TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3562 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003563 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003564}
3565
3566TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3567 MakeUnifiedPlanDescription();
3568
Steve Antona3a92c22017-12-07 10:27:41 -08003569 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003570 EXPECT_TRUE(
3571 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3572
3573 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3574}
3575
3576TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3577 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003578 TestSerialize(jdesc_);
3579}
3580
Seth Hampson5b4f0752018-04-02 16:31:36 -07003581// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003582// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3583// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003584// with no stream ids and multiple stream ids. For parsing this, the Unified
3585// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3586// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003587TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3588 // Create both msid lines for Plan B and Unified Plan support.
3589 MakeUnifiedPlanDescriptionMultipleStreamIds(
3590 cricket::kMsidSignalingMediaSection |
3591 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003592
3593 JsepSessionDescription deserialized_description(kDummyType);
3594 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3595 &deserialized_description));
3596
3597 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003598 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3599 cricket::kMsidSignalingSsrcAttribute,
3600 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003601}
3602
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003603// Tests the serialization of a Unified Plan SDP that is compatible for both
3604// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3605// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3606// multiple stream ids.
3607TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3608 // Create both msid lines for Plan B and Unified Plan support.
3609 MakeUnifiedPlanDescriptionMultipleStreamIds(
3610 cricket::kMsidSignalingMediaSection |
3611 cricket::kMsidSignalingSsrcAttribute);
3612 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3613 // We explicitly test that the serialized SDP string is equal to the hard
3614 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3615 // take priority over "a=ssrc msid" lines. This means if we just used
3616 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3617 // and still pass, because the deserialized version would be the same.
3618 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3619}
3620
3621// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3622// that signal stream IDs) is deserialized appropriately. It tests the case for
3623// no stream ids and multiple stream ids.
3624TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3625 // Only create a=msid lines for strictly Unified Plan stream ID support.
3626 MakeUnifiedPlanDescriptionMultipleStreamIds(
3627 cricket::kMsidSignalingMediaSection);
3628
3629 JsepSessionDescription deserialized_description(kDummyType);
3630 std::string unified_plan_sdp_string =
3631 kUnifiedPlanSdpFullStringWithSpecialMsid;
3632 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3633 EXPECT_TRUE(
3634 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3635
3636 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3637}
3638
3639// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3640// that signal stream IDs) is serialized appropriately. It tests the case for no
3641// stream ids and multiple stream ids.
3642TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3643 // Only create a=msid lines for strictly Unified Plan stream ID support.
3644 MakeUnifiedPlanDescriptionMultipleStreamIds(
3645 cricket::kMsidSignalingMediaSection);
3646
Seth Hampson5b4f0752018-04-02 16:31:36 -07003647 TestSerialize(jdesc_);
3648}
3649
Seth Hampson5897a6e2018-04-03 11:16:33 -07003650// This tests that a Unified Plan SDP with no a=ssrc lines is
3651// serialized/deserialized appropriately. In this case the
3652// MediaContentDescription will contain a StreamParams object that doesn't have
3653// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3654// SSRC lines.
3655TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3656 MakeUnifiedPlanDescription();
3657 RemoveSsrcSignalingFromStreamParams();
3658 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3659 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3660
3661 JsepSessionDescription deserialized_description(kDummyType);
3662 EXPECT_TRUE(
3663 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3664 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3665}
3666
3667TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3668 MakeUnifiedPlanDescription();
3669 RemoveSsrcSignalingFromStreamParams();
3670
3671 TestSerialize(jdesc_);
3672}
3673
Steve Antone831b8c2018-02-01 12:22:16 -08003674TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3675 JsepSessionDescription jsep_desc(kDummyType);
3676 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3677 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3678}
3679
3680TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3681 JsepSessionDescription jsep_desc(kDummyType);
3682 std::string sdp = kSdpSessionString;
3683 sdp += kSdpSctpDataChannelString;
3684 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3685 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3686}
3687
3688TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3689 JsepSessionDescription jsep_desc(kDummyType);
3690 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3691 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3692 jsep_desc.description()->msid_signaling());
3693}
3694
3695TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3696 JsepSessionDescription jsep_desc(kDummyType);
3697 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3698 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3699 jsep_desc.description()->msid_signaling());
3700}
3701
3702const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3703const char kSsrcAttributeMsidLine[] =
3704 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3705
3706TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3707 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3708 std::string sdp = webrtc::SdpSerialize(jdesc_);
3709
3710 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3711 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3712}
3713
3714TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3715 jdesc_.description()->set_msid_signaling(
3716 cricket::kMsidSignalingSsrcAttribute);
3717 std::string sdp = webrtc::SdpSerialize(jdesc_);
3718
3719 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3720 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3721}
3722
3723TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3724 jdesc_.description()->set_msid_signaling(
3725 cricket::kMsidSignalingMediaSection |
3726 cricket::kMsidSignalingSsrcAttribute);
3727 std::string sdp = webrtc::SdpSerialize(jdesc_);
3728
3729 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3730 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003731}
deadbeef7e146cb2016-09-28 10:04:34 -07003732
3733// Regression test for heap overflow bug:
3734// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3735TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003736 // The issue occurs when the sctp-port attribute is found in a video
3737 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003738 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003739 "v=0\r\n"
3740 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3741 "s=-\r\n"
3742 "t=0 0\r\n"
3743 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3744 "a=sctp-port 5000\r\n"
3745 "a=fmtp:108 foo=10\r\n";
3746
3747 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3748 "sctp-port");
3749}
deadbeefb2362572016-12-13 16:37:06 -08003750
3751// Regression test for integer overflow bug:
3752// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3753TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003754 // Bandwidth attribute is the max signed 32-bit int, which will get
3755 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003756 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003757 "v=0\r\n"
3758 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3759 "s=-\r\n"
3760 "t=0 0\r\n"
3761 "m=video 3457 RTP/SAVPF 120\r\n"
3762 "b=AS:2147483647\r\n"
3763 "foo=fail\r\n";
3764
3765 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3766}
deadbeef7bcdb692017-01-20 12:43:58 -08003767
deadbeefbc88c6b2017-08-02 11:26:34 -07003768// Similar to the above, except that negative values are illegal, not just
3769// error-prone as large values are.
3770// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3771TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3772 static const char kSdpWithNegativeBandwidth[] =
3773 "v=0\r\n"
3774 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3775 "s=-\r\n"
3776 "t=0 0\r\n"
3777 "m=video 3457 RTP/SAVPF 120\r\n"
3778 "b=AS:-1000\r\n";
3779
3780 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3781}
3782
deadbeef3e8016e2017-08-03 17:49:30 -07003783// An exception to the above rule: a value of -1 for b=AS should just be
3784// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3785// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3786// limit", but this is now what ommitting the attribute entirely will do, so
3787// ignoring it will have the intended effect.
3788TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3789 static const char kSdpWithBandwidthOfNegativeOne[] =
3790 "v=0\r\n"
3791 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3792 "s=-\r\n"
3793 "t=0 0\r\n"
3794 "m=video 3457 RTP/SAVPF 120\r\n"
3795 "b=AS:-1\r\n";
3796
Steve Antona3a92c22017-12-07 10:27:41 -08003797 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003798 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003799 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003800 GetFirstVideoContentDescription(jdesc_output.description());
3801 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003802 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3803}
3804
deadbeef7bcdb692017-01-20 12:43:58 -08003805// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3806// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3807// Regression test for:
3808// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3809TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3810 // Important piece is "ufrag foo pwd bar".
3811 static const char kSdpWithIceCredentialsInCandidateString[] =
3812 "v=0\r\n"
3813 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3814 "s=-\r\n"
3815 "t=0 0\r\n"
3816 "m=audio 9 RTP/SAVPF 111\r\n"
3817 "c=IN IP4 0.0.0.0\r\n"
3818 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3819 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3820 "a=rtpmap:111 opus/48000/2\r\n"
3821 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3822 "generation 2 ufrag foo pwd bar\r\n";
3823
Steve Antona3a92c22017-12-07 10:27:41 -08003824 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003825 EXPECT_TRUE(
3826 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3827 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3828 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003829 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003830 cricket::Candidate c = candidates->at(0)->candidate();
3831 EXPECT_EQ("ufrag_voice", c.username());
3832 EXPECT_EQ("pwd_voice", c.password());
3833}
deadbeef90f1e1e2017-02-10 12:35:05 -08003834
Johannes Kron211856b2018-09-06 12:12:28 +02003835// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3836// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3837// Regression test for:
3838// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3839TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3840 static const char kSdpWithFooIceCredentials[] =
3841 "v=0\r\n"
3842 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3843 "s=-\r\n"
3844 "t=0 0\r\n"
3845 "m=audio 9 RTP/SAVPF 111\r\n"
3846 "c=IN IP4 0.0.0.0\r\n"
3847 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3848 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3849 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3850 "a=rtpmap:111 opus/48000/2\r\n"
3851 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3852 "generation 2\r\n";
3853
3854 JsepSessionDescription jdesc_output(kDummyType);
3855 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3856 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3857 ASSERT_NE(nullptr, candidates);
3858 ASSERT_EQ(1U, candidates->count());
3859 cricket::Candidate c = candidates->at(0)->candidate();
3860 EXPECT_EQ("ufrag_voice", c.username());
3861 EXPECT_EQ("pwd_voice", c.password());
3862}
3863
deadbeef90f1e1e2017-02-10 12:35:05 -08003864// Test that SDP with an invalid port number in "a=candidate" lines is
3865// rejected, without crashing.
3866// Regression test for:
3867// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3868TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3869 static const char kSdpWithInvalidCandidatePort[] =
3870 "v=0\r\n"
3871 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3872 "s=-\r\n"
3873 "t=0 0\r\n"
3874 "m=audio 9 RTP/SAVPF 111\r\n"
3875 "c=IN IP4 0.0.0.0\r\n"
3876 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3877 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3878 "a=rtpmap:111 opus/48000/2\r\n"
3879 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3880 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3881
Steve Antona3a92c22017-12-07 10:27:41 -08003882 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003883 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3884}
deadbeefa4549d62017-02-10 17:26:22 -08003885
3886// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3887// Regression test for:
3888// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3889TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3890 static const char kSdpWithMissingTrackId[] =
3891 "v=0\r\n"
3892 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3893 "s=-\r\n"
3894 "t=0 0\r\n"
3895 "m=audio 9 RTP/SAVPF 111\r\n"
3896 "c=IN IP4 0.0.0.0\r\n"
3897 "a=rtpmap:111 opus/48000/2\r\n"
3898 "a=msid:stream_id \r\n";
3899
Steve Antona3a92c22017-12-07 10:27:41 -08003900 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003901 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3902}
3903
3904TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3905 static const char kSdpWithMissingStreamId[] =
3906 "v=0\r\n"
3907 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3908 "s=-\r\n"
3909 "t=0 0\r\n"
3910 "m=audio 9 RTP/SAVPF 111\r\n"
3911 "c=IN IP4 0.0.0.0\r\n"
3912 "a=rtpmap:111 opus/48000/2\r\n"
3913 "a=msid: track_id\r\n";
3914
Steve Antona3a92c22017-12-07 10:27:41 -08003915 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003916 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3917}
zhihuang38989e52017-03-21 11:04:53 -07003918
3919// Tests that if both session-level address and media-level address exist, use
3920// the media-level address.
3921TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003922 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003923
3924 // Sesssion-level address.
3925 std::string sdp = kSdpFullString;
3926 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3927 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3928
3929 const auto& content1 = jsep_desc.description()->contents()[0];
3930 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003931 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003932 const auto& content2 = jsep_desc.description()->contents()[1];
3933 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003934 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003935}
3936
3937// Tests that the session-level connection address will be used if the media
3938// level-addresses are not specified.
3939TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003940 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003941
3942 // Sesssion-level address.
3943 std::string sdp = kSdpString;
3944 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3945 // Remove the media level addresses.
3946 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3947 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3948 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3949
3950 const auto& content1 = jsep_desc.description()->contents()[0];
3951 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003952 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003953 const auto& content2 = jsep_desc.description()->contents()[1];
3954 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003955 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003956}
3957
3958TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003959 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003960
3961 std::string sdp = kSdpString;
3962 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3963 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3964 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3965 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3966 &sdp);
3967 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3968 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3969 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3970 &sdp);
3971 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3972 const auto& content1 = jsep_desc.description()->contents()[0];
3973 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003974 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003975 const auto& content2 = jsep_desc.description()->contents()[1];
3976 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003977 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003978}
3979
Qingsi Wang56991422019-02-08 12:53:06 -08003980// Test that a c= line that contains a hostname connection address can be
3981// parsed.
3982TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
3983 JsepSessionDescription jsep_desc(kDummyType);
3984 std::string sdp = kSdpString;
3985 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3986
3987 sdp = kSdpString;
3988 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
3989 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
3990 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3991
3992 ASSERT_NE(nullptr, jsep_desc.description());
3993 const auto& content1 = jsep_desc.description()->contents()[0];
3994 EXPECT_EQ("example.local:9",
3995 content1.media_description()->connection_address().ToString());
3996 const auto& content2 = jsep_desc.description()->contents()[1];
3997 EXPECT_EQ("example.local:9",
3998 content2.media_description()->connection_address().ToString());
3999}
4000
4001// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004002TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004003 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004004 std::string sdp = kSdpString;
4005 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4006
4007 // Unsupported multicast IPv4 address.
4008 sdp = kSdpFullString;
4009 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4010 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4011
4012 // Unsupported multicast IPv6 address.
4013 sdp = kSdpFullString;
4014 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4015 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4016
4017 // Mismatched address type.
4018 sdp = kSdpFullString;
4019 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4020 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4021
4022 sdp = kSdpFullString;
4023 Replace("c=IN IP4 74.125.224.39\r\n",
4024 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4025 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4026}
4027
4028TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004029 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004030 MakeDescriptionWithoutCandidates(&expected_jsep);
4031 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004032 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004033 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004034 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004035 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004036 auto audio_desc = jdesc.description()
4037 ->GetContentByName(kAudioContentName)
4038 ->media_description();
4039 auto video_desc = jdesc.description()
4040 ->GetContentByName(kVideoContentName)
4041 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004042 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4043 audio_desc->connection_address().ToString());
4044 EXPECT_EQ(video_desc_->connection_address().ToString(),
4045 video_desc->connection_address().ToString());
4046}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004047
Qingsi Wang56991422019-02-08 12:53:06 -08004048// Test that a media description that contains a hostname connection address can
4049// be correctly serialized.
4050TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4051 JsepSessionDescription expected_jsep(kDummyType);
4052 cricket::Candidate c;
4053 const rtc::SocketAddress hostname_addr("example.local", 1234);
4054 audio_desc_->set_connection_address(hostname_addr);
4055 video_desc_->set_connection_address(hostname_addr);
4056 ASSERT_TRUE(
4057 expected_jsep.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
4058 // Serialization.
4059 std::string message = webrtc::SdpSerialize(expected_jsep);
4060 // Deserialization.
4061 JsepSessionDescription jdesc(kDummyType);
4062 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4063 auto audio_desc = jdesc.description()
4064 ->GetContentByName(kAudioContentName)
4065 ->media_description();
4066 auto video_desc = jdesc.description()
4067 ->GetContentByName(kVideoContentName)
4068 ->media_description();
4069 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4070 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4071}
4072
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004073// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4074// used (i.e., a single space as the session name)." So we should accept that.
4075TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4076 JsepSessionDescription jsep_desc(kDummyType);
4077 std::string sdp = kSdpString;
4078 Replace("s=-\r\n", "s= \r\n", &sdp);
4079 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4080}
Amit Hilbucha2012042018-12-03 11:35:05 -08004081
4082// Simulcast malformed input test for invalid format.
4083TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4084 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4085 "a=simulcast:\r\n", "a=simulcast:");
4086}
4087
4088// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4089TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4090 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4091 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4092 "a=simulcast:");
4093}
4094
4095// Validates that deserialization uses the a=simulcast: attribute
4096TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004097 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4098 sdp += "a=rid:1 send\r\n";
4099 sdp += "a=rid:2 send\r\n";
4100 sdp += "a=rid:3 send\r\n";
4101 sdp += "a=rid:4 recv\r\n";
4102 sdp += "a=rid:5 recv\r\n";
4103 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004104 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4105 JsepSessionDescription output(kDummyType);
4106 SdpParseError error;
4107 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4108 const cricket::ContentInfos& contents = output.description()->contents();
4109 const cricket::MediaContentDescription* media =
4110 contents.back().media_description();
4111 EXPECT_TRUE(media->HasSimulcast());
4112 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4113 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004114 EXPECT_FALSE(media->streams().empty());
4115 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4116 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004117}
4118
4119// Validates that deserialization removes rids that do not appear in SDP
4120TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4121 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4122 sdp += "a=rid:1 send\r\n";
4123 sdp += "a=rid:3 send\r\n";
4124 sdp += "a=rid:4 recv\r\n";
4125 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4126 JsepSessionDescription output(kDummyType);
4127 SdpParseError error;
4128 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4129 const cricket::ContentInfos& contents = output.description()->contents();
4130 const cricket::MediaContentDescription* media =
4131 contents.back().media_description();
4132 EXPECT_TRUE(media->HasSimulcast());
4133 const SimulcastDescription& simulcast = media->simulcast_description();
4134 EXPECT_EQ(2ul, simulcast.send_layers().size());
4135 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4136
4137 std::vector<SimulcastLayer> all_send_layers =
4138 simulcast.send_layers().GetAllLayers();
4139 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004140 EXPECT_EQ(0,
4141 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4142 return layer.rid == "2";
4143 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004144
4145 std::vector<SimulcastLayer> all_receive_layers =
4146 simulcast.receive_layers().GetAllLayers();
4147 ASSERT_EQ(1ul, all_receive_layers.size());
4148 EXPECT_EQ("4", all_receive_layers[0].rid);
4149
4150 EXPECT_FALSE(media->streams().empty());
4151 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4152 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004153}
4154
4155// Validates that Simulcast removes rids that appear in both send and receive.
4156TEST_F(WebRtcSdpTest,
4157 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4158 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4159 sdp += "a=rid:1 send\r\n";
4160 sdp += "a=rid:2 send\r\n";
4161 sdp += "a=rid:3 send\r\n";
4162 sdp += "a=rid:4 recv\r\n";
4163 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4164 JsepSessionDescription output(kDummyType);
4165 SdpParseError error;
4166 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4167 const cricket::ContentInfos& contents = output.description()->contents();
4168 const cricket::MediaContentDescription* media =
4169 contents.back().media_description();
4170 EXPECT_TRUE(media->HasSimulcast());
4171 const SimulcastDescription& simulcast = media->simulcast_description();
4172 EXPECT_EQ(2ul, simulcast.send_layers().size());
4173 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4174 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4175 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4176
4177 EXPECT_FALSE(media->streams().empty());
4178 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4179 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004180}
4181
4182// Ignores empty rid line.
4183TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4184 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4185 sdp += "a=rid:1 send\r\n";
4186 sdp += "a=rid:2 send\r\n";
4187 sdp += "a=rid\r\n"; // Should ignore this line.
4188 sdp += "a=rid:\r\n"; // Should ignore this line.
4189 sdp += "a=simulcast:send 1;2\r\n";
4190 JsepSessionDescription output(kDummyType);
4191 SdpParseError error;
4192 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4193 const cricket::ContentInfos& contents = output.description()->contents();
4194 const cricket::MediaContentDescription* media =
4195 contents.back().media_description();
4196 EXPECT_TRUE(media->HasSimulcast());
4197 const SimulcastDescription& simulcast = media->simulcast_description();
4198 EXPECT_TRUE(simulcast.receive_layers().empty());
4199 EXPECT_EQ(2ul, simulcast.send_layers().size());
4200 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4201
4202 EXPECT_FALSE(media->streams().empty());
4203 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4204 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004205}
4206
4207// Ignores malformed rid lines.
4208TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4209 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4210 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4211 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4212 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4213 sdp += "a=rid:4\r\n"; // Should ignore this line.
4214 sdp += "a=rid:5 send\r\n";
4215 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4216 JsepSessionDescription output(kDummyType);
4217 SdpParseError error;
4218 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4219 const cricket::ContentInfos& contents = output.description()->contents();
4220 const cricket::MediaContentDescription* media =
4221 contents.back().media_description();
4222 EXPECT_TRUE(media->HasSimulcast());
4223 const SimulcastDescription& simulcast = media->simulcast_description();
4224 EXPECT_TRUE(simulcast.receive_layers().empty());
4225 EXPECT_EQ(1ul, simulcast.send_layers().size());
4226 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4227
4228 EXPECT_FALSE(media->streams().empty());
4229 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4230 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004231}
4232
4233// Removes RIDs that specify a different format than the m= section.
4234TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4235 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4236 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4237 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4238 sdp += "a=simulcast:send 1;2\r\n";
4239 JsepSessionDescription output(kDummyType);
4240 SdpParseError error;
4241 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4242 const cricket::ContentInfos& contents = output.description()->contents();
4243 const cricket::MediaContentDescription* media =
4244 contents.back().media_description();
4245 EXPECT_TRUE(media->HasSimulcast());
4246 const SimulcastDescription& simulcast = media->simulcast_description();
4247 EXPECT_TRUE(simulcast.receive_layers().empty());
4248 EXPECT_EQ(1ul, simulcast.send_layers().size());
4249 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4250 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4251 EXPECT_EQ(1ul, media->streams().size());
4252 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4253 EXPECT_EQ(1ul, rids.size());
4254 EXPECT_EQ("1", rids[0].rid);
4255 EXPECT_EQ(1ul, rids[0].payload_types.size());
4256 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004257}
4258
4259// Ignores duplicate rid lines
4260TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4261 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4262 sdp += "a=rid:1 send\r\n";
4263 sdp += "a=rid:2 send\r\n";
4264 sdp += "a=rid:2 send\r\n";
4265 sdp += "a=rid:3 send\r\n";
4266 sdp += "a=rid:4 recv\r\n";
4267 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4268 JsepSessionDescription output(kDummyType);
4269 SdpParseError error;
4270 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4271 const cricket::ContentInfos& contents = output.description()->contents();
4272 const cricket::MediaContentDescription* media =
4273 contents.back().media_description();
4274 EXPECT_TRUE(media->HasSimulcast());
4275 const SimulcastDescription& simulcast = media->simulcast_description();
4276 EXPECT_EQ(2ul, simulcast.send_layers().size());
4277 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4278 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4279 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4280
4281 EXPECT_FALSE(media->streams().empty());
4282 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4283 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004284}
4285
4286// Simulcast serialization integration test.
4287// This test will serialize and deserialize the description and compare.
4288// More detailed tests for parsing simulcast can be found in
4289// unit tests for SdpSerializer.
4290TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004291 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004292 auto description = jdesc_.description();
4293 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004294 ASSERT_EQ(media->streams().size(), 1ul);
4295 StreamParams& send_stream = media->mutable_streams()[0];
4296 std::vector<RidDescription> send_rids;
4297 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4298 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4299 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4300 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4301 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004302
Amit Hilbucha2012042018-12-03 11:35:05 -08004303 SimulcastDescription& simulcast = media->simulcast_description();
4304 simulcast.send_layers().AddLayerWithAlternatives(
4305 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4306 simulcast.send_layers().AddLayerWithAlternatives(
4307 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4308
Amit Hilbucha2012042018-12-03 11:35:05 -08004309 TestSerialize(jdesc_);
4310}
Steve Anton06817cd2018-12-18 15:55:30 -08004311
4312// Test that the content name is empty if the media section does not have an
4313// a=mid line.
4314TEST_F(WebRtcSdpTest, ParseNoMid) {
4315 std::string sdp = kSdpString;
4316 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4317 Replace("a=mid:video_content_name\r\n", "", &sdp);
4318
4319 JsepSessionDescription output(kDummyType);
4320 SdpParseError error;
4321 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4322
4323 EXPECT_THAT(output.description()->contents(),
4324 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4325 Field("name", &cricket::ContentInfo::name, "")));
4326}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004327
4328// Test that the media transport name and base64-decoded setting is parsed from
4329// an a=x-mt line.
4330TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4331 JsepSessionDescription output(kDummyType);
4332 std::string sdp = kSdpSessionString;
4333 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4334 SdpParseError error;
4335
4336 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4337 << error.description;
4338 const auto& settings = output.description()->MediaTransportSettings();
4339 ASSERT_EQ(1u, settings.size());
4340 EXPECT_EQ("rtp", settings[0].transport_name);
4341 EXPECT_EQ("test64", settings[0].transport_setting);
4342}
4343
4344// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4345TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4346 JsepSessionDescription output(kDummyType);
4347 std::string sdp = kSdpSessionString;
4348 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4349 SdpParseError error;
4350
4351 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4352}
4353
4354// Test that multiple a=x-mt lines are parsed in the order of preference (the
4355// order of the lines in the SDP).
4356TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4357 JsepSessionDescription output(kDummyType);
4358 std::string sdp = kSdpSessionString;
4359 sdp +=
4360 "a=x-mt:rtp:dGVzdDY0\r\n"
4361 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4362 SdpParseError error;
4363
4364 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4365 << error.description;
4366 const auto& settings = output.description()->MediaTransportSettings();
4367 ASSERT_EQ(2u, settings.size());
4368 EXPECT_EQ("rtp", settings[0].transport_name);
4369 EXPECT_EQ("test64", settings[0].transport_setting);
4370 EXPECT_EQ("generic", settings[1].transport_name);
4371 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4372}
4373
4374// Test that only the first a=x-mt line associated with a transport name is
4375// parsed and the rest ignored.
4376TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4377 JsepSessionDescription output(kDummyType);
4378 std::string sdp = kSdpSessionString;
4379 sdp +=
4380 "a=x-mt:rtp:dGVzdDY0\r\n"
4381 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4382 SdpParseError error;
4383
4384 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4385 // but ignore the repeated transport.
4386 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4387 const auto& settings = output.description()->MediaTransportSettings();
4388 EXPECT_EQ("test64", settings[0].transport_setting);
4389}
4390
4391// Test that an a=x-mt line fails to parse if it is missing a setting.
4392TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4393 JsepSessionDescription output(kDummyType);
4394 std::string sdp = kSdpSessionString;
4395 sdp += "a=x-mt:rtp\r\n";
4396 SdpParseError error;
4397
4398 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4399}
4400
4401// Test that an a=x-mt line fails to parse if its missing a name and setting.
4402TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4403 JsepSessionDescription output(kDummyType);
4404 std::string sdp = kSdpSessionString;
4405 sdp += "a=x-mt\r\n";
4406 SdpParseError error;
4407
4408 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4409}
4410
4411TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4412 JsepSessionDescription output(kDummyType);
4413 std::string sdp = kSdpSessionString;
4414 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4415 SdpParseError error;
4416
4417 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4418 << error.description;
4419 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4420}