blob: 2be454ffc9982bb1658631314bad8c2264dd891b [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <vector>
21
Steve Anton64b626b2019-01-28 17:25:26 -080022#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -080023#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080024#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020035#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 15:55:30 -080045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020047
ossu7bb87ee2017-01-23 04:56:25 -080048#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080050#endif
Steve Anton10542f22019-01-11 09:11:00 -080051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080066using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020068using cricket::RtpDataContentDescription;
69using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080070using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080071using cricket::SimulcastDescription;
72using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using cricket::StreamParams;
74using cricket::STUN_PORT_TYPE;
75using cricket::TransportDescription;
76using cricket::TransportInfo;
77using cricket::VideoCodec;
78using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080079using ::testing::ElementsAre;
80using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::IceCandidateCollection;
82using webrtc::IceCandidateInterface;
83using webrtc::JsepIceCandidate;
84using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070085using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080086using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080088using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::SessionDescriptionInterface;
90
91typedef std::vector<AudioCodec> AudioCodecs;
92typedef std::vector<Candidate> Candidates;
93
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080095static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020097static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080098static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -0800100static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const char kCandidateFoundation1[] = "a0+B/1";
104static const char kCandidateFoundation2[] = "a0+B/2";
105static const char kCandidateFoundation3[] = "a0+B/3";
106static const char kCandidateFoundation4[] = "a0+B/4";
107static const char kAttributeCryptoVoice[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
109 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
110 "dummy_session_params\r\n";
111static const char kAttributeCryptoVideo[] =
112 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
113 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200114static const char kFingerprint[] =
115 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 "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 +0200117static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118static const int kExtmapId = 1;
119static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
120static const char kExtmap[] =
121 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
122static const char kExtmapWithDirectionAndAttribute[] =
123 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700124static const char kExtmapWithDirectionAndAttributeEncrypted[] =
125 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
126 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
Peter Boström0c4e06b2015-10-07 12:23:21 +0200128static const uint8_t kIdentityDigest[] = {
129 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
130 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
lally@webrtc.org34807282015-02-24 20:19:39 +0000132static const char kDtlsSctp[] = "DTLS/SCTP";
133static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
134static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136struct CodecParams {
137 int max_ptime;
138 int ptime;
139 int min_ptime;
140 int sprop_stereo;
141 int stereo;
142 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000143 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144};
145
deadbeef9d3584c2016-02-16 17:54:10 -0800146// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
147// instead of "a=crypto", and have an explicit test for adding "a=crypto".
148// Currently it's the other way around.
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150// Reference sdp string
151static const char kSdpFullString[] =
152 "v=0\r\n"
153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
154 "s=-\r\n"
155 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800156 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
158 "c=IN IP4 74.125.127.126\r\n"
159 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
169 "raddr 192.168.1.5 rport 2346 "
170 "generation 2\r\n"
171 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
172 "raddr 192.168.1.5 rport 2348 "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
175 "a=mid:audio_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800178 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
180 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
181 "dummy_session_params\r\n"
182 "a=rtpmap:111 opus/48000/2\r\n"
183 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000184 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 "a=ssrc:1 cname:stream_1_cname\r\n"
186 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
187 "a=ssrc:1 mslabel:local_stream_1\r\n"
188 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 "m=video 3457 RTP/SAVPF 120\r\n"
190 "c=IN IP4 74.125.224.39\r\n"
191 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
192 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
199 "generation 2\r\n"
200 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
201 "generation 2\r\n"
202 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
203 "generation 2\r\n"
204 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
205 "a=mid:video_content_name\r\n"
206 "a=sendrecv\r\n"
207 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
208 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
209 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800210 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:2 cname:stream_1_cname\r\n"
212 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
213 "a=ssrc:2 mslabel:local_stream_1\r\n"
214 "a=ssrc:2 label:video_track_id_1\r\n"
215 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800216 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800218 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219
220// SDP reference string without the candidates.
221static const char kSdpString[] =
222 "v=0\r\n"
223 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
224 "s=-\r\n"
225 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000227 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000228 "c=IN IP4 0.0.0.0\r\n"
229 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
231 "a=mid:audio_content_name\r\n"
232 "a=sendrecv\r\n"
233 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800234 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
236 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
237 "dummy_session_params\r\n"
238 "a=rtpmap:111 opus/48000/2\r\n"
239 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000240 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 "a=ssrc:1 cname:stream_1_cname\r\n"
242 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
243 "a=ssrc:1 mslabel:local_stream_1\r\n"
244 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000245 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000246 "c=IN IP4 0.0.0.0\r\n"
247 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
249 "a=mid:video_content_name\r\n"
250 "a=sendrecv\r\n"
251 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
252 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
253 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800254 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 "a=ssrc:2 cname:stream_1_cname\r\n"
256 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
257 "a=ssrc:2 mslabel:local_stream_1\r\n"
258 "a=ssrc:2 label:video_track_id_1\r\n"
259 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800260 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800262 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
264static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000265 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000266 "c=IN IP4 0.0.0.0\r\n"
267 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n"
271 "a=sendrecv\r\n"
272 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
273 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
274 "a=rtpmap:101 google-data/90000\r\n"
275 "a=ssrc:10 cname:data_channel_cname\r\n"
276 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
277 "a=ssrc:10 mslabel:data_channel\r\n"
278 "a=ssrc:10 label:data_channeld0\r\n";
279
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200280// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000282 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000283 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000287 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000289// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200290// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
291// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000292static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000293 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000294 "a=sctp-port 5000\r\n"
295 "c=IN IP4 0.0.0.0\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n";
299
Harald Alvestrand48cce4d2019-04-11 10:41:24 +0200300// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 10:15:04 -0700301static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000302 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 10:15:04 -0700303 "a=sctp-port:5000\r\n"
304 "c=IN IP4 0.0.0.0\r\n"
305 "a=ice-ufrag:ufrag_data\r\n"
306 "a=ice-pwd:pwd_data\r\n"
307 "a=mid:data_content_name\r\n";
308
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000310 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 "c=IN IP4 74.125.127.126\r\n"
312 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
317 "raddr 192.168.1.5 rport 2346 "
318 "generation 2\r\n"
319 "a=ice-ufrag:ufrag_data\r\n"
320 "a=ice-pwd:pwd_data\r\n"
321 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000322 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000324static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000325 "v=0\r\n"
326 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
327 "s=-\r\n"
328 "t=0 0\r\n"
329 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000330 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000331 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000335 "a=x-google-flag:conference\r\n";
336
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000337static const char kSdpSessionString[] =
338 "v=0\r\n"
339 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
340 "s=-\r\n"
341 "t=0 0\r\n"
342 "a=msid-semantic: WMS local_stream\r\n";
343
344static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000345 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000346 "c=IN IP4 0.0.0.0\r\n"
347 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000348 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
349 "a=mid:audio_content_name\r\n"
350 "a=sendrecv\r\n"
351 "a=rtpmap:111 opus/48000/2\r\n"
352 "a=ssrc:1 cname:stream_1_cname\r\n"
353 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
354 "a=ssrc:1 mslabel:local_stream\r\n"
355 "a=ssrc:1 label:audio_track_id_1\r\n";
356
357static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000358 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000359 "c=IN IP4 0.0.0.0\r\n"
360 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000361 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
362 "a=mid:video_content_name\r\n"
363 "a=sendrecv\r\n"
364 "a=rtpmap:120 VP8/90000\r\n"
365 "a=ssrc:2 cname:stream_1_cname\r\n"
366 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
367 "a=ssrc:2 mslabel:local_stream\r\n"
368 "a=ssrc:2 label:video_track_id_1\r\n";
369
deadbeef25ed4352016-12-12 18:37:36 -0800370// Reference sdp string using bundle-only.
371static const char kBundleOnlySdpFullString[] =
372 "v=0\r\n"
373 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
374 "s=-\r\n"
375 "t=0 0\r\n"
376 "a=group:BUNDLE audio_content_name video_content_name\r\n"
377 "a=msid-semantic: WMS local_stream_1\r\n"
378 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
379 "c=IN IP4 74.125.127.126\r\n"
380 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
381 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
388 "generation 2\r\n"
389 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
390 "raddr 192.168.1.5 rport 2346 "
391 "generation 2\r\n"
392 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
393 "raddr 192.168.1.5 rport 2348 "
394 "generation 2\r\n"
395 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
396 "a=mid:audio_content_name\r\n"
397 "a=sendrecv\r\n"
398 "a=rtcp-mux\r\n"
399 "a=rtcp-rsize\r\n"
400 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
401 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
402 "dummy_session_params\r\n"
403 "a=rtpmap:111 opus/48000/2\r\n"
404 "a=rtpmap:103 ISAC/16000\r\n"
405 "a=rtpmap:104 ISAC/32000\r\n"
406 "a=ssrc:1 cname:stream_1_cname\r\n"
407 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
408 "a=ssrc:1 mslabel:local_stream_1\r\n"
409 "a=ssrc:1 label:audio_track_id_1\r\n"
410 "m=video 0 RTP/SAVPF 120\r\n"
411 "c=IN IP4 0.0.0.0\r\n"
412 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
413 "a=bundle-only\r\n"
414 "a=mid:video_content_name\r\n"
415 "a=sendrecv\r\n"
416 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
417 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
418 "a=rtpmap:120 VP8/90000\r\n"
419 "a=ssrc-group:FEC 2 3\r\n"
420 "a=ssrc:2 cname:stream_1_cname\r\n"
421 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
422 "a=ssrc:2 mslabel:local_stream_1\r\n"
423 "a=ssrc:2 label:video_track_id_1\r\n"
424 "a=ssrc:3 cname:stream_1_cname\r\n"
425 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
426 "a=ssrc:3 mslabel:local_stream_1\r\n"
427 "a=ssrc:3 label:video_track_id_1\r\n";
428
deadbeef9d3584c2016-02-16 17:54:10 -0800429// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
430// tracks.
431static const char kPlanBSdpFullString[] =
432 "v=0\r\n"
433 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
434 "s=-\r\n"
435 "t=0 0\r\n"
436 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
437 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
438 "c=IN IP4 74.125.127.126\r\n"
439 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
440 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
443 "generation 2\r\n"
444 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
449 "raddr 192.168.1.5 rport 2346 "
450 "generation 2\r\n"
451 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
452 "raddr 192.168.1.5 rport 2348 "
453 "generation 2\r\n"
454 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
455 "a=mid:audio_content_name\r\n"
456 "a=sendrecv\r\n"
457 "a=rtcp-mux\r\n"
458 "a=rtcp-rsize\r\n"
459 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
460 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
461 "dummy_session_params\r\n"
462 "a=rtpmap:111 opus/48000/2\r\n"
463 "a=rtpmap:103 ISAC/16000\r\n"
464 "a=rtpmap:104 ISAC/32000\r\n"
465 "a=ssrc:1 cname:stream_1_cname\r\n"
466 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
467 "a=ssrc:1 mslabel:local_stream_1\r\n"
468 "a=ssrc:1 label:audio_track_id_1\r\n"
469 "a=ssrc:4 cname:stream_2_cname\r\n"
470 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
471 "a=ssrc:4 mslabel:local_stream_2\r\n"
472 "a=ssrc:4 label:audio_track_id_2\r\n"
473 "m=video 3457 RTP/SAVPF 120\r\n"
474 "c=IN IP4 74.125.224.39\r\n"
475 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
476 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
479 "generation 2\r\n"
480 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
481 "generation 2\r\n"
482 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
483 "generation 2\r\n"
484 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
485 "generation 2\r\n"
486 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
487 "generation 2\r\n"
488 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
489 "a=mid:video_content_name\r\n"
490 "a=sendrecv\r\n"
491 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
492 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
493 "a=rtpmap:120 VP8/90000\r\n"
494 "a=ssrc-group:FEC 2 3\r\n"
495 "a=ssrc:2 cname:stream_1_cname\r\n"
496 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
497 "a=ssrc:2 mslabel:local_stream_1\r\n"
498 "a=ssrc:2 label:video_track_id_1\r\n"
499 "a=ssrc:3 cname:stream_1_cname\r\n"
500 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
501 "a=ssrc:3 mslabel:local_stream_1\r\n"
502 "a=ssrc:3 label:video_track_id_1\r\n"
503 "a=ssrc:5 cname:stream_2_cname\r\n"
504 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
505 "a=ssrc:5 mslabel:local_stream_2\r\n"
506 "a=ssrc:5 label:video_track_id_2\r\n"
507 "a=ssrc:6 cname:stream_2_cname\r\n"
508 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
509 "a=ssrc:6 mslabel:local_stream_2\r\n"
510 "a=ssrc:6 label:video_track_id_3\r\n";
511
512// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
513// tracks.
514static const char kUnifiedPlanSdpFullString[] =
515 "v=0\r\n"
516 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
517 "s=-\r\n"
518 "t=0 0\r\n"
519 "a=msid-semantic: WMS local_stream_1\r\n"
520 // Audio track 1, stream 1 (with candidates).
521 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
522 "c=IN IP4 74.125.127.126\r\n"
523 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
524 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
533 "raddr 192.168.1.5 rport 2346 "
534 "generation 2\r\n"
535 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
536 "raddr 192.168.1.5 rport 2348 "
537 "generation 2\r\n"
538 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
539 "a=mid:audio_content_name\r\n"
540 "a=msid:local_stream_1 audio_track_id_1\r\n"
541 "a=sendrecv\r\n"
542 "a=rtcp-mux\r\n"
543 "a=rtcp-rsize\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
545 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
546 "dummy_session_params\r\n"
547 "a=rtpmap:111 opus/48000/2\r\n"
548 "a=rtpmap:103 ISAC/16000\r\n"
549 "a=rtpmap:104 ISAC/32000\r\n"
550 "a=ssrc:1 cname:stream_1_cname\r\n"
551 // Video track 1, stream 1 (with candidates).
552 "m=video 3457 RTP/SAVPF 120\r\n"
553 "c=IN IP4 74.125.224.39\r\n"
554 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
555 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
558 "generation 2\r\n"
559 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
560 "generation 2\r\n"
561 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
562 "generation 2\r\n"
563 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
564 "generation 2\r\n"
565 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
566 "generation 2\r\n"
567 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
568 "a=mid:video_content_name\r\n"
569 "a=msid:local_stream_1 video_track_id_1\r\n"
570 "a=sendrecv\r\n"
571 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
572 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
573 "a=rtpmap:120 VP8/90000\r\n"
574 "a=ssrc-group:FEC 2 3\r\n"
575 "a=ssrc:2 cname:stream_1_cname\r\n"
576 "a=ssrc:3 cname:stream_1_cname\r\n"
577 // Audio track 2, stream 2.
578 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
579 "c=IN IP4 0.0.0.0\r\n"
580 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
581 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
582 "a=mid:audio_content_name_2\r\n"
583 "a=msid:local_stream_2 audio_track_id_2\r\n"
584 "a=sendrecv\r\n"
585 "a=rtcp-mux\r\n"
586 "a=rtcp-rsize\r\n"
587 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
588 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
589 "dummy_session_params\r\n"
590 "a=rtpmap:111 opus/48000/2\r\n"
591 "a=rtpmap:103 ISAC/16000\r\n"
592 "a=rtpmap:104 ISAC/32000\r\n"
593 "a=ssrc:4 cname:stream_2_cname\r\n"
594 // Video track 2, stream 2.
595 "m=video 9 RTP/SAVPF 120\r\n"
596 "c=IN IP4 0.0.0.0\r\n"
597 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
598 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
599 "a=mid:video_content_name_2\r\n"
600 "a=msid:local_stream_2 video_track_id_2\r\n"
601 "a=sendrecv\r\n"
602 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
603 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
604 "a=rtpmap:120 VP8/90000\r\n"
605 "a=ssrc:5 cname:stream_2_cname\r\n"
606 // Video track 3, stream 2.
607 "m=video 9 RTP/SAVPF 120\r\n"
608 "c=IN IP4 0.0.0.0\r\n"
609 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
610 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
611 "a=mid:video_content_name_3\r\n"
612 "a=msid:local_stream_2 video_track_id_3\r\n"
613 "a=sendrecv\r\n"
614 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
615 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
616 "a=rtpmap:120 VP8/90000\r\n"
617 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618
Seth Hampson5b4f0752018-04-02 16:31:36 -0700619// Unified Plan SDP reference string:
620// - audio track 1 has 1 a=msid lines
621// - audio track 2 has 2 a=msid lines
622// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
623// there are 0 media stream ids.
624// This Unified Plan SDP represents a SDP that signals the msid using both
625// a=msid and a=ssrc msid semantics.
626static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
627 "v=0\r\n"
628 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
629 "s=-\r\n"
630 "t=0 0\r\n"
631 "a=msid-semantic: WMS local_stream_1\r\n"
632 // Audio track 1, with 1 stream id.
633 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
634 "c=IN IP4 74.125.127.126\r\n"
635 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
636 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
639 "generation 2\r\n"
640 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
641 "generation 2\r\n"
642 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
643 "generation 2\r\n"
644 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
645 "raddr 192.168.1.5 rport 2346 "
646 "generation 2\r\n"
647 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
648 "raddr 192.168.1.5 rport 2348 "
649 "generation 2\r\n"
650 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
651 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700652 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700653 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700654 "a=rtcp-mux\r\n"
655 "a=rtcp-rsize\r\n"
656 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
657 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
658 "dummy_session_params\r\n"
659 "a=rtpmap:111 opus/48000/2\r\n"
660 "a=rtpmap:103 ISAC/16000\r\n"
661 "a=rtpmap:104 ISAC/32000\r\n"
662 "a=ssrc:1 cname:stream_1_cname\r\n"
663 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
664 "a=ssrc:1 mslabel:local_stream_1\r\n"
665 "a=ssrc:1 label:audio_track_id_1\r\n"
666 // Audio track 2, with two stream ids.
667 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
668 "c=IN IP4 0.0.0.0\r\n"
669 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
670 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
671 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700672 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700673 "a=msid:local_stream_1 audio_track_id_2\r\n"
674 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700675 "a=rtcp-mux\r\n"
676 "a=rtcp-rsize\r\n"
677 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
678 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
679 "dummy_session_params\r\n"
680 "a=rtpmap:111 opus/48000/2\r\n"
681 "a=rtpmap:103 ISAC/16000\r\n"
682 "a=rtpmap:104 ISAC/32000\r\n"
683 "a=ssrc:4 cname:stream_1_cname\r\n"
684 // The support for Plan B msid signaling only includes the
685 // first media stream id "local_stream_1."
686 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
687 "a=ssrc:4 mslabel:local_stream_1\r\n"
688 "a=ssrc:4 label:audio_track_id_2\r\n"
689 // Audio track 3, with no stream ids.
690 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
691 "c=IN IP4 0.0.0.0\r\n"
692 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
693 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
694 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700695 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700696 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700697 "a=rtcp-mux\r\n"
698 "a=rtcp-rsize\r\n"
699 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
700 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
701 "dummy_session_params\r\n"
702 "a=rtpmap:111 opus/48000/2\r\n"
703 "a=rtpmap:103 ISAC/16000\r\n"
704 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700705 "a=ssrc:7 cname:stream_2_cname\r\n"
706 "a=ssrc:7 msid:- audio_track_id_3\r\n"
707 "a=ssrc:7 mslabel:-\r\n"
708 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700709
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800710// SDP string for unified plan without SSRCs
711static const char kUnifiedPlanSdpFullStringNoSsrc[] =
712 "v=0\r\n"
713 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
714 "s=-\r\n"
715 "t=0 0\r\n"
716 "a=msid-semantic: WMS local_stream_1\r\n"
717 // Audio track 1, stream 1 (with candidates).
718 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
719 "c=IN IP4 74.125.127.126\r\n"
720 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
721 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
724 "generation 2\r\n"
725 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
726 "generation 2\r\n"
727 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
728 "generation 2\r\n"
729 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
730 "raddr 192.168.1.5 rport 2346 "
731 "generation 2\r\n"
732 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
733 "raddr 192.168.1.5 rport 2348 "
734 "generation 2\r\n"
735 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
736 "a=mid:audio_content_name\r\n"
737 "a=msid:local_stream_1 audio_track_id_1\r\n"
738 "a=sendrecv\r\n"
739 "a=rtcp-mux\r\n"
740 "a=rtcp-rsize\r\n"
741 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
742 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
743 "dummy_session_params\r\n"
744 "a=rtpmap:111 opus/48000/2\r\n"
745 "a=rtpmap:103 ISAC/16000\r\n"
746 "a=rtpmap:104 ISAC/32000\r\n"
747 // Video track 1, stream 1 (with candidates).
748 "m=video 3457 RTP/SAVPF 120\r\n"
749 "c=IN IP4 74.125.224.39\r\n"
750 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
751 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
754 "generation 2\r\n"
755 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
756 "generation 2\r\n"
757 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
758 "generation 2\r\n"
759 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
760 "generation 2\r\n"
761 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
762 "generation 2\r\n"
763 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
764 "a=mid:video_content_name\r\n"
765 "a=msid:local_stream_1 video_track_id_1\r\n"
766 "a=sendrecv\r\n"
767 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
768 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
769 "a=rtpmap:120 VP8/90000\r\n"
770 // Audio track 2, stream 2.
771 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
772 "c=IN IP4 0.0.0.0\r\n"
773 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
774 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
775 "a=mid:audio_content_name_2\r\n"
776 "a=msid:local_stream_2 audio_track_id_2\r\n"
777 "a=sendrecv\r\n"
778 "a=rtcp-mux\r\n"
779 "a=rtcp-rsize\r\n"
780 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
781 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
782 "dummy_session_params\r\n"
783 "a=rtpmap:111 opus/48000/2\r\n"
784 "a=rtpmap:103 ISAC/16000\r\n"
785 "a=rtpmap:104 ISAC/32000\r\n"
786 // Video track 2, stream 2.
787 "m=video 9 RTP/SAVPF 120\r\n"
788 "c=IN IP4 0.0.0.0\r\n"
789 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
790 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
791 "a=mid:video_content_name_2\r\n"
792 "a=msid:local_stream_2 video_track_id_2\r\n"
793 "a=sendrecv\r\n"
794 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
795 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
796 "a=rtpmap:120 VP8/90000\r\n"
797 // Video track 3, stream 2.
798 "m=video 9 RTP/SAVPF 120\r\n"
799 "c=IN IP4 0.0.0.0\r\n"
800 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
801 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
802 "a=mid:video_content_name_3\r\n"
803 "a=msid:local_stream_2 video_track_id_3\r\n"
804 "a=sendrecv\r\n"
805 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
806 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
807 "a=rtpmap:120 VP8/90000\r\n";
808
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809// One candidate reference string as per W3c spec.
810// candidate:<blah> not a=candidate:<blah>CRLF
811static const char kRawCandidate[] =
812 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
813// One candidate reference string.
814static const char kSdpOneCandidate[] =
815 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
816 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000817
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000818static const char kSdpTcpActiveCandidate[] =
819 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
820 "tcptype active generation 2";
821static const char kSdpTcpPassiveCandidate[] =
822 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
823 "tcptype passive generation 2";
824static const char kSdpTcpSOCandidate[] =
825 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
826 "tcptype so generation 2";
827static const char kSdpTcpInvalidCandidate[] =
828 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
829 "tcptype invalid generation 2";
830
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000831// One candidate reference string with IPV6 address.
832static const char kRawIPV6Candidate[] =
833 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700834 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835
836// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800837static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800839 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840
Zach Steinb336c272018-08-09 01:16:13 -0700841static const char kRawHostnameCandidate[] =
842 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
843
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844// Session id and version
845static const char kSessionId[] = "18446744069414584320";
846static const char kSessionVersion[] = "18446462598732840960";
847
deadbeef9d3584c2016-02-16 17:54:10 -0800848// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849static const char kIceOption1[] = "iceoption1";
850static const char kIceOption2[] = "iceoption2";
851static const char kIceOption3[] = "iceoption3";
852
deadbeef9d3584c2016-02-16 17:54:10 -0800853// ICE ufrags/passwords.
854static const char kUfragVoice[] = "ufrag_voice";
855static const char kPwdVoice[] = "pwd_voice";
856static const char kUfragVideo[] = "ufrag_video";
857static const char kPwdVideo[] = "pwd_video";
858static const char kUfragData[] = "ufrag_data";
859static const char kPwdData[] = "pwd_data";
860
861// Extra ufrags/passwords for extra unified plan m= sections.
862static const char kUfragVoice2[] = "ufrag_voice_2";
863static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700864static const char kUfragVoice3[] = "ufrag_voice_3";
865static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800866static const char kUfragVideo2[] = "ufrag_video_2";
867static const char kPwdVideo2[] = "pwd_video_2";
868static const char kUfragVideo3[] = "ufrag_video_3";
869static const char kPwdVideo3[] = "pwd_video_3";
870
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871// Content name
872static const char kAudioContentName[] = "audio_content_name";
873static const char kVideoContentName[] = "video_content_name";
874static const char kDataContentName[] = "data_content_name";
875
deadbeef9d3584c2016-02-16 17:54:10 -0800876// Extra content names for extra unified plan m= sections.
877static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700878static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800879static const char kVideoContentName2[] = "video_content_name_2";
880static const char kVideoContentName3[] = "video_content_name_3";
881
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800883static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884static const char kStream1Cname[] = "stream_1_cname";
885static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200886static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800888static const uint32_t kVideoTrack1Ssrc1 = 2;
889static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
891// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800892static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893static const char kStream2Cname[] = "stream_2_cname";
894static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200895static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800896static const char kVideoTrackId2[] = "video_track_id_2";
897static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800899static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700900static const char kAudioTrackId3[] = "audio_track_id_3";
901static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
903// DataChannel
904static const char kDataChannelLabel[] = "data_channel";
905static const char kDataChannelMsid[] = "data_channeld0";
906static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200907static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
909// Candidate
910static const char kDummyMid[] = "dummy_mid";
911static const int kDummyIndex = 123;
912
913// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800914static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
916// Helper functions
917
918static bool SdpDeserialize(const std::string& message,
919 JsepSessionDescription* jdesc) {
920 return webrtc::SdpDeserialize(message, jdesc, NULL);
921}
922
923static bool SdpDeserializeCandidate(const std::string& message,
924 JsepIceCandidate* candidate) {
925 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
926}
927
928// Add some extra |newlines| to the |message| after |line|.
929static void InjectAfter(const std::string& line,
930 const std::string& newlines,
931 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800932 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933}
934
935static void Replace(const std::string& line,
936 const std::string& newlines,
937 std::string* message) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -0800938 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939}
940
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000941// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
942// message.
943static void ExpectParseFailure(const std::string& bad_sdp,
944 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800945 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000947 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000949 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
950}
951
952// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
953static void ExpectParseFailure(const char* good_part, const char* bad_part) {
954 std::string bad_sdp = kSdpFullString;
955 Replace(good_part, bad_part, &bad_sdp);
956 ExpectParseFailure(bad_sdp, bad_part);
957}
958
959// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
960static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
961 const std::string& newlines,
962 const std::string& bad_part) {
963 std::string bad_sdp = kSdpFullString;
964 InjectAfter(injectpoint, newlines, &bad_sdp);
965 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966}
967
Steve Anton4e70a722017-11-28 14:57:10 -0800968static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 std::string* message) {
970 std::string new_direction;
971 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800972 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 new_direction = "a=inactive";
974 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800975 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 new_direction = "a=sendonly";
977 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800978 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 new_direction = "a=recvonly";
980 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800981 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 default:
983 new_direction = "a=sendrecv";
984 break;
985 }
986 Replace("a=sendrecv", new_direction, message);
987}
988
Yves Gerey665174f2018-06-19 15:03:05 +0200989static void ReplaceRejected(bool audio_rejected,
990 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 std::string* message) {
992 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800993 Replace("m=audio 9", "m=audio 0", message);
994 Replace(kAttributeIceUfragVoice, "", message);
995 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 }
997 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800998 Replace("m=video 9", "m=video 0", message);
999 Replace(kAttributeIceUfragVideo, "", message);
1000 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 }
1002}
1003
1004// WebRtcSdpTest
1005
Mirko Bonadei6a489f22019-04-09 15:11:12 +02001006class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001008 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001009#ifdef WEBRTC_ANDROID
1010 webrtc::InitializeAndroidObjects();
1011#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 // AudioContentDescription
1013 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001014 StreamParams audio_stream;
1015 audio_stream.id = kAudioTrackId1;
1016 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001017 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001018 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1019 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001020 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1021 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001022 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1023 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024
1025 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001026 video_desc_ = CreateVideoContentDescription();
1027 StreamParams video_stream;
1028 video_stream.id = kVideoTrackId1;
1029 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001030 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001031 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1032 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1033 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1034 video_stream.ssrc_groups.push_back(ssrc_group);
1035 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001036 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1037 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001038 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1039 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
1041 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001042 desc_.AddTransportInfo(TransportInfo(
1043 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1044 desc_.AddTransportInfo(TransportInfo(
1045 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046
1047 // v4 host
1048 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001049 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001050 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "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 candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001058 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001059 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1060 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001062 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001063 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1064 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065
1066 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001068 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1069 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001070 cricket::LOCAL_PORT_TYPE,
1071 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001073 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1074 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001075 cricket::LOCAL_PORT_TYPE,
1076 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001078 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1079 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001080 cricket::LOCAL_PORT_TYPE,
1081 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001083 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1084 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001085 cricket::LOCAL_PORT_TYPE,
1086 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087
1088 // stun
1089 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001090 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1091 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001092 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "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 candidate9.set_related_address(rel_address_stun);
1097
1098 address_stun.SetPort(port_stun++);
1099 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001100 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1101 address_stun, kCandidatePriority, "", "",
1102 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001103 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 candidate10.set_related_address(rel_address_stun);
1105
1106 // relay
1107 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001108 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001109 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1110 address_relay, kCandidatePriority, "", "",
1111 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001112 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001114 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1115 address_relay, kCandidatePriority, "", "",
1116 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001117 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118
1119 // voice
1120 candidates_.push_back(candidate1);
1121 candidates_.push_back(candidate2);
1122 candidates_.push_back(candidate5);
1123 candidates_.push_back(candidate6);
1124 candidates_.push_back(candidate9);
1125 candidates_.push_back(candidate10);
1126
1127 // video
1128 candidates_.push_back(candidate3);
1129 candidates_.push_back(candidate4);
1130 candidates_.push_back(candidate7);
1131 candidates_.push_back(candidate8);
1132 candidates_.push_back(candidate11);
1133 candidates_.push_back(candidate12);
1134
Yves Gerey665174f2018-06-19 15:03:05 +02001135 jcandidate_.reset(
1136 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137
1138 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001139 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 std::string mline_id;
1141 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001142 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143 // In this test, the audio m line index will be 0, and the video m line
1144 // will be 1.
1145 bool is_video = (i > 5);
1146 mline_id = is_video ? "video_content_name" : "audio_content_name";
1147 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001148 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 jdesc_.AddCandidate(&jice);
1150 }
1151 }
1152
Seth Hampson5b4f0752018-04-02 16:31:36 -07001153 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001154 const IceCandidateCollection* video_candidates_collection =
1155 jdesc_.candidates(1);
1156 ASSERT_NE(nullptr, video_candidates_collection);
1157 std::vector<cricket::Candidate> video_candidates;
1158 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1159 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1160 c.set_transport_name("video_content_name");
1161 video_candidates.push_back(c);
1162 }
1163 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001164 }
1165
1166 // Turns the existing reference description into a description using
1167 // a=bundle-only. This means no transport attributes and a 0 port value on
1168 // the m= sections not associated with the BUNDLE-tag.
1169 void MakeBundleOnlyDescription() {
1170 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001171
1172 // And the rest of the transport attributes.
1173 desc_.transport_infos()[1].description.ice_ufrag.clear();
1174 desc_.transport_infos()[1].description.ice_pwd.clear();
1175 desc_.transport_infos()[1].description.connection_role =
1176 cricket::CONNECTIONROLE_NONE;
1177
1178 // Set bundle-only flag.
1179 desc_.contents()[1].bundle_only = true;
1180
1181 // Add BUNDLE group.
1182 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1183 group.AddContentName(kAudioContentName);
1184 group.AddContentName(kVideoContentName);
1185 desc_.AddGroup(group);
1186
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001187 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-12 18:37:36 -08001188 jdesc_.session_version()));
1189 }
1190
deadbeef9d3584c2016-02-16 17:54:10 -08001191 // Turns the existing reference description into a plan B description,
1192 // with 2 audio tracks and 3 video tracks.
1193 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001194 audio_desc_ = audio_desc_->Copy();
1195 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001196
1197 StreamParams audio_track_2;
1198 audio_track_2.id = kAudioTrackId2;
1199 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001200 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001201 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1202 audio_desc_->AddStream(audio_track_2);
1203
1204 StreamParams video_track_2;
1205 video_track_2.id = kVideoTrackId2;
1206 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001207 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001208 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1209 video_desc_->AddStream(video_track_2);
1210
1211 StreamParams video_track_3;
1212 video_track_3.id = kVideoTrackId3;
1213 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001214 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001215 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1216 video_desc_->AddStream(video_track_3);
1217
1218 desc_.RemoveContentByName(kAudioContentName);
1219 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001220 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1221 absl::WrapUnique(audio_desc_));
1222 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1223 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001224
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001225 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001226 jdesc_.session_version()));
1227 }
1228
1229 // Turns the existing reference description into a unified plan description,
1230 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001231 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001232 // Audio track 2.
1233 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1234 StreamParams audio_track_2;
1235 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001236 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001237 if (use_ssrcs) {
1238 audio_track_2.cname = kStream2Cname;
1239 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1240 }
deadbeef9d3584c2016-02-16 17:54:10 -08001241 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001242 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1243 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001244 desc_.AddTransportInfo(TransportInfo(
1245 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001246 // Video track 2, in stream 2.
1247 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1248 StreamParams video_track_2;
1249 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001250 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001251 if (use_ssrcs) {
1252 video_track_2.cname = kStream2Cname;
1253 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1254 }
deadbeef9d3584c2016-02-16 17:54:10 -08001255 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001256 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1257 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001258 desc_.AddTransportInfo(TransportInfo(
1259 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001260
1261 // Video track 3, in stream 2.
1262 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1263 StreamParams video_track_3;
1264 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001265 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001266 if (use_ssrcs) {
1267 video_track_3.cname = kStream2Cname;
1268 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1269 }
deadbeef9d3584c2016-02-16 17:54:10 -08001270 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001271 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1272 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001273 desc_.AddTransportInfo(TransportInfo(
1274 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001275 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001276
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001277 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-16 17:54:10 -08001278 jdesc_.session_version()));
1279 }
1280
1281 // Creates an audio content description with no streams, and some default
1282 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 AudioContentDescription* CreateAudioContentDescription() {
1284 AudioContentDescription* audio = new AudioContentDescription();
1285 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001286 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001287 audio->AddCrypto(CryptoParams(
1288 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1290 "dummy_session_params"));
1291 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001292 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001293 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001294 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1295 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 return audio;
1297 }
1298
Seth Hampson5b4f0752018-04-02 16:31:36 -07001299 // Turns the existing reference description into a unified plan description,
1300 // with 3 audio MediaContentDescriptions with special StreamParams that
1301 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1302 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001303 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001304 desc_.RemoveContentByName(kVideoContentName);
1305 desc_.RemoveTransportInfoByName(kVideoContentName);
1306 RemoveVideoCandidates();
1307
1308 // Audio track 2 has 2 media stream ids.
1309 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1310 StreamParams audio_track_2;
1311 audio_track_2.id = kAudioTrackId2;
1312 audio_track_2.cname = kStream1Cname;
1313 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1314 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1315 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001316 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1317 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 15:55:30 -08001318 desc_.AddTransportInfo(TransportInfo(
1319 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001320
1321 // Audio track 3 has no stream ids.
1322 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1323 StreamParams audio_track_3;
1324 audio_track_3.id = kAudioTrackId3;
1325 audio_track_3.cname = kStream2Cname;
1326 audio_track_3.set_stream_ids({});
1327 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1328 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001329 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1330 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 15:55:30 -08001331 desc_.AddTransportInfo(TransportInfo(
1332 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001333 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001334 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 16:31:36 -07001335 jdesc_.session_version()));
1336 }
1337
Seth Hampson5897a6e2018-04-03 11:16:33 -07001338 // Turns the existing reference description into a unified plan description
1339 // with one audio MediaContentDescription that contains one StreamParams with
1340 // 0 ssrcs.
1341 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1342 desc_.RemoveContentByName(kVideoContentName);
1343 desc_.RemoveContentByName(kAudioContentName);
1344 desc_.RemoveTransportInfoByName(kVideoContentName);
1345 RemoveVideoCandidates();
1346
1347 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1348 StreamParams audio_track;
1349 audio_track.id = kAudioTrackId1;
1350 audio_track.set_stream_ids({kStreamId1});
1351 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001352 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1353 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 11:16:33 -07001354
1355 // Enable signaling a=msid lines.
1356 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001357 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 11:16:33 -07001358 jdesc_.session_version()));
1359 }
1360
deadbeef9d3584c2016-02-16 17:54:10 -08001361 // Creates a video content description with no streams, and some default
1362 // configuration.
1363 VideoContentDescription* CreateVideoContentDescription() {
1364 VideoContentDescription* video = new VideoContentDescription();
1365 video->AddCrypto(CryptoParams(
1366 1, "AES_CM_128_HMAC_SHA1_80",
1367 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1368 video->set_protocol(cricket::kMediaProtocolSavpf);
1369 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001370 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001371 return video;
1372 }
1373
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001375 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 // type
Harald Alvestrand1716d392019-06-03 20:35:45 +02001377 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378
1379 // content direction
1380 EXPECT_EQ(cd1->direction(), cd2->direction());
1381
1382 // rtcp_mux
1383 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1384
deadbeef13871492015-12-09 12:37:51 -08001385 // rtcp_reduced_size
1386 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 // cryptos
1389 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1390 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1391 ADD_FAILURE();
1392 return;
1393 }
Yves Gerey665174f2018-06-19 15:03:05 +02001394 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 const CryptoParams c1 = cd1->cryptos().at(i);
1396 const CryptoParams c2 = cd2->cryptos().at(i);
1397 EXPECT_TRUE(c1.Matches(c2));
1398 EXPECT_EQ(c1.key_params, c2.key_params);
1399 EXPECT_EQ(c1.session_params, c2.session_params);
1400 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001401
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001403 // Use an equivalence class here, for old and new versions of the
1404 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001405 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1406 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1407 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001408 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001409 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1410 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1411 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001412 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001413 } else {
1414 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1415 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416
1417 // codecs
1418 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1419
1420 // bandwidth
1421 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1422
1423 // streams
1424 EXPECT_EQ(cd1->streams(), cd2->streams());
1425
Johannes Kron0854eb62018-10-10 22:33:20 +02001426 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001427 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001428
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 // extmap
1430 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1431 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001432 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001433 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1434 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 EXPECT_EQ(ext1.uri, ext2.uri);
1436 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001437 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 }
1440
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001441 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1442 const std::vector<std::string>& ids) {
1443 // Order of elements does not matter, only equivalence of sets.
1444 EXPECT_EQ(rids.size(), ids.size());
1445 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-28 17:25:26 -08001446 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1447 return rid.rid == id;
1448 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001449 }
1450 }
1451
Amit Hilbucha2012042018-12-03 11:35:05 -08001452 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1453 const SimulcastDescription& simulcast2) {
1454 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1455 EXPECT_EQ(simulcast1.receive_layers().size(),
1456 simulcast2.receive_layers().size());
1457 }
1458
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001459 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1460 const RtpDataContentDescription* dcd2) {
1461 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1462 }
1463
1464 void CompareSctpDataContentDescription(
1465 const SctpDataContentDescription* dcd1,
1466 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001467 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001468 EXPECT_EQ(dcd1->port(), dcd2->port());
1469 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:17 +00001470 }
1471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 void CompareSessionDescription(const SessionDescription& desc1,
1473 const SessionDescription& desc2) {
1474 // Compare content descriptions.
1475 if (desc1.contents().size() != desc2.contents().size()) {
1476 ADD_FAILURE();
1477 return;
1478 }
Yves Gerey665174f2018-06-19 15:03:05 +02001479 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1481 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001482 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001484 EXPECT_EQ(c1.type, c2.type);
1485 EXPECT_EQ(c1.rejected, c2.rejected);
1486 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487
1488 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1489 if (IsAudioContent(&c1)) {
1490 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001491 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001493 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1495 }
1496
1497 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1498 if (IsVideoContent(&c1)) {
1499 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001500 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001502 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1504 }
1505
1506 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001507 if (c1.media_description()->as_sctp()) {
1508 ASSERT_TRUE(c2.media_description()->as_sctp());
1509 const SctpDataContentDescription* scd1 =
1510 c1.media_description()->as_sctp();
1511 const SctpDataContentDescription* scd2 =
1512 c2.media_description()->as_sctp();
1513 CompareSctpDataContentDescription(scd1, scd2);
1514 } else {
1515 if (IsDataContent(&c1)) {
1516 const RtpDataContentDescription* dcd1 =
1517 c1.media_description()->as_rtp_data();
1518 const RtpDataContentDescription* dcd2 =
1519 c2.media_description()->as_rtp_data();
1520 CompareRtpDataContentDescription(dcd1, dcd2);
1521 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001523
1524 CompareSimulcastDescription(
1525 c1.media_description()->simulcast_description(),
1526 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 }
1528
1529 // group
1530 const cricket::ContentGroups groups1 = desc1.groups();
1531 const cricket::ContentGroups groups2 = desc2.groups();
1532 EXPECT_EQ(groups1.size(), groups1.size());
1533 if (groups1.size() != groups2.size()) {
1534 ADD_FAILURE();
1535 return;
1536 }
1537 for (size_t i = 0; i < groups1.size(); ++i) {
1538 const cricket::ContentGroup group1 = groups1.at(i);
1539 const cricket::ContentGroup group2 = groups2.at(i);
1540 EXPECT_EQ(group1.semantics(), group2.semantics());
1541 const cricket::ContentNames names1 = group1.content_names();
1542 const cricket::ContentNames names2 = group2.content_names();
1543 EXPECT_EQ(names1.size(), names2.size());
1544 if (names1.size() != names2.size()) {
1545 ADD_FAILURE();
1546 return;
1547 }
1548 cricket::ContentNames::const_iterator iter1 = names1.begin();
1549 cricket::ContentNames::const_iterator iter2 = names2.begin();
1550 while (iter1 != names1.end()) {
1551 EXPECT_EQ(*iter1++, *iter2++);
1552 }
1553 }
1554
1555 // transport info
1556 const cricket::TransportInfos transports1 = desc1.transport_infos();
1557 const cricket::TransportInfos transports2 = desc2.transport_infos();
1558 EXPECT_EQ(transports1.size(), transports2.size());
1559 if (transports1.size() != transports2.size()) {
1560 ADD_FAILURE();
1561 return;
1562 }
1563 for (size_t i = 0; i < transports1.size(); ++i) {
1564 const cricket::TransportInfo transport1 = transports1.at(i);
1565 const cricket::TransportInfo transport2 = transports2.at(i);
1566 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 EXPECT_EQ(transport1.description.ice_ufrag,
1568 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001569 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001570 EXPECT_EQ(transport1.description.ice_mode,
1571 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 if (transport1.description.identity_fingerprint) {
1573 EXPECT_EQ(*transport1.description.identity_fingerprint,
1574 *transport2.description.identity_fingerprint);
1575 } else {
1576 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1577 transport2.description.identity_fingerprint.get());
1578 }
1579 EXPECT_EQ(transport1.description.transport_options,
1580 transport2.description.transport_options);
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001581 EXPECT_EQ(transport1.description.opaque_parameters,
1582 transport2.description.opaque_parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 }
deadbeefc80741f2015-10-22 13:14:45 -07001584
1585 // global attributes
1586 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001587 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 }
1589
Yves Gerey665174f2018-06-19 15:03:05 +02001590 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1591 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1593 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1594 CompareSessionDescription(*desc1.description(), *desc2.description());
1595 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1596 return false;
1597 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1598 const IceCandidateCollection* cc1 = desc1.candidates(i);
1599 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001600 if (cc1->count() != cc2->count()) {
1601 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001603 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 for (size_t j = 0; j < cc1->count(); ++j) {
1605 const IceCandidateInterface* c1 = cc1->at(j);
1606 const IceCandidateInterface* c2 = cc2->at(j);
1607 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1608 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1609 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1610 }
1611 }
1612 return true;
1613 }
1614
1615 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1616 // them with invalid keywords so that the parser will just ignore them.
1617 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 15:13:09 -08001618 absl::StrReplaceAll(
1619 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 return true;
1621 }
1622
1623 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001624 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1625 int mline_index,
1626 const std::string& ufrag,
1627 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 std::string content_name;
1629 if (mline_index == 0) {
1630 content_name = kAudioContentName;
1631 } else if (mline_index == 1) {
1632 content_name = kVideoContentName;
1633 } else {
nissec80e7412017-01-11 05:56:46 -08001634 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 }
Yves Gerey665174f2018-06-19 15:03:05 +02001636 TransportInfo transport_info(content_name,
1637 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 SessionDescription* desc =
1639 const_cast<SessionDescription*>(jdesc->description());
1640 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001641 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1643 const IceCandidateCollection* cc = jdesc_.candidates(i);
1644 for (size_t j = 0; j < cc->count(); ++j) {
1645 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001646 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1647 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 }
1649 }
1650 }
1651 return true;
1652 }
1653
1654 void AddIceOptions(const std::string& content_name,
1655 const std::vector<std::string>& transport_options) {
1656 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1657 cricket::TransportInfo transport_info =
1658 *(desc_.GetTransportInfoByName(content_name));
1659 desc_.RemoveTransportInfoByName(content_name);
1660 transport_info.description.transport_options = transport_options;
1661 desc_.AddTransportInfo(transport_info);
1662 }
1663
deadbeef3f7219b2015-12-28 15:17:14 -08001664 void SetIceUfragPwd(const std::string& content_name,
1665 const std::string& ice_ufrag,
1666 const std::string& ice_pwd) {
1667 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1668 cricket::TransportInfo transport_info =
1669 *(desc_.GetTransportInfoByName(content_name));
1670 desc_.RemoveTransportInfoByName(content_name);
1671 transport_info.description.ice_ufrag = ice_ufrag;
1672 transport_info.description.ice_pwd = ice_pwd;
1673 desc_.AddTransportInfo(transport_info);
1674 }
1675
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07001676 void AddOpaqueTransportParameters(const std::string& content_name,
1677 cricket::OpaqueTransportParameters params) {
1678 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1679 cricket::TransportInfo info = *(desc_.GetTransportInfoByName(content_name));
1680 desc_.RemoveTransportInfoByName(content_name);
1681 info.description.opaque_parameters = params;
1682 desc_.AddTransportInfo(info);
1683 }
1684
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 void AddFingerprint() {
1686 desc_.RemoveTransportInfoByName(kAudioContentName);
1687 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001688 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001689 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001690 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001691 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1692 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001693 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1694 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001695 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001696 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1697 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001698 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 }
1700
jbauch5869f502017-06-29 12:31:36 -07001701 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001702 audio_desc_ = audio_desc_->Copy();
1703 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001704 audio_desc_->AddRtpHeaderExtension(
1705 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1706 video_desc_->AddRtpHeaderExtension(
1707 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 desc_.RemoveContentByName(kAudioContentName);
1709 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001710 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1711 absl::WrapUnique(audio_desc_));
1712 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1713 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 }
1715
1716 void RemoveCryptos() {
1717 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1718 video_desc_->set_cryptos(std::vector<CryptoParams>());
1719 }
1720
Seth Hampson5897a6e2018-04-03 11:16:33 -07001721 // Removes everything in StreamParams from the session description that is
1722 // used for a=ssrc lines.
1723 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 20:35:45 +02001724 for (cricket::ContentInfo& content_info :
1725 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 11:16:33 -07001726 // With Unified Plan there should be one StreamParams per m= section.
1727 StreamParams& stream =
1728 content_info.media_description()->mutable_streams()[0];
1729 stream.ssrcs.clear();
1730 stream.ssrc_groups.clear();
1731 stream.cname.clear();
1732 }
1733 }
1734
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001735 // Removes all a=ssrc lines from the SDP string, except for the
1736 // "a=ssrc:... cname:..." lines.
1737 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1738 const char kAttributeSsrc[] = "a=ssrc";
1739 const char kAttributeCname[] = "cname";
1740 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1741 while (ssrc_line_pos != std::string::npos) {
1742 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1743 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1744 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1745 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1746 // Only erase a=ssrc lines that don't contain "cname".
1747 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1748 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1749 } else {
1750 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1751 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1752 }
1753 }
1754 }
1755
Seth Hampson5897a6e2018-04-03 11:16:33 -07001756 // Removes all a=ssrc lines from the SDP string.
1757 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1758 const char kAttributeSsrc[] = "a=ssrc";
1759 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1760 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1761 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1762 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1763 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1764 }
1765 }
1766
Steve Anton4e70a722017-11-28 14:57:10 -08001767 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 audio_desc_->set_direction(direction);
1769 video_desc_->set_direction(direction);
1770 std::string new_sdp = kSdpFullString;
1771 ReplaceDirection(direction, &new_sdp);
1772
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001773 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 jdesc_.session_version())) {
1775 return false;
1776 }
Steve Antone831b8c2018-02-01 12:22:16 -08001777 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 EXPECT_EQ(new_sdp, message);
1779 return true;
1780 }
1781
1782 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001783 audio_desc_ = audio_desc_->Copy();
1784 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001785
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 desc_.RemoveContentByName(kAudioContentName);
1787 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001788 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001789 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001790 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001791 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001792 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1793 audio_rejected ? "" : kPwdVoice);
1794 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1795 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001796
1797 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1799
Steve Antona3a92c22017-12-07 10:27:41 -08001800 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001801 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001802 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 EXPECT_EQ(new_sdp, message);
1804 return true;
1805 }
1806
zstein4b2e0822017-02-17 19:48:38 -08001807 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001808 std::unique_ptr<SctpDataContentDescription> data(
1809 new SctpDataContentDescription());
1810 sctp_desc_ = data.get();
1811 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:38 +00001812 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001813 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-20 16:34:00 -08001814 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001815 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001816 desc_.AddTransportInfo(TransportInfo(
1817 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 }
1819
1820 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001821 std::unique_ptr<RtpDataContentDescription> data(
1822 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 data_desc_ = data.get();
1824
deadbeef67cf2c12016-04-13 10:07:16 -07001825 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 StreamParams data_stream;
1827 data_stream.id = kDataChannelMsid;
1828 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001829 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 data_stream.ssrcs.push_back(kDataChannelSsrc);
1831 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001832 data_desc_->AddCrypto(
1833 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1834 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 20:35:45 +02001836 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1837 std::move(data));
Steve Anton06817cd2018-12-18 15:55:30 -08001838 desc_.AddTransportInfo(TransportInfo(
1839 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 }
1841
Steve Anton4e70a722017-11-28 14:57:10 -08001842 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 std::string new_sdp = kSdpFullString;
1844 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001845 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846
1847 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1848
1849 audio_desc_->set_direction(direction);
1850 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001851 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 jdesc_.session_version())) {
1853 return false;
1854 }
1855 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1856 return true;
1857 }
1858
1859 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001860 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001862 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001864
Steve Antonb1c1de12017-12-21 15:14:30 -08001865 audio_desc_ = audio_desc_->Copy();
1866 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 desc_.RemoveContentByName(kAudioContentName);
1868 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001869 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001870 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-20 16:34:00 -08001871 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +02001872 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-16 17:54:10 -08001873 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1874 audio_rejected ? "" : kPwdVoice);
1875 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1876 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001877 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001878 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 15:17:14 -08001879 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 return false;
1881 }
deadbeef3f7219b2015-12-28 15:17:14 -08001882 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 return true;
1884 }
1885
Yves Gerey665174f2018-06-19 15:03:05 +02001886 void TestDeserializeExtmap(bool session_level,
1887 bool media_level,
1888 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001889 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001890 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02001891 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001893 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 std::string sdp_with_extmap = kSdpString;
1895 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001896 InjectAfter(kSessionTime,
1897 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1898 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 &sdp_with_extmap);
1900 }
1901 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001902 InjectAfter(kAttributeIcePwdVoice,
1903 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1904 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001906 InjectAfter(kAttributeIcePwdVideo,
1907 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1908 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 &sdp_with_extmap);
1910 }
1911 // The extmap can't be present at the same time in both session level and
1912 // media level.
1913 if (session_level && media_level) {
1914 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001915 EXPECT_FALSE(
1916 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1918 } else {
1919 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1920 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1921 }
1922 }
1923
1924 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001925 const std::string& name,
1926 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 cricket::CodecParameterMap::const_iterator found = params.find(name);
1928 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001929 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 }
1931
1932 void TestDeserializeCodecParams(const CodecParams& params,
1933 JsepSessionDescription* jdesc_output) {
1934 std::string sdp =
1935 "v=0\r\n"
1936 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1937 "s=-\r\n"
1938 "t=0 0\r\n"
1939 // Include semantics for WebRTC Media Streams since it is supported by
1940 // this parser, and will be added to the SDP when serializing a session
1941 // description.
1942 "a=msid-semantic: WMS\r\n"
1943 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001944 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 // Pltype 111 listed before 103 and 104 in the map.
1946 "a=rtpmap:111 opus/48000/2\r\n"
1947 // Pltype 103 listed before 104.
1948 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001949 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001950 "a=fmtp:111 0-15,66,70\r\n"
1951 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001953 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001954 << "; sprop-stereo=" << params.sprop_stereo
1955 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001956 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 << "a=ptime:" << params.ptime << "\r\n"
1958 << "a=maxptime:" << params.max_ptime << "\r\n";
1959 sdp += os.str();
1960
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001961 os.clear();
1962 os.str("");
1963 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001964 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001965 << "a=rtpmap:99 VP8/90000\r\n"
1966 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001967 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001968 sdp += os.str();
1969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 // Deserialize
1971 SdpParseError error;
1972 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1973
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001975 GetFirstAudioContentDescription(jdesc_output->description());
1976 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 ASSERT_FALSE(acd->codecs().empty());
1978 cricket::AudioCodec opus = acd->codecs()[0];
1979 EXPECT_EQ("opus", opus.name);
1980 EXPECT_EQ(111, opus.id);
1981 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1982 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1983 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1984 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001985 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1986 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1988 cricket::AudioCodec codec = acd->codecs()[i];
1989 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1990 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001992
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001993 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001994 GetFirstVideoContentDescription(jdesc_output->description());
1995 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001996 ASSERT_FALSE(vcd->codecs().empty());
1997 cricket::VideoCodec vp8 = vcd->codecs()[0];
1998 EXPECT_EQ("VP8", vp8.name);
1999 EXPECT_EQ(99, vp8.id);
2000 cricket::VideoCodec rtx = vcd->codecs()[1];
2001 EXPECT_EQ("RTX", rtx.name);
2002 EXPECT_EQ(95, rtx.id);
2003 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 }
2005
2006 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
2007 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002008 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 "v=0\r\n"
2010 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2011 "s=-\r\n"
2012 "t=0 0\r\n"
2013 // Include semantics for WebRTC Media Streams since it is supported by
2014 // this parser, and will be added to the SDP when serializing a session
2015 // description.
2016 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002017 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002018 "a=rtpmap:111 opus/48000/2\r\n";
2019 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 "m=video 3457 RTP/SAVPF 101\r\n"
2021 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +02002022 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002024 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002025 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002027 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02002028 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002029 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02002030 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00002031 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 // Deserialize
2033 SdpParseError error;
2034 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002036 GetFirstAudioContentDescription(jdesc_output->description());
2037 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 ASSERT_FALSE(acd->codecs().empty());
2039 cricket::AudioCodec opus = acd->codecs()[0];
2040 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002041 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2042 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002045 GetFirstVideoContentDescription(jdesc_output->description());
2046 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 ASSERT_FALSE(vcd->codecs().empty());
2048 cricket::VideoCodec vp8 = vcd->codecs()[0];
2049 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2050 vp8.name.c_str());
2051 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002052 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 13:40:02 +02002053 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2054 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 15:03:05 +02002055 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2056 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2057 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2058 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2059 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2060 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2061 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 }
2063
2064 // Two SDP messages can mean the same thing but be different strings, e.g.
2065 // some of the lines can be serialized in different order.
2066 // However, a deserialized description can be compared field by field and has
2067 // no order. If deserializer has already been tested, serializing then
2068 // deserializing and comparing JsepSessionDescription will test
2069 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002070 void TestSerialize(const JsepSessionDescription& jdesc) {
2071 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002072 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 SdpParseError error;
2074 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2075 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2076 }
2077
zhihuang38989e52017-03-21 11:04:53 -07002078 // Calling 'Initialize' with a copy of the inner SessionDescription will
2079 // create a copy of the JsepSessionDescription without candidates. The
2080 // 'connection address' field, previously set from the candidates, must also
2081 // be reset.
2082 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2083 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2084 rtc::SocketAddress video_addr("0.0.0.0", 9);
2085 audio_desc_->set_connection_address(audio_addr);
2086 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002087 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 11:04:53 -07002088 }
2089
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 protected:
2091 SessionDescription desc_;
2092 AudioContentDescription* audio_desc_;
2093 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002094 RtpDataContentDescription* data_desc_;
2095 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002097 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 JsepSessionDescription jdesc_;
2099};
2100
2101void TestMismatch(const std::string& string1, const std::string& string2) {
2102 int position = 0;
2103 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2104 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002105 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 break;
2107 }
2108 }
2109 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2110 << " character\n"
2111 << " 1: " << string1.substr(position, 20) << "\n"
2112 << " 2: " << string2.substr(position, 20) << "\n";
2113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2116 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002117 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 TestMismatch(std::string(kSdpFullString), message);
2119}
2120
2121TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002122 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002123 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124}
2125
2126// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2127// the case in a DTLS offer.
2128TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2129 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002130 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002131 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002132 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
2134 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002135 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2136 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 EXPECT_EQ(sdp_with_fingerprint, message);
2139}
2140
2141// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2142// be the case in a DTLS answer.
2143TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2144 AddFingerprint();
2145 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002146 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002147 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002148 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149
2150 std::string sdp_with_fingerprint = kSdpString;
2151 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2152 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002153 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2154 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155
2156 EXPECT_EQ(sdp_with_fingerprint, message);
2157}
2158
2159TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2160 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002161 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002162 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002163 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 EXPECT_EQ(std::string(kSdpString), message);
2165}
2166
2167TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2168 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2169 group.AddContentName(kAudioContentName);
2170 group.AddContentName(kVideoContentName);
2171 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002172 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002174 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 std::string sdp_with_bundle = kSdpFullString;
2176 InjectAfter(kSessionTime,
2177 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2178 &sdp_with_bundle);
2179 EXPECT_EQ(sdp_with_bundle, message);
2180}
2181
2182TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002183 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002185 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002187 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002189 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002191 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002193 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 &sdp_with_bandwidth);
2195 EXPECT_EQ(sdp_with_bandwidth, message);
2196}
2197
2198TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2199 std::vector<std::string> transport_options;
2200 transport_options.push_back(kIceOption1);
2201 transport_options.push_back(kIceOption3);
2202 AddIceOptions(kAudioContentName, transport_options);
2203 transport_options.clear();
2204 transport_options.push_back(kIceOption2);
2205 transport_options.push_back(kIceOption3);
2206 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002207 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002209 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002211 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002213 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 &sdp_with_ice_options);
2215 EXPECT_EQ(sdp_with_ice_options, message);
2216}
2217
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002218TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithOpaqueTransportParams) {
2219 cricket::OpaqueTransportParameters params;
2220 params.protocol = "foo";
2221 params.parameters = "test64";
2222 AddOpaqueTransportParameters(kAudioContentName, params);
2223 AddOpaqueTransportParameters(kVideoContentName, params);
2224
2225 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2226 jdesc_.session_version()));
2227 std::string message = webrtc::SdpSerialize(jdesc_);
2228
2229 std::string sdp_with_transport_parameters = kSdpFullString;
2230 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2231 &sdp_with_transport_parameters);
2232 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2233 &sdp_with_transport_parameters);
2234 EXPECT_EQ(message, sdp_with_transport_parameters);
2235}
2236
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002238 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239}
2240
2241TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002242 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243}
2244
2245TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002246 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247}
2248
2249TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2250 EXPECT_TRUE(TestSerializeRejected(true, false));
2251}
2252
2253TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2254 EXPECT_TRUE(TestSerializeRejected(false, true));
2255}
2256
2257TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2258 EXPECT_TRUE(TestSerializeRejected(true, true));
2259}
2260
2261TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2262 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002263 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264
zhihuang38989e52017-03-21 11:04:53 -07002265 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002266 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267
2268 std::string expected_sdp = kSdpString;
2269 expected_sdp.append(kSdpRtpDataChannelString);
2270 EXPECT_EQ(expected_sdp, message);
2271}
2272
2273TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002274 bool use_sctpmap = true;
2275 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002276 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277
zhihuang38989e52017-03-21 11:04:53 -07002278 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002279 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280
2281 std::string expected_sdp = kSdpString;
2282 expected_sdp.append(kSdpSctpDataChannelString);
2283 EXPECT_EQ(message, expected_sdp);
2284}
2285
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002286void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2287 const SessionDescription& desc,
2288 int port) {
2289 // Take our pre-built session description and change the SCTP port.
2290 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2291 SctpDataContentDescription* dcdesc =
2292 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2293 dcdesc->set_port(port);
2294 ASSERT_TRUE(
2295 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2296}
2297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002298TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002299 bool use_sctpmap = true;
2300 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002301 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002302 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002303
2304 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002305 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002306
Steve Antone831b8c2018-02-01 12:22:16 -08002307 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002308
2309 std::string expected_sdp = kSdpString;
2310 expected_sdp.append(kSdpSctpDataChannelString);
2311
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002312 absl::StrReplaceAll(
2313 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2314 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002315
2316 EXPECT_EQ(expected_sdp, message);
2317}
2318
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002319TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002320 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002321 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002322 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002323 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002324 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002325
2326 std::string expected_sdp = kSdpString;
2327 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002328 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002329 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002330 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002331 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002332}
2333
Johannes Kron0854eb62018-10-10 22:33:20 +02002334TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002335 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002336 TestSerialize(jdesc_);
2337}
2338
2339TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2340 cricket::MediaContentDescription* video_desc =
2341 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2342 ASSERT_TRUE(video_desc);
2343 cricket::MediaContentDescription* audio_desc =
2344 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2345 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002346 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002347 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002348 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002349 cricket::MediaContentDescription::kMedia);
2350 TestSerialize(jdesc_);
2351}
2352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002354 bool encrypted = false;
2355 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002356 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002357 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002358 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359
2360 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002361 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2362 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363
2364 EXPECT_EQ(sdp_with_extmap, message);
2365}
2366
jbauch5869f502017-06-29 12:31:36 -07002367TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2368 bool encrypted = true;
2369 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002370 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002371 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002372 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002373 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002374}
2375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376TEST_F(WebRtcSdpTest, SerializeCandidates) {
2377 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002378 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002379
2380 Candidate candidate_with_ufrag(candidates_.front());
2381 candidate_with_ufrag.set_username("ABC");
2382 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2383 candidate_with_ufrag));
2384 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2385 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002386
2387 Candidate candidate_with_network_info(candidates_.front());
2388 candidate_with_network_info.set_network_id(1);
2389 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2390 candidate_with_network_info));
2391 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2392 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2393 candidate_with_network_info.set_network_cost(999);
2394 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2395 candidate_with_network_info));
2396 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2397 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2398 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399}
2400
Zach Steinb336c272018-08-09 01:16:13 -07002401TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2402 rtc::SocketAddress address("a.test", 1234);
2403 cricket::Candidate candidate(
2404 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2405 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2406 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2407 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2408 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2409}
2410
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002411// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2412// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002413TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002414 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002415 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2416 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2417 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002418 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002419 std::unique_ptr<IceCandidateInterface> jcandidate(
2420 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002421
2422 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2423 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2424}
2425
htaa6b99442016-04-12 10:29:17 -07002426TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002427 cricket::VideoCodec h264_codec("H264");
2428 h264_codec.SetParam("profile-level-id", "42e01f");
2429 h264_codec.SetParam("level-asymmetry-allowed", "1");
2430 h264_codec.SetParam("packetization-mode", "1");
2431 video_desc_->AddCodec(h264_codec);
2432
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002433 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 10:29:17 -07002434
Steve Antone831b8c2018-02-01 12:22:16 -08002435 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002436 size_t after_pt = message.find(" H264/90000");
2437 ASSERT_NE(after_pt, std::string::npos);
2438 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2439 ASSERT_NE(before_pt, std::string::npos);
2440 before_pt += strlen("a=rtpmap:");
2441 std::string pt = message.substr(before_pt, after_pt - before_pt);
2442 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2443 std::string to_find = "a=fmtp:" + pt + " ";
2444 size_t fmtp_pos = message.find(to_find);
2445 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002446 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002447 ASSERT_NE(std::string::npos, fmtp_endpos);
2448 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2449 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2450 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2451 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002452 // Check that there are no spaces after semicolons.
2453 // https://bugs.webrtc.org/5793
2454 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002455}
2456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002458 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 // Deserialize
2460 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2461 // Verify
2462 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2463}
2464
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002465TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002466 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002467 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002468 "v=0\r\n"
2469 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2470 "s=-\r\n"
2471 "t=0 0\r\n"
2472 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002473 // Deserialize
2474 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2475 EXPECT_EQ(0u, jdesc.description()->contents().size());
2476}
2477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002479 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 std::string sdp_without_carriage_return = kSdpFullString;
2481 Replace("\r\n", "\n", &sdp_without_carriage_return);
2482 // Deserialize
2483 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2484 // Verify
2485 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2486}
2487
2488TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2489 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002490 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002491 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 15:03:05 +02002492 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002493 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2495 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2496}
2497
2498TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2499 static const char kSdpNoRtpmapString[] =
2500 "v=0\r\n"
2501 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2502 "s=-\r\n"
2503 "t=0 0\r\n"
2504 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2505 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002506 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 // The rtpmap line for static payload codec is optional.
2508 "a=rtpmap:18 G729/16000\r\n"
2509 "a=rtpmap:103 ISAC/16000\r\n";
2510
Steve Antona3a92c22017-12-07 10:27:41 -08002511 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2513 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002514 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002516 // The codecs in the AudioContentDescription should be in the same order as
2517 // the payload types (<fmt>s) on the m= line.
2518 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2519 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002520 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 EXPECT_EQ(ref_codecs, audio->codecs());
2522}
2523
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002524TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2525 static const char kSdpNoRtpmapString[] =
2526 "v=0\r\n"
2527 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2528 "s=-\r\n"
2529 "t=0 0\r\n"
2530 "m=audio 49232 RTP/AVP 18 103\r\n"
2531 "a=fmtp:18 annexb=yes\r\n"
2532 "a=rtpmap:103 ISAC/16000\r\n";
2533
Steve Antona3a92c22017-12-07 10:27:41 -08002534 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002535 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2536 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002537 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002538
2539 cricket::AudioCodec g729 = audio->codecs()[0];
2540 EXPECT_EQ("G729", g729.name);
2541 EXPECT_EQ(8000, g729.clockrate);
2542 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002543 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002544 ASSERT_TRUE(found != g729.params.end());
2545 EXPECT_EQ(found->second, "yes");
2546
2547 cricket::AudioCodec isac = audio->codecs()[1];
2548 EXPECT_EQ("ISAC", isac.name);
2549 EXPECT_EQ(103, isac.id);
2550 EXPECT_EQ(16000, isac.clockrate);
2551}
2552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553// Ensure that we can deserialize SDP with a=fingerprint properly.
2554TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2555 // Add a DTLS a=fingerprint attribute to our session description.
2556 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002557 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002558 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 jdesc_.session_version()));
2560
Steve Antona3a92c22017-12-07 10:27:41 -08002561 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 std::string sdp_with_fingerprint = kSdpString;
2563 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2564 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2565 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2566 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2567}
2568
2569TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002570 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 std::string sdp_with_bundle = kSdpFullString;
2572 InjectAfter(kSessionTime,
2573 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2574 &sdp_with_bundle);
2575 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2576 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2577 group.AddContentName(kAudioContentName);
2578 group.AddContentName(kVideoContentName);
2579 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002580 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 jdesc_.session_version()));
2582 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2583}
2584
2585TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002586 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002588 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002590 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002592 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002593 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002595 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002597 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 jdesc_.session_version()));
2599 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2600}
2601
2602TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002603 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002605 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002607 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002609 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 &sdp_with_ice_options);
2611 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2612 std::vector<std::string> transport_options;
2613 transport_options.push_back(kIceOption3);
2614 transport_options.push_back(kIceOption1);
2615 AddIceOptions(kAudioContentName, transport_options);
2616 transport_options.clear();
2617 transport_options.push_back(kIceOption3);
2618 transport_options.push_back(kIceOption2);
2619 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002620 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 jdesc_.session_version()));
2622 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2623}
2624
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -07002625TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithOpaqueTransportParams) {
2626 std::string sdp_with_transport_parameters = kSdpFullString;
2627 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2628 &sdp_with_transport_parameters);
2629 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2630 &sdp_with_transport_parameters);
2631
2632 JsepSessionDescription jdesc_with_transport_parameters(kDummyType);
2633 EXPECT_TRUE(SdpDeserialize(sdp_with_transport_parameters,
2634 &jdesc_with_transport_parameters));
2635
2636 cricket::OpaqueTransportParameters params;
2637 params.protocol = "foo";
2638 params.parameters = "test64";
2639
2640 AddOpaqueTransportParameters(kAudioContentName, params);
2641 AddOpaqueTransportParameters(kVideoContentName, params);
2642
2643 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2644 jdesc_.session_version()));
2645 EXPECT_TRUE(
2646 CompareSessionDescription(jdesc_, jdesc_with_transport_parameters));
2647}
2648
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2650 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002651 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 std::string sdp_with_ufrag_pwd = kSdpFullString;
2653 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2654 // Add session level ufrag and pwd
2655 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002656 "a=ice-pwd:session+level+icepwd\r\n"
2657 "a=ice-ufrag:session+level+iceufrag\r\n",
2658 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002660 InjectAfter(
2661 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2663 &sdp_with_ufrag_pwd);
2664 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002665 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2666 "media+level+icepwd"));
2667 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2668 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2670 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2671}
2672
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002674 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675}
2676
2677TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002678 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679}
2680
2681TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002682 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683}
2684
2685TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2686 EXPECT_TRUE(TestDeserializeRejected(true, false));
2687}
2688
2689TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2690 EXPECT_TRUE(TestDeserializeRejected(false, true));
2691}
2692
2693TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2694 EXPECT_TRUE(TestDeserializeRejected(true, true));
2695}
2696
2697// Tests that we can still handle the sdp uses mslabel and label instead of
2698// msid for backward compatibility.
2699TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002700 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002701 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 std::string sdp_without_msid = kSdpFullString;
2703 Replace("msid", "xmsid", &sdp_without_msid);
2704 // Deserialize
2705 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2706 // Verify
2707 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002708 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2709 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710}
2711
Johannes Kron0854eb62018-10-10 22:33:20 +02002712TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002713 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002714 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2715 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2716 // Deserialize
2717 JsepSessionDescription jdesc_deserialized(kDummyType);
2718 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2719 // Verify
2720 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2721}
2722
2723TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002724 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002725 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2726 // Deserialize
2727 JsepSessionDescription jdesc_deserialized(kDummyType);
2728 EXPECT_TRUE(
2729 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2730 // Verify
2731 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2732}
2733
2734TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2735 cricket::MediaContentDescription* video_desc =
2736 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2737 ASSERT_TRUE(video_desc);
2738 cricket::MediaContentDescription* audio_desc =
2739 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2740 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002741 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002742 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002743 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002744 cricket::MediaContentDescription::kMedia);
2745
2746 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2747 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2748 &sdp_with_extmap_allow_mixed);
2749 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2750 &sdp_with_extmap_allow_mixed);
2751
2752 // Deserialize
2753 JsepSessionDescription jdesc_deserialized(kDummyType);
2754 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2755 // Verify
2756 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2757}
2758
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2760 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2761
2762 std::string sdp = kSdpOneCandidate;
2763 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2764 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2765 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2766 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002767 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768
2769 // Candidate line without generation extension.
2770 sdp = kSdpOneCandidate;
2771 Replace(" generation 2", "", &sdp);
2772 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2773 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2774 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2775 Candidate expected = jcandidate_->candidate();
2776 expected.set_generation(0);
2777 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2778
honghaiza0c44ea2016-03-23 16:07:48 -07002779 // Candidate with network id and/or cost.
2780 sdp = kSdpOneCandidate;
2781 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2782 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2783 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2784 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2785 expected = jcandidate_->candidate();
2786 expected.set_network_id(2);
2787 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2788 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2789 // Add network cost
2790 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2791 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2792 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2793 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2794
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002795 sdp = kSdpTcpActiveCandidate;
2796 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2797 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002798 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002799 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2800 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2801 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002802 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2803 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002804 EXPECT_TRUE(
2805 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002806 sdp = kSdpTcpPassiveCandidate;
2807 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2808 sdp = kSdpTcpSOCandidate;
2809 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810}
2811
2812// This test verifies the deserialization of candidate-attribute
2813// as per RFC 5245. Candiate-attribute will be of the format
2814// candidate:<blah>. This format will be used when candidates
2815// are trickled.
2816TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2817 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2818
2819 std::string candidate_attribute = kRawCandidate;
2820 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2821 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2822 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2823 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2824 EXPECT_EQ(2u, jcandidate.candidate().generation());
2825
2826 // Candidate line without generation extension.
2827 candidate_attribute = kRawCandidate;
2828 Replace(" generation 2", "", &candidate_attribute);
2829 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2830 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2831 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2832 Candidate expected = jcandidate_->candidate();
2833 expected.set_generation(0);
2834 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2835
2836 // Candidate line without candidate:
2837 candidate_attribute = kRawCandidate;
2838 Replace("candidate:", "", &candidate_attribute);
2839 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2840
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002841 // Candidate line with IPV6 address.
2842 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002843
2844 // Candidate line with hostname address.
2845 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002846}
2847
2848// This test verifies that the deserialization of an invalid candidate string
2849// fails.
2850TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002851 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002852
2853 std::string candidate_attribute = kRawCandidate;
2854 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002856
2857 candidate_attribute = kSdpOneCandidate;
2858 candidate_attribute.replace(0, 1, "x");
2859 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2860
2861 candidate_attribute = kRawCandidate;
2862 candidate_attribute.append("\r\n");
2863 candidate_attribute.append(kRawCandidate);
2864 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2865
2866 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867}
2868
2869TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2870 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002871 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002872 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873
2874 std::string sdp_with_data = kSdpString;
2875 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002876 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877
2878 // Deserialize
2879 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2880 // Verify
2881 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2882}
2883
2884TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002885 bool use_sctpmap = true;
2886 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002887 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002888 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889
2890 std::string sdp_with_data = kSdpString;
2891 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002892 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002894 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:35 +00002895 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2896 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2897
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002898 // Verify with DTLS/SCTP.
2899 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2900 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002901 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2902 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2903
2904 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:38 +00002905 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 15:03:05 +02002906 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2908 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2909}
2910
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002911TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002912 bool use_sctpmap = false;
2913 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002914 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002915 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002916
2917 std::string sdp_with_data = kSdpString;
2918 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002919 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002920
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002921 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2922 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2923}
2924
lally69f57602015-10-08 10:15:04 -07002925TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002926 bool use_sctpmap = false;
2927 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002928 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002929 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 10:15:04 -07002930
2931 std::string sdp_with_data = kSdpString;
2932 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002933 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002934
lally69f57602015-10-08 10:15:04 -07002935 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2936 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2937}
2938
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002939// Helper function to set the max-message-size parameter in the
2940// SCTP data codec.
2941void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002942 int new_value,
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002943 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002944 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002945 SctpDataContentDescription* dcdesc =
2946 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2947 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 09:31:04 +02002948 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002949}
2950
2951TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
2952 bool use_sctpmap = false;
2953 AddSctpDataChannel(use_sctpmap);
2954 JsepSessionDescription jdesc(kDummyType);
2955 std::string sdp_with_data = kSdpString;
2956
2957 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2958 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02002959 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002960 JsepSessionDescription jdesc_output(kDummyType);
2961
Harald Alvestrand48cce4d2019-04-11 10:41:24 +02002962 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2963 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2964}
2965
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +02002966TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
2967 bool use_sctpmap = false;
2968 AddSctpDataChannel(use_sctpmap);
2969 JsepSessionDescription jdesc(kDummyType);
2970 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
2971 std::string message = webrtc::SdpSerialize(jdesc);
2972 EXPECT_NE(std::string::npos,
2973 message.find("\r\na=max-message-size:12345\r\n"));
2974 JsepSessionDescription jdesc_output(kDummyType);
2975 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2976 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2977}
2978
2979TEST_F(WebRtcSdpTest,
2980 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
2981 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
2982 // The default max message size is 64K.
2983 bool use_sctpmap = false;
2984 AddSctpDataChannel(use_sctpmap);
2985 JsepSessionDescription jdesc(kDummyType);
2986 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
2987 std::string message = webrtc::SdpSerialize(jdesc);
2988 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
2989 JsepSessionDescription jdesc_output(kDummyType);
2990 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
2991 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2992}
2993
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002994// Test to check the behaviour if sctp-port is specified
2995// on the m= line and in a=sctp-port.
2996TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002997 bool use_sctpmap = true;
2998 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002999 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003000 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003001
3002 std::string sdp_with_data = kSdpString;
3003 // Append m= attributes
3004 sdp_with_data.append(kSdpSctpDataChannelString);
3005 // Append a=sctp-port attribute
3006 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08003007 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003008
3009 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3010}
3011
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003012// Test behavior if a=rtpmap occurs in an SCTP section.
3013TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
3014 std::string sdp_with_data = kSdpString;
3015 // Append m= attributes
3016 sdp_with_data.append(kSdpSctpDataChannelString);
3017 // Append a=rtpmap attribute
3018 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
3019 JsepSessionDescription jdesc_output(kDummyType);
3020 // Correct behavior is to ignore the extra attribute.
3021 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3022}
3023
3024TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
3025 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
3026 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
3027 for (auto proto : bad_strings) {
3028 std::string sdp_with_data = kSdpString;
3029 sdp_with_data.append("m=application 9 ");
3030 sdp_with_data.append(proto);
3031 sdp_with_data.append(" 47\r\n");
3032 JsepSessionDescription jdesc_output(kDummyType);
3033 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3034 << "Parsing should have failed on " << proto;
3035 }
3036 // The following strings are strange, but acceptable as RTP.
3037 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
3038 "obviously-bogus/RTP/"};
3039 for (auto proto : weird_strings) {
3040 std::string sdp_with_data = kSdpString;
3041 sdp_with_data.append("m=application 9 ");
3042 sdp_with_data.append(proto);
3043 sdp_with_data.append(" 47\r\n");
3044 JsepSessionDescription jdesc_output(kDummyType);
3045 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
3046 << "Parsing should have succeeded on " << proto;
3047 }
3048}
3049
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003050// For crbug/344475.
3051TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3052 std::string sdp_with_data = kSdpString;
3053 sdp_with_data.append(kSdpSctpDataChannelString);
3054 // Remove the "\n" at the end.
3055 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08003056 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00003057
3058 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3059 // No crash is a pass.
3060}
3061
zstein4b2e0822017-02-17 19:48:38 -08003062TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3063 bool use_sctpmap = true;
3064 AddSctpDataChannel(use_sctpmap);
3065
3066 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08003067 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003068 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:02 +00003069
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00003070 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00003071 std::string sdp_with_data = kSdpString;
3072 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003073 absl::StrReplaceAll(
3074 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3075 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003076 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00003077
3078 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3079 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08003080}
3081
3082TEST_F(WebRtcSdpTest,
3083 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3084 bool use_sctpmap = false;
3085 AddSctpDataChannel(use_sctpmap);
3086
Steve Antona3a92c22017-12-07 10:27:41 -08003087 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003088 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003089
3090 // We need to test the deserialized JsepSessionDescription from
3091 // kSdpSctpDataChannelStringWithSctpPort for
3092 // draft-ietf-mmusic-sctp-sdp-07
3093 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08003094 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003095 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 15:13:09 -08003096 absl::StrReplaceAll(
3097 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3098 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08003099 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00003100
3101 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3102 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00003103}
3104
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003105TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003106 // We want to test that deserializing data content limits bandwidth
3107 // settings (it should never be greater than the default).
3108 // This should prevent someone from using unlimited data bandwidth through
3109 // JS and "breaking the Internet".
3110 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003111 std::string sdp_with_bandwidth = kSdpString;
3112 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003113 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003114 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003115 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003116
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003117 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3118}
3119
3120TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08003121 bool use_sctpmap = true;
3122 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08003123 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02003124 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003125 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003126 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003127
3128 std::string sdp_with_bandwidth = kSdpString;
3129 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02003130 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003131 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08003132 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07003133
3134 // SCTP has congestion control, so we shouldn't limit the bandwidth
3135 // as we do for RTP.
3136 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003137 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3138}
3139
Yves Gerey665174f2018-06-19 15:03:05 +02003140class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003141 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003142
3143TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003144 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003145 bool encrypted = GetParam();
3146 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147}
3148
Yves Gerey665174f2018-06-19 15:03:05 +02003149TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003150 bool encrypted = GetParam();
3151 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152}
3153
Yves Gerey665174f2018-06-19 15:03:05 +02003154TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003155 bool encrypted = GetParam();
3156 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157}
3158
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003159INSTANTIATE_TEST_SUITE_P(Encrypted,
3160 WebRtcSdpExtmapTest,
3161 ::testing::Values(false, true));
jbauch5869f502017-06-29 12:31:36 -07003162
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003163TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003164 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003165 std::string sdp = kSdpFullString;
3166 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3167 // Deserialize
3168 SdpParseError error;
3169 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003170 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003171 EXPECT_EQ(lastline, error.line);
3172 EXPECT_EQ("Invalid SDP line.", error.description);
3173}
3174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003175TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3176 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3177 std::string new_sdp = kSdpOneCandidate;
3178 Replace("udp", "unsupported_transport", &new_sdp);
3179 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3180 new_sdp = kSdpOneCandidate;
3181 Replace("udp", "uDP", &new_sdp);
3182 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3183 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3184 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3185 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3186}
3187
honghaiza54a0802015-12-16 18:37:23 -08003188TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003190 EXPECT_TRUE(
3191 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3193 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3194 Candidate ref_candidate = jcandidate_->candidate();
3195 ref_candidate.set_username("user_rtp");
3196 ref_candidate.set_password("password_rtp");
3197 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3198}
3199
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003200TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003201 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003202
3203 // Deserialize
3204 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3205
3206 // Verify
3207 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003208 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003209 EXPECT_TRUE(audio->conference_mode());
3210
3211 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003212 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003213 EXPECT_TRUE(video->conference_mode());
3214}
3215
deadbeefd45aea82017-09-16 01:24:29 -07003216TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003217 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003218
3219 // We tested deserialization already above, so just test that if we serialize
3220 // and deserialize the flag doesn't disappear.
3221 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003222 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003223 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3224
3225 // Verify.
3226 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003227 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003228 EXPECT_TRUE(audio->conference_mode());
3229
3230 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003231 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003232 EXPECT_TRUE(video->conference_mode());
3233}
3234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3236 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003237 const char kSdpEmptyType[] = " =candidate";
3238 const char kSdpEqualAsPlus[] = "a+candidate";
3239 const char kSdpSpaceAfterEqual[] = "a= candidate";
3240 const char kSdpUpperType[] = "A=candidate";
3241 const char kSdpEmptyLine[] = "";
3242 const char kSdpMissingValue[] = "a=";
3243
Yves Gerey665174f2018-06-19 15:03:05 +02003244 const char kSdpBrokenFingerprint[] =
3245 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003246 "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 +02003247 const char kSdpExtraField[] =
3248 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 "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 +02003250 const char kSdpMissingSpace[] =
3251 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252 "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 +00003253 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003254 const char kSdpMd5[] =
3255 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003256 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257
3258 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003259 ExpectParseFailure("v=", kSdpDestroyer);
3260 ExpectParseFailure("o=", kSdpDestroyer);
3261 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003262 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003263 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264
3265 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003266 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3267 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268
3269 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003270 ExpectParseFailure("a=candidate", kSdpEmptyType);
3271 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3272 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3273 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274
3275 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3276 // because it's orthogonal to what we are replacing and hence
3277 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003278 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3279 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3280 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3281 ExpectParseFailure("a=sendrecv", kSdpMd5);
3282
3283 // Empty Line
3284 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3285 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003286}
3287
3288TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3289 // ssrc
3290 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003291 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003292 // crypto
3293 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3294 // rtpmap
3295 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3296 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3297 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3298 // candidate
3299 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3300 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3301 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3302 ExpectParseFailure("rport 2346", "rport badvalue");
3303 ExpectParseFailure("rport 2346 generation 2",
3304 "rport 2346 generation badvalue");
3305 // m line
3306 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3307 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3308
3309 // bandwidth
3310 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003311 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003312 // rtcp-fb
3313 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3314 "a=rtcp-fb:badvalue nack\r\n",
3315 "a=rtcp-fb:badvalue nack");
3316 // extmap
3317 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3318 "a=extmap:badvalue http://example.com\r\n",
3319 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320}
3321
3322TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003323 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324
3325 const char kSdpWithReorderedPlTypesString[] =
3326 "v=0\r\n"
3327 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3328 "s=-\r\n"
3329 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003330 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003331 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3332 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003334 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335
3336 // Deserialize
3337 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3338
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003340 GetFirstAudioContentDescription(jdesc_output.description());
3341 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003343 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3344 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 EXPECT_EQ(104, acd->codecs()[0].id);
3346}
3347
3348TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003349 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 CodecParams params;
3351 params.max_ptime = 40;
3352 params.ptime = 30;
3353 params.min_ptime = 10;
3354 params.sprop_stereo = 1;
3355 params.stereo = 1;
3356 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003357 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003359 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360}
3361
3362TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3363 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003364 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003366 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367}
3368
3369TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3370 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003371 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003373 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374}
3375
3376TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003377 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378
3379 const char kSdpWithFmtpString[] =
3380 "v=0\r\n"
3381 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3382 "s=-\r\n"
3383 "t=0 0\r\n"
3384 "m=video 3457 RTP/SAVPF 120\r\n"
3385 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003386 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3387
3388 // Deserialize
3389 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003390 EXPECT_TRUE(
3391 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003392
Donald Curtis0e07f922015-05-15 09:21:23 -07003393 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003394 GetFirstVideoContentDescription(jdesc_output.description());
3395 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003396 ASSERT_FALSE(vcd->codecs().empty());
3397 cricket::VideoCodec vp8 = vcd->codecs()[0];
3398 EXPECT_EQ("VP8", vp8.name);
3399 EXPECT_EQ(120, vp8.id);
3400 cricket::CodecParameterMap::iterator found =
3401 vp8.params.find("x-google-min-bitrate");
3402 ASSERT_TRUE(found != vp8.params.end());
3403 EXPECT_EQ(found->second, "10");
3404 found = vp8.params.find("x-google-max-quantization");
3405 ASSERT_TRUE(found != vp8.params.end());
3406 EXPECT_EQ(found->second, "40");
3407}
3408
johan2d8d23e2016-06-03 01:22:42 -07003409TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003410 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003411
3412 const char kSdpWithFmtpString[] =
3413 "v=0\r\n"
3414 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3415 "s=-\r\n"
3416 "t=0 0\r\n"
3417 "m=video 49170 RTP/AVP 98\r\n"
3418 "a=rtpmap:98 H264/90000\r\n"
3419 "a=fmtp:98 profile-level-id=42A01E; "
3420 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3421
3422 // Deserialize.
3423 SdpParseError error;
3424 EXPECT_TRUE(
3425 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3426
johan2d8d23e2016-06-03 01:22:42 -07003427 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003428 GetFirstVideoContentDescription(jdesc_output.description());
3429 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003430 ASSERT_FALSE(vcd->codecs().empty());
3431 cricket::VideoCodec h264 = vcd->codecs()[0];
3432 EXPECT_EQ("H264", h264.name);
3433 EXPECT_EQ(98, h264.id);
3434 cricket::CodecParameterMap::const_iterator found =
3435 h264.params.find("profile-level-id");
3436 ASSERT_TRUE(found != h264.params.end());
3437 EXPECT_EQ(found->second, "42A01E");
3438 found = h264.params.find("sprop-parameter-sets");
3439 ASSERT_TRUE(found != h264.params.end());
3440 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3441}
3442
Donald Curtis0e07f922015-05-15 09:21:23 -07003443TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003444 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003445
3446 const char kSdpWithFmtpString[] =
3447 "v=0\r\n"
3448 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3449 "s=-\r\n"
3450 "t=0 0\r\n"
3451 "m=video 3457 RTP/SAVPF 120\r\n"
3452 "a=rtpmap:120 VP8/90000\r\n"
3453 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454
3455 // Deserialize
3456 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003457 EXPECT_TRUE(
3458 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003461 GetFirstVideoContentDescription(jdesc_output.description());
3462 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 ASSERT_FALSE(vcd->codecs().empty());
3464 cricket::VideoCodec vp8 = vcd->codecs()[0];
3465 EXPECT_EQ("VP8", vp8.name);
3466 EXPECT_EQ(120, vp8.id);
3467 cricket::CodecParameterMap::iterator found =
3468 vp8.params.find("x-google-min-bitrate");
3469 ASSERT_TRUE(found != vp8.params.end());
3470 EXPECT_EQ(found->second, "10");
3471 found = vp8.params.find("x-google-max-quantization");
3472 ASSERT_TRUE(found != vp8.params.end());
3473 EXPECT_EQ(found->second, "40");
3474}
3475
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003476TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3477 JsepSessionDescription jdesc_output(kDummyType);
3478
3479 const char kSdpWithPacketizationString[] =
3480 "v=0\r\n"
3481 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3482 "s=-\r\n"
3483 "t=0 0\r\n"
3484 "m=audio 9 RTP/SAVPF 111\r\n"
3485 "a=rtpmap:111 opus/48000/2\r\n"
3486 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3487 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3488 "a=rtpmap:120 VP8/90000\r\n"
3489 "a=packetization:120 raw\r\n"
3490 "a=rtpmap:121 VP9/90000\r\n"
3491 "a=rtpmap:122 H264/90000\r\n"
3492 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3493
3494 SdpParseError error;
3495 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3496 &error));
3497
3498 AudioContentDescription* acd =
3499 GetFirstAudioContentDescription(jdesc_output.description());
3500 ASSERT_TRUE(acd);
3501 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3502 cricket::AudioCodec opus = acd->codecs()[0];
3503 EXPECT_EQ(opus.name, "opus");
3504 EXPECT_EQ(opus.id, 111);
3505
3506 const VideoContentDescription* vcd =
3507 GetFirstVideoContentDescription(jdesc_output.description());
3508 ASSERT_TRUE(vcd);
3509 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3510 cricket::VideoCodec vp8 = vcd->codecs()[0];
3511 EXPECT_EQ(vp8.name, "VP8");
3512 EXPECT_EQ(vp8.id, 120);
3513 EXPECT_EQ(vp8.packetization, "raw");
3514 cricket::VideoCodec vp9 = vcd->codecs()[1];
3515 EXPECT_EQ(vp9.name, "VP9");
3516 EXPECT_EQ(vp9.id, 121);
3517 EXPECT_EQ(vp9.packetization, absl::nullopt);
3518 cricket::VideoCodec h264 = vcd->codecs()[2];
3519 EXPECT_EQ(h264.name, "H264");
3520 EXPECT_EQ(h264.id, 122);
3521 EXPECT_EQ(h264.packetization, absl::nullopt);
3522}
3523
ossuaa4b0772017-01-30 07:41:18 -08003524TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003525 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003526
3527 cricket::AudioCodecs codecs = acd->codecs();
3528 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3529 acd->set_codecs(codecs);
3530
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003531 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003532 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003533 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003534 std::string sdp_with_fmtp = kSdpFullString;
3535 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3536 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3537 &sdp_with_fmtp);
3538 EXPECT_EQ(sdp_with_fmtp, message);
3539}
3540
3541TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003542 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003543
3544 cricket::AudioCodecs codecs = acd->codecs();
3545 codecs[0].params["stereo"] = "1";
3546 acd->set_codecs(codecs);
3547
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003548 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003549 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003550 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003551 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003552 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003553 &sdp_with_fmtp);
3554 EXPECT_EQ(sdp_with_fmtp, message);
3555}
3556
3557TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003558 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003559
3560 cricket::AudioCodecs codecs = acd->codecs();
3561 codecs[0].params["ptime"] = "20";
3562 codecs[0].params["maxptime"] = "120";
3563 acd->set_codecs(codecs);
3564
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003565 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003566 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003567 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003568 std::string sdp_with_fmtp = kSdpFullString;
3569 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3570 "a=maxptime:120\r\n" // No comma here. String merging!
3571 "a=ptime:20\r\n",
3572 &sdp_with_fmtp);
3573 EXPECT_EQ(sdp_with_fmtp, message);
3574}
3575
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003577 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578
3579 cricket::VideoCodecs codecs = vcd->codecs();
3580 codecs[0].params["x-google-min-bitrate"] = "10";
3581 vcd->set_codecs(codecs);
3582
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003583 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003585 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586 std::string sdp_with_fmtp = kSdpFullString;
3587 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003588 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 EXPECT_EQ(sdp_with_fmtp, message);
3590}
3591
Mirta Dvornicic479a3c02019-06-04 15:38:50 +02003592TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3593 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3594
3595 cricket::VideoCodecs codecs = vcd->codecs();
3596 codecs[0].packetization = "raw";
3597 vcd->set_codecs(codecs);
3598
3599 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3600 jdesc_.session_version()));
3601 std::string message = webrtc::SdpSerialize(jdesc_);
3602 std::string sdp_with_packetization = kSdpFullString;
3603 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3604 &sdp_with_packetization);
3605 EXPECT_EQ(sdp_with_packetization, message);
3606}
3607
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003608TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3609 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003610 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611 std::string sdp_with_icelite = kSdpFullString;
3612 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3613 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3614 const cricket::TransportInfo* tinfo1 =
3615 desc->GetTransportInfoByName("audio_content_name");
3616 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3617 const cricket::TransportInfo* tinfo2 =
3618 desc->GetTransportInfoByName("video_content_name");
3619 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003620
3621 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003622 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3624 desc = jdesc_with_icelite.description();
3625 const cricket::TransportInfo* atinfo =
3626 desc->GetTransportInfoByName("audio_content_name");
3627 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3628 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003629 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003631
3632 // Now that we know deserialization works, we can use TestSerialize to test
3633 // serialization.
3634 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635}
3636
3637// Verifies that the candidates in the input SDP are parsed and serialized
3638// correctly in the output SDP.
3639TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3640 std::string sdp_with_data = kSdpString;
3641 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003642 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643
3644 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003645 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003646}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003647
3648TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3649 AddFingerprint();
3650 TransportInfo audio_transport_info =
3651 *(desc_.GetTransportInfoByName(kAudioContentName));
3652 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3653 audio_transport_info.description.connection_role);
3654 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003655 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003656
3657 TransportInfo video_transport_info =
3658 *(desc_.GetTransportInfoByName(kVideoContentName));
3659 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3660 video_transport_info.description.connection_role);
3661 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003662 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003663
3664 desc_.RemoveTransportInfoByName(kAudioContentName);
3665 desc_.RemoveTransportInfoByName(kVideoContentName);
3666
3667 desc_.AddTransportInfo(audio_transport_info);
3668 desc_.AddTransportInfo(video_transport_info);
3669
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003670 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003671 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003672 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003673 std::string sdp_with_dtlssetup = kSdpFullString;
3674
3675 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003676 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3677 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003678 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003679 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003680 EXPECT_EQ(sdp_with_dtlssetup, message);
3681}
3682
3683TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003684 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003685 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003686 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003687 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3688 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3689 const cricket::TransportInfo* atinfo =
3690 desc->GetTransportInfoByName("audio_content_name");
3691 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3692 atinfo->description.connection_role);
3693 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003694 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003695 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3696 vtinfo->description.connection_role);
3697}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003698
3699// Verifies that the order of the serialized m-lines follows the order of the
3700// ContentInfo in SessionDescription, and vise versa for deserialization.
3701TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003702 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003703 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3704 kSdpSctpDataChannelString};
3705 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3706 cricket::MEDIA_TYPE_VIDEO,
3707 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003708
3709 // Verifies all 6 permutations.
3710 for (size_t i = 0; i < 6; ++i) {
3711 size_t media_content_in_sdp[3];
3712 // The index of the first media content.
3713 media_content_in_sdp[0] = i / 2;
3714 // The index of the second media content.
3715 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3716 // The index of the third media content.
3717 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3718
3719 std::string sdp_string = kSdpSessionString;
3720 for (size_t i = 0; i < 3; ++i)
3721 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3722
3723 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3724 cricket::SessionDescription* desc = jdesc.description();
3725 EXPECT_EQ(3u, desc->contents().size());
3726
3727 for (size_t i = 0; i < 3; ++i) {
3728 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003729 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003730 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3731 }
3732
Steve Antone831b8c2018-02-01 12:22:16 -08003733 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003734 EXPECT_EQ(sdp_string, serialized_sdp);
3735 }
3736}
deadbeef9d3584c2016-02-16 17:54:10 -08003737
deadbeef25ed4352016-12-12 18:37:36 -08003738TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3739 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003740 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003741 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003742 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3743 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3744}
3745
deadbeef12771a12017-01-03 13:53:47 -08003746// The semantics of "a=bundle-only" are only defined when it's used in
3747// combination with a 0 port on the m= line. We should ignore it if used with a
3748// nonzero port.
3749TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3750 // Make the base bundle-only description but unset the bundle-only flag.
3751 MakeBundleOnlyDescription();
3752 jdesc_.description()->contents()[1].bundle_only = false;
3753
3754 std::string modified_sdp = kBundleOnlySdpFullString;
3755 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003756 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003757 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3758 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003759}
3760
3761TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3762 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003763 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003764}
3765
deadbeef9d3584c2016-02-16 17:54:10 -08003766TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3767 MakePlanBDescription();
3768
Steve Antona3a92c22017-12-07 10:27:41 -08003769 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003770 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3771
3772 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3773}
3774
3775TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3776 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003777 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003778}
3779
3780TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3781 MakeUnifiedPlanDescription();
3782
Steve Antona3a92c22017-12-07 10:27:41 -08003783 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003784 EXPECT_TRUE(
3785 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3786
3787 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3788}
3789
3790TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3791 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003792 TestSerialize(jdesc_);
3793}
3794
Seth Hampson5b4f0752018-04-02 16:31:36 -07003795// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003796// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3797// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003798// with no stream ids and multiple stream ids. For parsing this, the Unified
3799// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3800// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003801TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3802 // Create both msid lines for Plan B and Unified Plan support.
3803 MakeUnifiedPlanDescriptionMultipleStreamIds(
3804 cricket::kMsidSignalingMediaSection |
3805 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003806
3807 JsepSessionDescription deserialized_description(kDummyType);
3808 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3809 &deserialized_description));
3810
3811 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003812 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3813 cricket::kMsidSignalingSsrcAttribute,
3814 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003815}
3816
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003817// Tests the serialization of a Unified Plan SDP that is compatible for both
3818// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3819// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3820// multiple stream ids.
3821TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3822 // Create both msid lines for Plan B and Unified Plan support.
3823 MakeUnifiedPlanDescriptionMultipleStreamIds(
3824 cricket::kMsidSignalingMediaSection |
3825 cricket::kMsidSignalingSsrcAttribute);
3826 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3827 // We explicitly test that the serialized SDP string is equal to the hard
3828 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3829 // take priority over "a=ssrc msid" lines. This means if we just used
3830 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3831 // and still pass, because the deserialized version would be the same.
3832 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3833}
3834
3835// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3836// that signal stream IDs) is deserialized appropriately. It tests the case for
3837// no stream ids and multiple stream ids.
3838TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3839 // Only create a=msid lines for strictly Unified Plan stream ID support.
3840 MakeUnifiedPlanDescriptionMultipleStreamIds(
3841 cricket::kMsidSignalingMediaSection);
3842
3843 JsepSessionDescription deserialized_description(kDummyType);
3844 std::string unified_plan_sdp_string =
3845 kUnifiedPlanSdpFullStringWithSpecialMsid;
3846 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3847 EXPECT_TRUE(
3848 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3849
3850 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3851}
3852
3853// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3854// that signal stream IDs) is serialized appropriately. It tests the case for no
3855// stream ids and multiple stream ids.
3856TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3857 // Only create a=msid lines for strictly Unified Plan stream ID support.
3858 MakeUnifiedPlanDescriptionMultipleStreamIds(
3859 cricket::kMsidSignalingMediaSection);
3860
Seth Hampson5b4f0752018-04-02 16:31:36 -07003861 TestSerialize(jdesc_);
3862}
3863
Seth Hampson5897a6e2018-04-03 11:16:33 -07003864// This tests that a Unified Plan SDP with no a=ssrc lines is
3865// serialized/deserialized appropriately. In this case the
3866// MediaContentDescription will contain a StreamParams object that doesn't have
3867// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3868// SSRC lines.
3869TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3870 MakeUnifiedPlanDescription();
3871 RemoveSsrcSignalingFromStreamParams();
3872 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3873 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3874
3875 JsepSessionDescription deserialized_description(kDummyType);
3876 EXPECT_TRUE(
3877 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3878 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3879}
3880
3881TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3882 MakeUnifiedPlanDescription();
3883 RemoveSsrcSignalingFromStreamParams();
3884
3885 TestSerialize(jdesc_);
3886}
3887
Steve Antone831b8c2018-02-01 12:22:16 -08003888TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3889 JsepSessionDescription jsep_desc(kDummyType);
3890 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3891 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3892}
3893
3894TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3895 JsepSessionDescription jsep_desc(kDummyType);
3896 std::string sdp = kSdpSessionString;
3897 sdp += kSdpSctpDataChannelString;
3898 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3899 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3900}
3901
3902TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3903 JsepSessionDescription jsep_desc(kDummyType);
3904 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3905 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3906 jsep_desc.description()->msid_signaling());
3907}
3908
3909TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3910 JsepSessionDescription jsep_desc(kDummyType);
3911 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3912 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3913 jsep_desc.description()->msid_signaling());
3914}
3915
3916const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3917const char kSsrcAttributeMsidLine[] =
3918 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3919
3920TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3921 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3922 std::string sdp = webrtc::SdpSerialize(jdesc_);
3923
3924 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3925 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3926}
3927
3928TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3929 jdesc_.description()->set_msid_signaling(
3930 cricket::kMsidSignalingSsrcAttribute);
3931 std::string sdp = webrtc::SdpSerialize(jdesc_);
3932
3933 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3934 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3935}
3936
3937TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3938 jdesc_.description()->set_msid_signaling(
3939 cricket::kMsidSignalingMediaSection |
3940 cricket::kMsidSignalingSsrcAttribute);
3941 std::string sdp = webrtc::SdpSerialize(jdesc_);
3942
3943 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3944 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003945}
deadbeef7e146cb2016-09-28 10:04:34 -07003946
3947// Regression test for heap overflow bug:
3948// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3949TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003950 // The issue occurs when the sctp-port attribute is found in a video
3951 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003952 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003953 "v=0\r\n"
3954 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3955 "s=-\r\n"
3956 "t=0 0\r\n"
3957 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3958 "a=sctp-port 5000\r\n"
3959 "a=fmtp:108 foo=10\r\n";
3960
3961 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3962 "sctp-port");
3963}
deadbeefb2362572016-12-13 16:37:06 -08003964
3965// Regression test for integer overflow bug:
3966// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3967TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003968 // Bandwidth attribute is the max signed 32-bit int, which will get
3969 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003970 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003971 "v=0\r\n"
3972 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3973 "s=-\r\n"
3974 "t=0 0\r\n"
3975 "m=video 3457 RTP/SAVPF 120\r\n"
3976 "b=AS:2147483647\r\n"
3977 "foo=fail\r\n";
3978
3979 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3980}
deadbeef7bcdb692017-01-20 12:43:58 -08003981
deadbeefbc88c6b2017-08-02 11:26:34 -07003982// Similar to the above, except that negative values are illegal, not just
3983// error-prone as large values are.
3984// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3985TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3986 static const char kSdpWithNegativeBandwidth[] =
3987 "v=0\r\n"
3988 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3989 "s=-\r\n"
3990 "t=0 0\r\n"
3991 "m=video 3457 RTP/SAVPF 120\r\n"
3992 "b=AS:-1000\r\n";
3993
3994 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3995}
3996
deadbeef3e8016e2017-08-03 17:49:30 -07003997// An exception to the above rule: a value of -1 for b=AS should just be
3998// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3999// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4000// limit", but this is now what ommitting the attribute entirely will do, so
4001// ignoring it will have the intended effect.
4002TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4003 static const char kSdpWithBandwidthOfNegativeOne[] =
4004 "v=0\r\n"
4005 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4006 "s=-\r\n"
4007 "t=0 0\r\n"
4008 "m=video 3457 RTP/SAVPF 120\r\n"
4009 "b=AS:-1\r\n";
4010
Steve Antona3a92c22017-12-07 10:27:41 -08004011 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07004012 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07004013 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08004014 GetFirstVideoContentDescription(jdesc_output.description());
4015 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07004016 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4017}
4018
deadbeef7bcdb692017-01-20 12:43:58 -08004019// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4020// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4021// Regression test for:
4022// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4023TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4024 // Important piece is "ufrag foo pwd bar".
4025 static const char kSdpWithIceCredentialsInCandidateString[] =
4026 "v=0\r\n"
4027 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4028 "s=-\r\n"
4029 "t=0 0\r\n"
4030 "m=audio 9 RTP/SAVPF 111\r\n"
4031 "c=IN IP4 0.0.0.0\r\n"
4032 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4033 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4034 "a=rtpmap:111 opus/48000/2\r\n"
4035 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4036 "generation 2 ufrag foo pwd bar\r\n";
4037
Steve Antona3a92c22017-12-07 10:27:41 -08004038 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08004039 EXPECT_TRUE(
4040 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4041 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4042 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02004043 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08004044 cricket::Candidate c = candidates->at(0)->candidate();
4045 EXPECT_EQ("ufrag_voice", c.username());
4046 EXPECT_EQ("pwd_voice", c.password());
4047}
deadbeef90f1e1e2017-02-10 12:35:05 -08004048
Johannes Kron211856b2018-09-06 12:12:28 +02004049// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4050// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4051// Regression test for:
4052// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4053TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4054 static const char kSdpWithFooIceCredentials[] =
4055 "v=0\r\n"
4056 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4057 "s=-\r\n"
4058 "t=0 0\r\n"
4059 "m=audio 9 RTP/SAVPF 111\r\n"
4060 "c=IN IP4 0.0.0.0\r\n"
4061 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4062 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4063 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4064 "a=rtpmap:111 opus/48000/2\r\n"
4065 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4066 "generation 2\r\n";
4067
4068 JsepSessionDescription jdesc_output(kDummyType);
4069 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4070 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4071 ASSERT_NE(nullptr, candidates);
4072 ASSERT_EQ(1U, candidates->count());
4073 cricket::Candidate c = candidates->at(0)->candidate();
4074 EXPECT_EQ("ufrag_voice", c.username());
4075 EXPECT_EQ("pwd_voice", c.password());
4076}
4077
deadbeef90f1e1e2017-02-10 12:35:05 -08004078// Test that SDP with an invalid port number in "a=candidate" lines is
4079// rejected, without crashing.
4080// Regression test for:
4081// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4082TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4083 static const char kSdpWithInvalidCandidatePort[] =
4084 "v=0\r\n"
4085 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4086 "s=-\r\n"
4087 "t=0 0\r\n"
4088 "m=audio 9 RTP/SAVPF 111\r\n"
4089 "c=IN IP4 0.0.0.0\r\n"
4090 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4091 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4092 "a=rtpmap:111 opus/48000/2\r\n"
4093 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4094 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4095
Steve Antona3a92c22017-12-07 10:27:41 -08004096 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08004097 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4098}
deadbeefa4549d62017-02-10 17:26:22 -08004099
4100// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4101// Regression test for:
4102// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4103TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4104 static const char kSdpWithMissingTrackId[] =
4105 "v=0\r\n"
4106 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4107 "s=-\r\n"
4108 "t=0 0\r\n"
4109 "m=audio 9 RTP/SAVPF 111\r\n"
4110 "c=IN IP4 0.0.0.0\r\n"
4111 "a=rtpmap:111 opus/48000/2\r\n"
4112 "a=msid:stream_id \r\n";
4113
Steve Antona3a92c22017-12-07 10:27:41 -08004114 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004115 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4116}
4117
4118TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4119 static const char kSdpWithMissingStreamId[] =
4120 "v=0\r\n"
4121 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4122 "s=-\r\n"
4123 "t=0 0\r\n"
4124 "m=audio 9 RTP/SAVPF 111\r\n"
4125 "c=IN IP4 0.0.0.0\r\n"
4126 "a=rtpmap:111 opus/48000/2\r\n"
4127 "a=msid: track_id\r\n";
4128
Steve Antona3a92c22017-12-07 10:27:41 -08004129 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08004130 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4131}
zhihuang38989e52017-03-21 11:04:53 -07004132
4133// Tests that if both session-level address and media-level address exist, use
4134// the media-level address.
4135TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08004136 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004137
4138 // Sesssion-level address.
4139 std::string sdp = kSdpFullString;
4140 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4141 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4142
4143 const auto& content1 = jsep_desc.description()->contents()[0];
4144 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08004145 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004146 const auto& content2 = jsep_desc.description()->contents()[1];
4147 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08004148 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004149}
4150
4151// Tests that the session-level connection address will be used if the media
4152// level-addresses are not specified.
4153TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08004154 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004155
4156 // Sesssion-level address.
4157 std::string sdp = kSdpString;
4158 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4159 // Remove the media level addresses.
4160 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4161 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4162 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4163
4164 const auto& content1 = jsep_desc.description()->contents()[0];
4165 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004166 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004167 const auto& content2 = jsep_desc.description()->contents()[1];
4168 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004169 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004170}
4171
4172TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08004173 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004174
4175 std::string sdp = kSdpString;
4176 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4177 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4178 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4179 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4180 &sdp);
4181 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4182 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4183 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4184 &sdp);
4185 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4186 const auto& content1 = jsep_desc.description()->contents()[0];
4187 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004188 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004189 const auto& content2 = jsep_desc.description()->contents()[1];
4190 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08004191 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07004192}
4193
Qingsi Wang56991422019-02-08 12:53:06 -08004194// Test that a c= line that contains a hostname connection address can be
4195// parsed.
4196TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4197 JsepSessionDescription jsep_desc(kDummyType);
4198 std::string sdp = kSdpString;
4199 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4200
4201 sdp = kSdpString;
4202 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4203 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4204 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4205
4206 ASSERT_NE(nullptr, jsep_desc.description());
4207 const auto& content1 = jsep_desc.description()->contents()[0];
4208 EXPECT_EQ("example.local:9",
4209 content1.media_description()->connection_address().ToString());
4210 const auto& content2 = jsep_desc.description()->contents()[1];
4211 EXPECT_EQ("example.local:9",
4212 content2.media_description()->connection_address().ToString());
4213}
4214
4215// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 11:04:53 -07004216TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08004217 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004218 std::string sdp = kSdpString;
4219 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4220
4221 // Unsupported multicast IPv4 address.
4222 sdp = kSdpFullString;
4223 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4224 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4225
4226 // Unsupported multicast IPv6 address.
4227 sdp = kSdpFullString;
4228 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4229 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4230
4231 // Mismatched address type.
4232 sdp = kSdpFullString;
4233 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4234 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4235
4236 sdp = kSdpFullString;
4237 Replace("c=IN IP4 74.125.224.39\r\n",
4238 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4239 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4240}
4241
4242TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004243 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004244 MakeDescriptionWithoutCandidates(&expected_jsep);
4245 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004246 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004247 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004248 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004249 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004250 auto audio_desc = jdesc.description()
4251 ->GetContentByName(kAudioContentName)
4252 ->media_description();
4253 auto video_desc = jdesc.description()
4254 ->GetContentByName(kVideoContentName)
4255 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004256 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4257 audio_desc->connection_address().ToString());
4258 EXPECT_EQ(video_desc_->connection_address().ToString(),
4259 video_desc->connection_address().ToString());
4260}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004261
Qingsi Wang56991422019-02-08 12:53:06 -08004262// Test that a media description that contains a hostname connection address can
4263// be correctly serialized.
4264TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithHostnameConnectionAddress) {
4265 JsepSessionDescription expected_jsep(kDummyType);
4266 cricket::Candidate c;
4267 const rtc::SocketAddress hostname_addr("example.local", 1234);
4268 audio_desc_->set_connection_address(hostname_addr);
4269 video_desc_->set_connection_address(hostname_addr);
4270 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004271 expected_jsep.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Qingsi Wang56991422019-02-08 12:53:06 -08004272 // Serialization.
4273 std::string message = webrtc::SdpSerialize(expected_jsep);
4274 // Deserialization.
4275 JsepSessionDescription jdesc(kDummyType);
4276 ASSERT_TRUE(SdpDeserialize(message, &jdesc));
4277 auto audio_desc = jdesc.description()
4278 ->GetContentByName(kAudioContentName)
4279 ->media_description();
4280 auto video_desc = jdesc.description()
4281 ->GetContentByName(kVideoContentName)
4282 ->media_description();
4283 EXPECT_EQ(hostname_addr, audio_desc->connection_address());
4284 EXPECT_EQ(hostname_addr, video_desc->connection_address());
4285}
4286
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004287// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4288// used (i.e., a single space as the session name)." So we should accept that.
4289TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4290 JsepSessionDescription jsep_desc(kDummyType);
4291 std::string sdp = kSdpString;
4292 Replace("s=-\r\n", "s= \r\n", &sdp);
4293 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4294}
Amit Hilbucha2012042018-12-03 11:35:05 -08004295
4296// Simulcast malformed input test for invalid format.
4297TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4298 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4299 "a=simulcast:\r\n", "a=simulcast:");
4300}
4301
4302// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4303TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4304 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4305 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4306 "a=simulcast:");
4307}
4308
4309// Validates that deserialization uses the a=simulcast: attribute
4310TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004311 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4312 sdp += "a=rid:1 send\r\n";
4313 sdp += "a=rid:2 send\r\n";
4314 sdp += "a=rid:3 send\r\n";
4315 sdp += "a=rid:4 recv\r\n";
4316 sdp += "a=rid:5 recv\r\n";
4317 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004318 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4319 JsepSessionDescription output(kDummyType);
4320 SdpParseError error;
4321 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4322 const cricket::ContentInfos& contents = output.description()->contents();
4323 const cricket::MediaContentDescription* media =
4324 contents.back().media_description();
4325 EXPECT_TRUE(media->HasSimulcast());
4326 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4327 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004328 EXPECT_FALSE(media->streams().empty());
4329 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4330 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004331}
4332
4333// Validates that deserialization removes rids that do not appear in SDP
4334TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4335 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4336 sdp += "a=rid:1 send\r\n";
4337 sdp += "a=rid:3 send\r\n";
4338 sdp += "a=rid:4 recv\r\n";
4339 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4340 JsepSessionDescription output(kDummyType);
4341 SdpParseError error;
4342 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4343 const cricket::ContentInfos& contents = output.description()->contents();
4344 const cricket::MediaContentDescription* media =
4345 contents.back().media_description();
4346 EXPECT_TRUE(media->HasSimulcast());
4347 const SimulcastDescription& simulcast = media->simulcast_description();
4348 EXPECT_EQ(2ul, simulcast.send_layers().size());
4349 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4350
4351 std::vector<SimulcastLayer> all_send_layers =
4352 simulcast.send_layers().GetAllLayers();
4353 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-28 17:25:26 -08004354 EXPECT_EQ(0,
4355 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4356 return layer.rid == "2";
4357 }));
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004358
4359 std::vector<SimulcastLayer> all_receive_layers =
4360 simulcast.receive_layers().GetAllLayers();
4361 ASSERT_EQ(1ul, all_receive_layers.size());
4362 EXPECT_EQ("4", all_receive_layers[0].rid);
4363
4364 EXPECT_FALSE(media->streams().empty());
4365 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4366 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004367}
4368
4369// Validates that Simulcast removes rids that appear in both send and receive.
4370TEST_F(WebRtcSdpTest,
4371 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4372 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4373 sdp += "a=rid:1 send\r\n";
4374 sdp += "a=rid:2 send\r\n";
4375 sdp += "a=rid:3 send\r\n";
4376 sdp += "a=rid:4 recv\r\n";
4377 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4378 JsepSessionDescription output(kDummyType);
4379 SdpParseError error;
4380 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4381 const cricket::ContentInfos& contents = output.description()->contents();
4382 const cricket::MediaContentDescription* media =
4383 contents.back().media_description();
4384 EXPECT_TRUE(media->HasSimulcast());
4385 const SimulcastDescription& simulcast = media->simulcast_description();
4386 EXPECT_EQ(2ul, simulcast.send_layers().size());
4387 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4388 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4389 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4390
4391 EXPECT_FALSE(media->streams().empty());
4392 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4393 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004394}
4395
4396// Ignores empty rid line.
4397TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4398 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4399 sdp += "a=rid:1 send\r\n";
4400 sdp += "a=rid:2 send\r\n";
4401 sdp += "a=rid\r\n"; // Should ignore this line.
4402 sdp += "a=rid:\r\n"; // Should ignore this line.
4403 sdp += "a=simulcast:send 1;2\r\n";
4404 JsepSessionDescription output(kDummyType);
4405 SdpParseError error;
4406 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4407 const cricket::ContentInfos& contents = output.description()->contents();
4408 const cricket::MediaContentDescription* media =
4409 contents.back().media_description();
4410 EXPECT_TRUE(media->HasSimulcast());
4411 const SimulcastDescription& simulcast = media->simulcast_description();
4412 EXPECT_TRUE(simulcast.receive_layers().empty());
4413 EXPECT_EQ(2ul, simulcast.send_layers().size());
4414 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4415
4416 EXPECT_FALSE(media->streams().empty());
4417 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4418 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004419}
4420
4421// Ignores malformed rid lines.
4422TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4423 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4424 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4425 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4426 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4427 sdp += "a=rid:4\r\n"; // Should ignore this line.
4428 sdp += "a=rid:5 send\r\n";
4429 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4430 JsepSessionDescription output(kDummyType);
4431 SdpParseError error;
4432 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4433 const cricket::ContentInfos& contents = output.description()->contents();
4434 const cricket::MediaContentDescription* media =
4435 contents.back().media_description();
4436 EXPECT_TRUE(media->HasSimulcast());
4437 const SimulcastDescription& simulcast = media->simulcast_description();
4438 EXPECT_TRUE(simulcast.receive_layers().empty());
4439 EXPECT_EQ(1ul, simulcast.send_layers().size());
4440 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4441
4442 EXPECT_FALSE(media->streams().empty());
4443 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4444 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004445}
4446
4447// Removes RIDs that specify a different format than the m= section.
4448TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4449 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4450 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4451 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4452 sdp += "a=simulcast:send 1;2\r\n";
4453 JsepSessionDescription output(kDummyType);
4454 SdpParseError error;
4455 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4456 const cricket::ContentInfos& contents = output.description()->contents();
4457 const cricket::MediaContentDescription* media =
4458 contents.back().media_description();
4459 EXPECT_TRUE(media->HasSimulcast());
4460 const SimulcastDescription& simulcast = media->simulcast_description();
4461 EXPECT_TRUE(simulcast.receive_layers().empty());
4462 EXPECT_EQ(1ul, simulcast.send_layers().size());
4463 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4464 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4465 EXPECT_EQ(1ul, media->streams().size());
4466 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4467 EXPECT_EQ(1ul, rids.size());
4468 EXPECT_EQ("1", rids[0].rid);
4469 EXPECT_EQ(1ul, rids[0].payload_types.size());
4470 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004471}
4472
4473// Ignores duplicate rid lines
4474TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4475 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4476 sdp += "a=rid:1 send\r\n";
4477 sdp += "a=rid:2 send\r\n";
4478 sdp += "a=rid:2 send\r\n";
4479 sdp += "a=rid:3 send\r\n";
4480 sdp += "a=rid:4 recv\r\n";
4481 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4482 JsepSessionDescription output(kDummyType);
4483 SdpParseError error;
4484 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4485 const cricket::ContentInfos& contents = output.description()->contents();
4486 const cricket::MediaContentDescription* media =
4487 contents.back().media_description();
4488 EXPECT_TRUE(media->HasSimulcast());
4489 const SimulcastDescription& simulcast = media->simulcast_description();
4490 EXPECT_EQ(2ul, simulcast.send_layers().size());
4491 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4492 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4493 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4494
4495 EXPECT_FALSE(media->streams().empty());
4496 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4497 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004498}
4499
Florent Castellic4421972019-07-02 20:27:42 +02004500TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4501 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4502 sdp += "a=rid:1 recv\r\n";
4503 sdp += "a=rid:2 recv\r\n";
4504 sdp += "a=simulcast:send 1;2\r\n";
4505 JsepSessionDescription output(kDummyType);
4506 SdpParseError error;
4507 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4508 const cricket::ContentInfos& contents = output.description()->contents();
4509 const cricket::MediaContentDescription* media =
4510 contents.back().media_description();
4511 EXPECT_FALSE(media->HasSimulcast());
4512}
4513
4514TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4515 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4516 sdp += "a=rid:1 send\r\n";
4517 sdp += "a=rid:2 send\r\n";
4518 sdp += "a=simulcast:recv 1;2\r\n";
4519 JsepSessionDescription output(kDummyType);
4520 SdpParseError error;
4521 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4522 const cricket::ContentInfos& contents = output.description()->contents();
4523 const cricket::MediaContentDescription* media =
4524 contents.back().media_description();
4525 EXPECT_FALSE(media->HasSimulcast());
4526}
4527
4528TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4529 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4530 sdp += "a=rid:1 send\r\n";
4531 sdp += "a=rid:2 send\r\n";
4532 sdp += "a=rid:3 send\r\n";
4533 sdp += "a=rid:4 recv\r\n";
4534 sdp += "a=rid:5 recv\r\n";
4535 sdp += "a=rid:6 recv\r\n";
4536 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4537 JsepSessionDescription output(kDummyType);
4538 SdpParseError error;
4539 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4540 const cricket::ContentInfos& contents = output.description()->contents();
4541 const cricket::MediaContentDescription* media =
4542 contents.back().media_description();
4543 EXPECT_TRUE(media->HasSimulcast());
4544 const SimulcastDescription& simulcast = media->simulcast_description();
4545 EXPECT_EQ(2ul, simulcast.send_layers().size());
4546 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4547 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4548 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4549
4550 EXPECT_FALSE(media->streams().empty());
4551 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4552 CompareRidDescriptionIds(rids, {"1", "3"});
4553}
4554
Amit Hilbucha2012042018-12-03 11:35:05 -08004555// Simulcast serialization integration test.
4556// This test will serialize and deserialize the description and compare.
4557// More detailed tests for parsing simulcast can be found in
4558// unit tests for SdpSerializer.
4559TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004560 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004561 auto description = jdesc_.description();
4562 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004563 ASSERT_EQ(media->streams().size(), 1ul);
4564 StreamParams& send_stream = media->mutable_streams()[0];
4565 std::vector<RidDescription> send_rids;
4566 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4567 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4568 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4569 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4570 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 12:47:54 +02004571 std::vector<RidDescription> receive_rids;
4572 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4573 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4574 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4575 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004576
Amit Hilbucha2012042018-12-03 11:35:05 -08004577 SimulcastDescription& simulcast = media->simulcast_description();
4578 simulcast.send_layers().AddLayerWithAlternatives(
4579 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4580 simulcast.send_layers().AddLayerWithAlternatives(
4581 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 12:47:54 +02004582 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4583 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4584 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 11:35:05 -08004585
Amit Hilbucha2012042018-12-03 11:35:05 -08004586 TestSerialize(jdesc_);
4587}
Steve Anton06817cd2018-12-18 15:55:30 -08004588
4589// Test that the content name is empty if the media section does not have an
4590// a=mid line.
4591TEST_F(WebRtcSdpTest, ParseNoMid) {
4592 std::string sdp = kSdpString;
4593 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4594 Replace("a=mid:video_content_name\r\n", "", &sdp);
4595
4596 JsepSessionDescription output(kDummyType);
4597 SdpParseError error;
4598 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4599
4600 EXPECT_THAT(output.description()->contents(),
4601 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4602 Field("name", &cricket::ContentInfo::name, "")));
4603}
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -08004604
4605// Test that the media transport name and base64-decoded setting is parsed from
4606// an a=x-mt line.
4607TEST_F(WebRtcSdpTest, ParseMediaTransport) {
4608 JsepSessionDescription output(kDummyType);
4609 std::string sdp = kSdpSessionString;
4610 sdp += "a=x-mt:rtp:dGVzdDY0\r\n";
4611 SdpParseError error;
4612
4613 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4614 << error.description;
4615 const auto& settings = output.description()->MediaTransportSettings();
4616 ASSERT_EQ(1u, settings.size());
4617 EXPECT_EQ("rtp", settings[0].transport_name);
4618 EXPECT_EQ("test64", settings[0].transport_setting);
4619}
4620
4621// Test that an a=x-mt line fails to parse if its setting is invalid base 64.
4622TEST_F(WebRtcSdpTest, ParseMediaTransportInvalidBase64) {
4623 JsepSessionDescription output(kDummyType);
4624 std::string sdp = kSdpSessionString;
4625 sdp += "a=x-mt:rtp:ThisIsInvalidBase64\r\n";
4626 SdpParseError error;
4627
4628 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4629}
4630
4631// Test that multiple a=x-mt lines are parsed in the order of preference (the
4632// order of the lines in the SDP).
4633TEST_F(WebRtcSdpTest, ParseMediaTransportMultipleLines) {
4634 JsepSessionDescription output(kDummyType);
4635 std::string sdp = kSdpSessionString;
4636 sdp +=
4637 "a=x-mt:rtp:dGVzdDY0\r\n"
4638 "a=x-mt:generic:Z2VuZXJpY3NldHRpbmc=\r\n";
4639 SdpParseError error;
4640
4641 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4642 << error.description;
4643 const auto& settings = output.description()->MediaTransportSettings();
4644 ASSERT_EQ(2u, settings.size());
4645 EXPECT_EQ("rtp", settings[0].transport_name);
4646 EXPECT_EQ("test64", settings[0].transport_setting);
4647 EXPECT_EQ("generic", settings[1].transport_name);
4648 EXPECT_EQ("genericsetting", settings[1].transport_setting);
4649}
4650
4651// Test that only the first a=x-mt line associated with a transport name is
4652// parsed and the rest ignored.
4653TEST_F(WebRtcSdpTest, ParseMediaTransportSkipRepeatedTransport) {
4654 JsepSessionDescription output(kDummyType);
4655 std::string sdp = kSdpSessionString;
4656 sdp +=
4657 "a=x-mt:rtp:dGVzdDY0\r\n"
4658 "a=x-mt:rtp:Z2VuZXJpY3NldHRpbmc=\r\n";
4659 SdpParseError error;
4660
4661 // Repeated 'rtp' transport setting. We still parse the SDP successfully,
4662 // but ignore the repeated transport.
4663 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4664 const auto& settings = output.description()->MediaTransportSettings();
4665 EXPECT_EQ("test64", settings[0].transport_setting);
4666}
4667
4668// Test that an a=x-mt line fails to parse if it is missing a setting.
4669TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine) {
4670 JsepSessionDescription output(kDummyType);
4671 std::string sdp = kSdpSessionString;
4672 sdp += "a=x-mt:rtp\r\n";
4673 SdpParseError error;
4674
4675 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4676}
4677
4678// Test that an a=x-mt line fails to parse if its missing a name and setting.
4679TEST_F(WebRtcSdpTest, ParseMediaTransportMalformedLine2) {
4680 JsepSessionDescription output(kDummyType);
4681 std::string sdp = kSdpSessionString;
4682 sdp += "a=x-mt\r\n";
4683 SdpParseError error;
4684
4685 ASSERT_FALSE(webrtc::SdpDeserialize(sdp, &output, &error));
4686}
4687
4688TEST_F(WebRtcSdpTest, ParseMediaTransportIgnoreNonsenseAttributeLines) {
4689 JsepSessionDescription output(kDummyType);
4690 std::string sdp = kSdpSessionString;
4691 sdp += "a=x-nonsense:rtp:dGVzdDY0\r\n";
4692 SdpParseError error;
4693
4694 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error))
4695 << error.description;
4696 EXPECT_TRUE(output.description()->MediaTransportSettings().empty());
4697}
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004698
4699TEST_F(WebRtcSdpTest, SerializeMediaTransportSettings) {
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004700 auto description = absl::make_unique<cricket::SessionDescription>();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004701
4702 JsepSessionDescription output(SdpType::kOffer);
4703 // JsepSessionDescription takes ownership of the description.
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004704 output.Initialize(std::move(description), "session_id", "session_version");
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004705 output.description()->AddMediaTransportSetting("foo", "bar");
4706 std::string serialized_out;
4707 output.ToString(&serialized_out);
4708 ASSERT_THAT(serialized_out, ::testing::HasSubstr("\r\na=x-mt:foo:YmFy\r\n"));
4709}
4710
4711TEST_F(WebRtcSdpTest, SerializeMediaTransportSettingsTestCopy) {
4712 cricket::SessionDescription description;
4713 description.AddMediaTransportSetting("name", "setting");
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02004714 std::unique_ptr<cricket::SessionDescription> copy = description.Clone();
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -08004715 ASSERT_EQ(1u, copy->MediaTransportSettings().size());
4716 EXPECT_EQ("name", copy->MediaTransportSettings()[0].transport_name);
4717 EXPECT_EQ("setting", copy->MediaTransportSettings()[0].transport_setting);
4718}
Guido Urdanetacecf87f2019-05-31 10:17:38 +00004719
4720TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4721 AddSctpDataChannel(false); // Don't use sctpmap
4722 JsepSessionDescription jsep_desc(kDummyType);
4723 MakeDescriptionWithoutCandidates(&jsep_desc);
4724 std::string message = webrtc::SdpSerialize(jsep_desc);
4725 EXPECT_NE(std::string::npos,
4726 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4727}
4728
4729TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4730 AddSctpDataChannel(false);
4731 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4732 cricket::kMediaProtocolUdpDtlsSctp,
4733 cricket::kMediaProtocolTcpDtlsSctp};
4734 for (const auto& protocol : protocols) {
4735 sctp_desc_->set_protocol(protocol);
4736 JsepSessionDescription jsep_desc(kDummyType);
4737 MakeDescriptionWithoutCandidates(&jsep_desc);
4738 std::string message = webrtc::SdpSerialize(jsep_desc);
4739 EXPECT_NE(std::string::npos, message.find(protocol));
4740 JsepSessionDescription jsep_output(kDummyType);
4741 SdpParseError error;
4742 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4743 }
4744}