blob: 59897af0404fc5f0f8d9fa4af347e807833e8617 [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
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "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 +020093static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kExtmapId = 1;
95static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
96static const char kExtmap[] =
97 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
98static const char kExtmapWithDirectionAndAttribute[] =
99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700100static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Boström0c4e06b2015-10-07 12:23:21 +0200104static const uint8_t kIdentityDigest[] = {
105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
lally@webrtc.org34807282015-02-24 20:19:39 +0000108static const char kDtlsSctp[] = "DTLS/SCTP";
109static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
110static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112struct CodecParams {
113 int max_ptime;
114 int ptime;
115 int min_ptime;
116 int sprop_stereo;
117 int stereo;
118 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000119 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
deadbeef9d3584c2016-02-16 17:54:10 -0800122// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
123// instead of "a=crypto", and have an explicit test for adding "a=crypto".
124// Currently it's the other way around.
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Reference sdp string
127static const char kSdpFullString[] =
128 "v=0\r\n"
129 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800132 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
134 "c=IN IP4 74.125.127.126\r\n"
135 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
136 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
145 "raddr 192.168.1.5 rport 2346 "
146 "generation 2\r\n"
147 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
148 "raddr 192.168.1.5 rport 2348 "
149 "generation 2\r\n"
150 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
151 "a=mid:audio_content_name\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800154 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 "m=video 3457 RTP/SAVPF 120\r\n"
166 "c=IN IP4 74.125.224.39\r\n"
167 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
168 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
177 "generation 2\r\n"
178 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
179 "generation 2\r\n"
180 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
181 "a=mid:video_content_name\r\n"
182 "a=sendrecv\r\n"
183 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
184 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
185 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:2 cname:stream_1_cname\r\n"
188 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
189 "a=ssrc:2 mslabel:local_stream_1\r\n"
190 "a=ssrc:2 label:video_track_id_1\r\n"
191 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800194 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196// SDP reference string without the candidates.
197static const char kSdpString[] =
198 "v=0\r\n"
199 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800202 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000203 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000204 "c=IN IP4 0.0.0.0\r\n"
205 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
207 "a=mid:audio_content_name\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800210 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
212 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
213 "dummy_session_params\r\n"
214 "a=rtpmap:111 opus/48000/2\r\n"
215 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000216 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 "a=ssrc:1 cname:stream_1_cname\r\n"
218 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
219 "a=ssrc:1 mslabel:local_stream_1\r\n"
220 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000221 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000222 "c=IN IP4 0.0.0.0\r\n"
223 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
225 "a=mid:video_content_name\r\n"
226 "a=sendrecv\r\n"
227 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
229 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:2 cname:stream_1_cname\r\n"
232 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
233 "a=ssrc:2 mslabel:local_stream_1\r\n"
234 "a=ssrc:2 label:video_track_id_1\r\n"
235 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800238 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000241 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000242 "c=IN IP4 0.0.0.0\r\n"
243 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 "a=ice-ufrag:ufrag_data\r\n"
245 "a=ice-pwd:pwd_data\r\n"
246 "a=mid:data_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
250 "a=rtpmap:101 google-data/90000\r\n"
251 "a=ssrc:10 cname:data_channel_cname\r\n"
252 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
253 "a=ssrc:10 mslabel:data_channel\r\n"
254 "a=ssrc:10 label:data_channeld0\r\n";
255
256static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000257 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000258 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 "a=ice-ufrag:ufrag_data\r\n"
260 "a=ice-pwd:pwd_data\r\n"
261 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000264// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000265static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000266 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
267 "a=max-message-size=100000\r\n"
268 "a=sctp-port 5000\r\n"
269 "c=IN IP4 0.0.0.0\r\n"
270 "a=ice-ufrag:ufrag_data\r\n"
271 "a=ice-pwd:pwd_data\r\n"
272 "a=mid:data_content_name\r\n";
273
lally69f57602015-10-08 10:15:04 -0700274static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
275 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
276 "a=max-message-size=100000\r\n"
277 "a=sctp-port:5000\r\n"
278 "c=IN IP4 0.0.0.0\r\n"
279 "a=ice-ufrag:ufrag_data\r\n"
280 "a=ice-pwd:pwd_data\r\n"
281 "a=mid:data_content_name\r\n";
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283static const char kSdpSctpDataChannelWithCandidatesString[] =
284 "m=application 2345 DTLS/SCTP 5000\r\n"
285 "c=IN IP4 74.125.127.126\r\n"
286 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
289 "generation 2\r\n"
290 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
291 "raddr 192.168.1.5 rport 2346 "
292 "generation 2\r\n"
293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000298static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "v=0\r\n"
300 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
303 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000309 "a=x-google-flag:conference\r\n";
310
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000311static const char kSdpSessionString[] =
312 "v=0\r\n"
313 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
314 "s=-\r\n"
315 "t=0 0\r\n"
316 "a=msid-semantic: WMS local_stream\r\n";
317
318static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000319 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000320 "c=IN IP4 0.0.0.0\r\n"
321 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000322 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
323 "a=mid:audio_content_name\r\n"
324 "a=sendrecv\r\n"
325 "a=rtpmap:111 opus/48000/2\r\n"
326 "a=ssrc:1 cname:stream_1_cname\r\n"
327 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
328 "a=ssrc:1 mslabel:local_stream\r\n"
329 "a=ssrc:1 label:audio_track_id_1\r\n";
330
331static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000332 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000333 "c=IN IP4 0.0.0.0\r\n"
334 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000335 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
336 "a=mid:video_content_name\r\n"
337 "a=sendrecv\r\n"
338 "a=rtpmap:120 VP8/90000\r\n"
339 "a=ssrc:2 cname:stream_1_cname\r\n"
340 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
341 "a=ssrc:2 mslabel:local_stream\r\n"
342 "a=ssrc:2 label:video_track_id_1\r\n";
343
deadbeef25ed4352016-12-12 18:37:36 -0800344// Reference sdp string using bundle-only.
345static const char kBundleOnlySdpFullString[] =
346 "v=0\r\n"
347 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
348 "s=-\r\n"
349 "t=0 0\r\n"
350 "a=group:BUNDLE audio_content_name video_content_name\r\n"
351 "a=msid-semantic: WMS local_stream_1\r\n"
352 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
353 "c=IN IP4 74.125.127.126\r\n"
354 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
355 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
364 "raddr 192.168.1.5 rport 2346 "
365 "generation 2\r\n"
366 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
367 "raddr 192.168.1.5 rport 2348 "
368 "generation 2\r\n"
369 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
370 "a=mid:audio_content_name\r\n"
371 "a=sendrecv\r\n"
372 "a=rtcp-mux\r\n"
373 "a=rtcp-rsize\r\n"
374 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
375 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
376 "dummy_session_params\r\n"
377 "a=rtpmap:111 opus/48000/2\r\n"
378 "a=rtpmap:103 ISAC/16000\r\n"
379 "a=rtpmap:104 ISAC/32000\r\n"
380 "a=ssrc:1 cname:stream_1_cname\r\n"
381 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
382 "a=ssrc:1 mslabel:local_stream_1\r\n"
383 "a=ssrc:1 label:audio_track_id_1\r\n"
384 "m=video 0 RTP/SAVPF 120\r\n"
385 "c=IN IP4 0.0.0.0\r\n"
386 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
387 "a=bundle-only\r\n"
388 "a=mid:video_content_name\r\n"
389 "a=sendrecv\r\n"
390 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
391 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
392 "a=rtpmap:120 VP8/90000\r\n"
393 "a=ssrc-group:FEC 2 3\r\n"
394 "a=ssrc:2 cname:stream_1_cname\r\n"
395 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
396 "a=ssrc:2 mslabel:local_stream_1\r\n"
397 "a=ssrc:2 label:video_track_id_1\r\n"
398 "a=ssrc:3 cname:stream_1_cname\r\n"
399 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:3 mslabel:local_stream_1\r\n"
401 "a=ssrc:3 label:video_track_id_1\r\n";
402
deadbeef9d3584c2016-02-16 17:54:10 -0800403// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
404// tracks.
405static const char kPlanBSdpFullString[] =
406 "v=0\r\n"
407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
408 "s=-\r\n"
409 "t=0 0\r\n"
410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
411 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
412 "c=IN IP4 74.125.127.126\r\n"
413 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
414 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
423 "raddr 192.168.1.5 rport 2346 "
424 "generation 2\r\n"
425 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
426 "raddr 192.168.1.5 rport 2348 "
427 "generation 2\r\n"
428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
429 "a=mid:audio_content_name\r\n"
430 "a=sendrecv\r\n"
431 "a=rtcp-mux\r\n"
432 "a=rtcp-rsize\r\n"
433 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n"
436 "a=rtpmap:111 opus/48000/2\r\n"
437 "a=rtpmap:103 ISAC/16000\r\n"
438 "a=rtpmap:104 ISAC/32000\r\n"
439 "a=ssrc:1 cname:stream_1_cname\r\n"
440 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
441 "a=ssrc:1 mslabel:local_stream_1\r\n"
442 "a=ssrc:1 label:audio_track_id_1\r\n"
443 "a=ssrc:4 cname:stream_2_cname\r\n"
444 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
445 "a=ssrc:4 mslabel:local_stream_2\r\n"
446 "a=ssrc:4 label:audio_track_id_2\r\n"
447 "m=video 3457 RTP/SAVPF 120\r\n"
448 "c=IN IP4 74.125.224.39\r\n"
449 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
450 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
459 "generation 2\r\n"
460 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
461 "generation 2\r\n"
462 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
463 "a=mid:video_content_name\r\n"
464 "a=sendrecv\r\n"
465 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
466 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
467 "a=rtpmap:120 VP8/90000\r\n"
468 "a=ssrc-group:FEC 2 3\r\n"
469 "a=ssrc:2 cname:stream_1_cname\r\n"
470 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
471 "a=ssrc:2 mslabel:local_stream_1\r\n"
472 "a=ssrc:2 label:video_track_id_1\r\n"
473 "a=ssrc:3 cname:stream_1_cname\r\n"
474 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
475 "a=ssrc:3 mslabel:local_stream_1\r\n"
476 "a=ssrc:3 label:video_track_id_1\r\n"
477 "a=ssrc:5 cname:stream_2_cname\r\n"
478 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
479 "a=ssrc:5 mslabel:local_stream_2\r\n"
480 "a=ssrc:5 label:video_track_id_2\r\n"
481 "a=ssrc:6 cname:stream_2_cname\r\n"
482 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
483 "a=ssrc:6 mslabel:local_stream_2\r\n"
484 "a=ssrc:6 label:video_track_id_3\r\n";
485
486// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
487// tracks.
488static const char kUnifiedPlanSdpFullString[] =
489 "v=0\r\n"
490 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
491 "s=-\r\n"
492 "t=0 0\r\n"
493 "a=msid-semantic: WMS local_stream_1\r\n"
494 // Audio track 1, stream 1 (with candidates).
495 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
496 "c=IN IP4 74.125.127.126\r\n"
497 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
498 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
505 "generation 2\r\n"
506 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
507 "raddr 192.168.1.5 rport 2346 "
508 "generation 2\r\n"
509 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
510 "raddr 192.168.1.5 rport 2348 "
511 "generation 2\r\n"
512 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
513 "a=mid:audio_content_name\r\n"
514 "a=msid:local_stream_1 audio_track_id_1\r\n"
515 "a=sendrecv\r\n"
516 "a=rtcp-mux\r\n"
517 "a=rtcp-rsize\r\n"
518 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
519 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
520 "dummy_session_params\r\n"
521 "a=rtpmap:111 opus/48000/2\r\n"
522 "a=rtpmap:103 ISAC/16000\r\n"
523 "a=rtpmap:104 ISAC/32000\r\n"
524 "a=ssrc:1 cname:stream_1_cname\r\n"
525 // Video track 1, stream 1 (with candidates).
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:3 cname:stream_1_cname\r\n"
551 // Audio track 2, stream 2.
552 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
553 "c=IN IP4 0.0.0.0\r\n"
554 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
555 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
556 "a=mid:audio_content_name_2\r\n"
557 "a=msid:local_stream_2 audio_track_id_2\r\n"
558 "a=sendrecv\r\n"
559 "a=rtcp-mux\r\n"
560 "a=rtcp-rsize\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
562 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
563 "dummy_session_params\r\n"
564 "a=rtpmap:111 opus/48000/2\r\n"
565 "a=rtpmap:103 ISAC/16000\r\n"
566 "a=rtpmap:104 ISAC/32000\r\n"
567 "a=ssrc:4 cname:stream_2_cname\r\n"
568 // Video track 2, stream 2.
569 "m=video 9 RTP/SAVPF 120\r\n"
570 "c=IN IP4 0.0.0.0\r\n"
571 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
572 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
573 "a=mid:video_content_name_2\r\n"
574 "a=msid:local_stream_2 video_track_id_2\r\n"
575 "a=sendrecv\r\n"
576 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
577 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
578 "a=rtpmap:120 VP8/90000\r\n"
579 "a=ssrc:5 cname:stream_2_cname\r\n"
580 // Video track 3, stream 2.
581 "m=video 9 RTP/SAVPF 120\r\n"
582 "c=IN IP4 0.0.0.0\r\n"
583 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
584 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
585 "a=mid:video_content_name_3\r\n"
586 "a=msid:local_stream_2 video_track_id_3\r\n"
587 "a=sendrecv\r\n"
588 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
589 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
590 "a=rtpmap:120 VP8/90000\r\n"
591 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Seth Hampson5b4f0752018-04-02 16:31:36 -0700593// Unified Plan SDP reference string:
594// - audio track 1 has 1 a=msid lines
595// - audio track 2 has 2 a=msid lines
596// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
597// there are 0 media stream ids.
598// This Unified Plan SDP represents a SDP that signals the msid using both
599// a=msid and a=ssrc msid semantics.
600static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
601 "v=0\r\n"
602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
603 "s=-\r\n"
604 "t=0 0\r\n"
605 "a=msid-semantic: WMS local_stream_1\r\n"
606 // Audio track 1, with 1 stream id.
607 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
608 "c=IN IP4 74.125.127.126\r\n"
609 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
617 "generation 2\r\n"
618 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
619 "raddr 192.168.1.5 rport 2346 "
620 "generation 2\r\n"
621 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
622 "raddr 192.168.1.5 rport 2348 "
623 "generation 2\r\n"
624 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
625 "a=mid:audio_content_name\r\n"
626 "a=msid:local_stream_1 audio_track_id_1\r\n"
627 "a=sendrecv\r\n"
628 "a=rtcp-mux\r\n"
629 "a=rtcp-rsize\r\n"
630 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
631 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
632 "dummy_session_params\r\n"
633 "a=rtpmap:111 opus/48000/2\r\n"
634 "a=rtpmap:103 ISAC/16000\r\n"
635 "a=rtpmap:104 ISAC/32000\r\n"
636 "a=ssrc:1 cname:stream_1_cname\r\n"
637 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
638 "a=ssrc:1 mslabel:local_stream_1\r\n"
639 "a=ssrc:1 label:audio_track_id_1\r\n"
640 // Audio track 2, with two stream ids.
641 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
642 "c=IN IP4 0.0.0.0\r\n"
643 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
644 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
645 "a=mid:audio_content_name_2\r\n"
646 "a=msid:local_stream_1 audio_track_id_2\r\n"
647 "a=msid:local_stream_2 audio_track_id_2\r\n"
648 "a=sendrecv\r\n"
649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:4 cname:stream_1_cname\r\n"
658 // The support for Plan B msid signaling only includes the
659 // first media stream id "local_stream_1."
660 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
661 "a=ssrc:4 mslabel:local_stream_1\r\n"
662 "a=ssrc:4 label:audio_track_id_2\r\n"
663 // Audio track 3, with no stream ids.
664 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
665 "c=IN IP4 0.0.0.0\r\n"
666 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
667 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
668 "a=mid:audio_content_name_3\r\n"
669 "a=msid:- audio_track_id_3\r\n"
670 "a=sendrecv\r\n"
671 "a=rtcp-mux\r\n"
672 "a=rtcp-rsize\r\n"
673 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
674 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
675 "dummy_session_params\r\n"
676 "a=rtpmap:111 opus/48000/2\r\n"
677 "a=rtpmap:103 ISAC/16000\r\n"
678 "a=rtpmap:104 ISAC/32000\r\n"
679 "a=ssrc:7 cname:stream_2_cname\r\n";
680
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681// One candidate reference string as per W3c spec.
682// candidate:<blah> not a=candidate:<blah>CRLF
683static const char kRawCandidate[] =
684 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
685// One candidate reference string.
686static const char kSdpOneCandidate[] =
687 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
688 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000689
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000690static const char kSdpTcpActiveCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype active generation 2";
693static const char kSdpTcpPassiveCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype passive generation 2";
696static const char kSdpTcpSOCandidate[] =
697 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
698 "tcptype so generation 2";
699static const char kSdpTcpInvalidCandidate[] =
700 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
701 "tcptype invalid generation 2";
702
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000703// One candidate reference string with IPV6 address.
704static const char kRawIPV6Candidate[] =
705 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700706 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707
708// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800709static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800711 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
Zach Steinb336c272018-08-09 01:16:13 -0700713static const char kRawHostnameCandidate[] =
714 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
715
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716// Session id and version
717static const char kSessionId[] = "18446744069414584320";
718static const char kSessionVersion[] = "18446462598732840960";
719
deadbeef9d3584c2016-02-16 17:54:10 -0800720// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721static const char kIceOption1[] = "iceoption1";
722static const char kIceOption2[] = "iceoption2";
723static const char kIceOption3[] = "iceoption3";
724
deadbeef9d3584c2016-02-16 17:54:10 -0800725// ICE ufrags/passwords.
726static const char kUfragVoice[] = "ufrag_voice";
727static const char kPwdVoice[] = "pwd_voice";
728static const char kUfragVideo[] = "ufrag_video";
729static const char kPwdVideo[] = "pwd_video";
730static const char kUfragData[] = "ufrag_data";
731static const char kPwdData[] = "pwd_data";
732
733// Extra ufrags/passwords for extra unified plan m= sections.
734static const char kUfragVoice2[] = "ufrag_voice_2";
735static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700736static const char kUfragVoice3[] = "ufrag_voice_3";
737static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800738static const char kUfragVideo2[] = "ufrag_video_2";
739static const char kPwdVideo2[] = "pwd_video_2";
740static const char kUfragVideo3[] = "ufrag_video_3";
741static const char kPwdVideo3[] = "pwd_video_3";
742
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743// Content name
744static const char kAudioContentName[] = "audio_content_name";
745static const char kVideoContentName[] = "video_content_name";
746static const char kDataContentName[] = "data_content_name";
747
deadbeef9d3584c2016-02-16 17:54:10 -0800748// Extra content names for extra unified plan m= sections.
749static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700750static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800751static const char kVideoContentName2[] = "video_content_name_2";
752static const char kVideoContentName3[] = "video_content_name_3";
753
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800755static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756static const char kStream1Cname[] = "stream_1_cname";
757static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200758static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800760static const uint32_t kVideoTrack1Ssrc1 = 2;
761static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800764static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765static const char kStream2Cname[] = "stream_2_cname";
766static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200767static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800768static const char kVideoTrackId2[] = "video_track_id_2";
769static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800771static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700772static const char kAudioTrackId3[] = "audio_track_id_3";
773static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774
775// DataChannel
776static const char kDataChannelLabel[] = "data_channel";
777static const char kDataChannelMsid[] = "data_channeld0";
778static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200779static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781// Candidate
782static const char kDummyMid[] = "dummy_mid";
783static const int kDummyIndex = 123;
784
785// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800786static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788// Helper functions
789
790static bool SdpDeserialize(const std::string& message,
791 JsepSessionDescription* jdesc) {
792 return webrtc::SdpDeserialize(message, jdesc, NULL);
793}
794
795static bool SdpDeserializeCandidate(const std::string& message,
796 JsepIceCandidate* candidate) {
797 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
798}
799
800// Add some extra |newlines| to the |message| after |line|.
801static void InjectAfter(const std::string& line,
802 const std::string& newlines,
803 std::string* message) {
804 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200805 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
806 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
809static void Replace(const std::string& line,
810 const std::string& newlines,
811 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200812 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
813 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814}
815
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000816// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
817// message.
818static void ExpectParseFailure(const std::string& bad_sdp,
819 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800820 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000822 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000824 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
825}
826
827// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
828static void ExpectParseFailure(const char* good_part, const char* bad_part) {
829 std::string bad_sdp = kSdpFullString;
830 Replace(good_part, bad_part, &bad_sdp);
831 ExpectParseFailure(bad_sdp, bad_part);
832}
833
834// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
835static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
836 const std::string& newlines,
837 const std::string& bad_part) {
838 std::string bad_sdp = kSdpFullString;
839 InjectAfter(injectpoint, newlines, &bad_sdp);
840 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841}
842
Steve Anton4e70a722017-11-28 14:57:10 -0800843static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 std::string* message) {
845 std::string new_direction;
846 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800847 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 new_direction = "a=inactive";
849 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800850 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 new_direction = "a=sendonly";
852 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800853 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 new_direction = "a=recvonly";
855 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800856 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 default:
858 new_direction = "a=sendrecv";
859 break;
860 }
861 Replace("a=sendrecv", new_direction, message);
862}
863
Yves Gerey665174f2018-06-19 15:03:05 +0200864static void ReplaceRejected(bool audio_rejected,
865 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 std::string* message) {
867 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800868 Replace("m=audio 9", "m=audio 0", message);
869 Replace(kAttributeIceUfragVoice, "", message);
870 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 }
872 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800873 Replace("m=video 9", "m=video 0", message);
874 Replace(kAttributeIceUfragVideo, "", message);
875 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877}
878
879// WebRtcSdpTest
880
881class WebRtcSdpTest : public testing::Test {
882 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800883 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800884#ifdef WEBRTC_ANDROID
885 webrtc::InitializeAndroidObjects();
886#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // AudioContentDescription
888 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800889 StreamParams audio_stream;
890 audio_stream.id = kAudioTrackId1;
891 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800892 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800893 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
894 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
896 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800897 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800900 video_desc_ = CreateVideoContentDescription();
901 StreamParams video_stream;
902 video_stream.id = kVideoTrackId1;
903 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800904 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800905 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
906 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
907 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
908 video_stream.ssrc_groups.push_back(ssrc_group);
909 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700910 rtc::SocketAddress video_addr("74.125.224.39", 3457);
911 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800912 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800915 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
916 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
917 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
918 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919
920 // v4 host
921 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000923 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000924 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
925 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000932 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000935 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
947 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000948 cricket::LOCAL_PORT_TYPE,
949 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
952 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 cricket::LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000956 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
957 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000958 cricket::LOCAL_PORT_TYPE,
959 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 // stun
962 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000963 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
964 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
966 address_stun, kCandidatePriority, "", "",
967 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000968 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 candidate9.set_related_address(rel_address_stun);
970
971 address_stun.SetPort(port_stun++);
972 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
974 address_stun, kCandidatePriority, "", "",
975 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 candidate10.set_related_address(rel_address_stun);
978
979 // relay
980 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
983 address_relay, kCandidatePriority, "", "",
984 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000987 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
988 address_relay, kCandidatePriority, "", "",
989 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000990 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // voice
993 candidates_.push_back(candidate1);
994 candidates_.push_back(candidate2);
995 candidates_.push_back(candidate5);
996 candidates_.push_back(candidate6);
997 candidates_.push_back(candidate9);
998 candidates_.push_back(candidate10);
999
1000 // video
1001 candidates_.push_back(candidate3);
1002 candidates_.push_back(candidate4);
1003 candidates_.push_back(candidate7);
1004 candidates_.push_back(candidate8);
1005 candidates_.push_back(candidate11);
1006 candidates_.push_back(candidate12);
1007
Yves Gerey665174f2018-06-19 15:03:05 +02001008 jcandidate_.reset(
1009 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // Set up JsepSessionDescription.
1012 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1013 std::string mline_id;
1014 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001015 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // In this test, the audio m line index will be 0, and the video m line
1017 // will be 1.
1018 bool is_video = (i > 5);
1019 mline_id = is_video ? "video_content_name" : "audio_content_name";
1020 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001021 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 jdesc_.AddCandidate(&jice);
1023 }
1024 }
1025
Seth Hampson5b4f0752018-04-02 16:31:36 -07001026 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001027 const IceCandidateCollection* video_candidates_collection =
1028 jdesc_.candidates(1);
1029 ASSERT_NE(nullptr, video_candidates_collection);
1030 std::vector<cricket::Candidate> video_candidates;
1031 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1032 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1033 c.set_transport_name("video_content_name");
1034 video_candidates.push_back(c);
1035 }
1036 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001037 }
1038
1039 // Turns the existing reference description into a description using
1040 // a=bundle-only. This means no transport attributes and a 0 port value on
1041 // the m= sections not associated with the BUNDLE-tag.
1042 void MakeBundleOnlyDescription() {
1043 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001044
1045 // And the rest of the transport attributes.
1046 desc_.transport_infos()[1].description.ice_ufrag.clear();
1047 desc_.transport_infos()[1].description.ice_pwd.clear();
1048 desc_.transport_infos()[1].description.connection_role =
1049 cricket::CONNECTIONROLE_NONE;
1050
1051 // Set bundle-only flag.
1052 desc_.contents()[1].bundle_only = true;
1053
1054 // Add BUNDLE group.
1055 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1056 group.AddContentName(kAudioContentName);
1057 group.AddContentName(kVideoContentName);
1058 desc_.AddGroup(group);
1059
1060 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1061 jdesc_.session_version()));
1062 }
1063
deadbeef9d3584c2016-02-16 17:54:10 -08001064 // Turns the existing reference description into a plan B description,
1065 // with 2 audio tracks and 3 video tracks.
1066 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001067 audio_desc_ = audio_desc_->Copy();
1068 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001069
1070 StreamParams audio_track_2;
1071 audio_track_2.id = kAudioTrackId2;
1072 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001073 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001074 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1075 audio_desc_->AddStream(audio_track_2);
1076
1077 StreamParams video_track_2;
1078 video_track_2.id = kVideoTrackId2;
1079 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001080 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001081 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1082 video_desc_->AddStream(video_track_2);
1083
1084 StreamParams video_track_3;
1085 video_track_3.id = kVideoTrackId3;
1086 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001087 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001088 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1089 video_desc_->AddStream(video_track_3);
1090
1091 desc_.RemoveContentByName(kAudioContentName);
1092 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001093 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1094 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001095
1096 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1097 jdesc_.session_version()));
1098 }
1099
1100 // Turns the existing reference description into a unified plan description,
1101 // with 2 audio tracks and 3 video tracks.
1102 void MakeUnifiedPlanDescription() {
1103 // Audio track 2.
1104 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1105 StreamParams audio_track_2;
1106 audio_track_2.id = kAudioTrackId2;
1107 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001108 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001109 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1110 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001111 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001112 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1113 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001114 // Video track 2, in stream 2.
1115 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1116 StreamParams video_track_2;
1117 video_track_2.id = kVideoTrackId2;
1118 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001119 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001120 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1121 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001122 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001123 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1124 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1125
1126 // Video track 3, in stream 2.
1127 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1128 StreamParams video_track_3;
1129 video_track_3.id = kVideoTrackId3;
1130 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001131 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001132 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1133 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001134 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001135 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1136 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001137 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001138
1139 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1140 jdesc_.session_version()));
1141 }
1142
1143 // Creates an audio content description with no streams, and some default
1144 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 AudioContentDescription* CreateAudioContentDescription() {
1146 AudioContentDescription* audio = new AudioContentDescription();
1147 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001148 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001149 audio->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1152 "dummy_session_params"));
1153 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001154 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001155 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001156 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1157 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 return audio;
1159 }
1160
Seth Hampson5b4f0752018-04-02 16:31:36 -07001161 // Turns the existing reference description into a unified plan description,
1162 // with 3 audio MediaContentDescriptions with special StreamParams that
1163 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1164 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1165 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1166 desc_.RemoveContentByName(kVideoContentName);
1167 desc_.RemoveTransportInfoByName(kVideoContentName);
1168 RemoveVideoCandidates();
1169
1170 // Audio track 2 has 2 media stream ids.
1171 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1172 StreamParams audio_track_2;
1173 audio_track_2.id = kAudioTrackId2;
1174 audio_track_2.cname = kStream1Cname;
1175 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1176 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1177 audio_desc_2->AddStream(audio_track_2);
1178 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1179 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1180 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1181
1182 // Audio track 3 has no stream ids.
1183 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1184 StreamParams audio_track_3;
1185 audio_track_3.id = kAudioTrackId3;
1186 audio_track_3.cname = kStream2Cname;
1187 audio_track_3.set_stream_ids({});
1188 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1189 audio_desc_3->AddStream(audio_track_3);
1190 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1191 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1192 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1193 // Make sure to create both a=msid lines.
1194 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1195 cricket::kMsidSignalingSsrcAttribute);
1196 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1197 jdesc_.session_version()));
1198 }
1199
Seth Hampson5897a6e2018-04-03 11:16:33 -07001200 // Turns the existing reference description into a unified plan description
1201 // with one audio MediaContentDescription that contains one StreamParams with
1202 // 0 ssrcs.
1203 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1204 desc_.RemoveContentByName(kVideoContentName);
1205 desc_.RemoveContentByName(kAudioContentName);
1206 desc_.RemoveTransportInfoByName(kVideoContentName);
1207 RemoveVideoCandidates();
1208
1209 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1210 StreamParams audio_track;
1211 audio_track.id = kAudioTrackId1;
1212 audio_track.set_stream_ids({kStreamId1});
1213 audio_desc->AddStream(audio_track);
1214 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1215
1216 // Enable signaling a=msid lines.
1217 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1218 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1219 jdesc_.session_version()));
1220 }
1221
deadbeef9d3584c2016-02-16 17:54:10 -08001222 // Creates a video content description with no streams, and some default
1223 // configuration.
1224 VideoContentDescription* CreateVideoContentDescription() {
1225 VideoContentDescription* video = new VideoContentDescription();
1226 video->AddCrypto(CryptoParams(
1227 1, "AES_CM_128_HMAC_SHA1_80",
1228 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1229 video->set_protocol(cricket::kMediaProtocolSavpf);
1230 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001231 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001232 return video;
1233 }
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001236 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // type
1238 EXPECT_EQ(cd1->type(), cd1->type());
1239
1240 // content direction
1241 EXPECT_EQ(cd1->direction(), cd2->direction());
1242
1243 // rtcp_mux
1244 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1245
deadbeef13871492015-12-09 12:37:51 -08001246 // rtcp_reduced_size
1247 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // cryptos
1250 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1251 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1252 ADD_FAILURE();
1253 return;
1254 }
Yves Gerey665174f2018-06-19 15:03:05 +02001255 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 const CryptoParams c1 = cd1->cryptos().at(i);
1257 const CryptoParams c2 = cd2->cryptos().at(i);
1258 EXPECT_TRUE(c1.Matches(c2));
1259 EXPECT_EQ(c1.key_params, c2.key_params);
1260 EXPECT_EQ(c1.session_params, c2.session_params);
1261 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001264 // Use an equivalence class here, for old and new versions of the
1265 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001266 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1267 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1268 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001269 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001270 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1271 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1272 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001273 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001274 } else {
1275 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277
1278 // codecs
1279 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1280
1281 // bandwidth
1282 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1283
1284 // streams
1285 EXPECT_EQ(cd1->streams(), cd2->streams());
1286
Johannes Kron0854eb62018-10-10 22:33:20 +02001287 // extmap-allow-mixed
Johannes Kron9ac3c912018-10-12 10:54:26 +02001288 EXPECT_EQ(cd1->extmap_allow_mixed_headers(),
1289 cd2->extmap_allow_mixed_headers());
Johannes Kron0854eb62018-10-10 22:33:20 +02001290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 // extmap
1292 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1293 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001294 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001295 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1296 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_EQ(ext1.uri, ext2.uri);
1298 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001299 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 }
1302
zstein4b2e0822017-02-17 19:48:38 -08001303 void CompareDataContentDescription(const DataContentDescription* dcd1,
1304 const DataContentDescription* dcd2) {
1305 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1306 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1307 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308
1309 void CompareSessionDescription(const SessionDescription& desc1,
1310 const SessionDescription& desc2) {
1311 // Compare content descriptions.
1312 if (desc1.contents().size() != desc2.contents().size()) {
1313 ADD_FAILURE();
1314 return;
1315 }
Yves Gerey665174f2018-06-19 15:03:05 +02001316 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1318 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001319 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001321 EXPECT_EQ(c1.type, c2.type);
1322 EXPECT_EQ(c1.rejected, c2.rejected);
1323 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324
1325 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1326 if (IsAudioContent(&c1)) {
1327 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1332 }
1333
1334 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1335 if (IsVideoContent(&c1)) {
1336 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001337 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001339 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1341 }
1342
1343 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1344 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001345 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1346 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001347 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 }
1349 }
1350
1351 // group
1352 const cricket::ContentGroups groups1 = desc1.groups();
1353 const cricket::ContentGroups groups2 = desc2.groups();
1354 EXPECT_EQ(groups1.size(), groups1.size());
1355 if (groups1.size() != groups2.size()) {
1356 ADD_FAILURE();
1357 return;
1358 }
1359 for (size_t i = 0; i < groups1.size(); ++i) {
1360 const cricket::ContentGroup group1 = groups1.at(i);
1361 const cricket::ContentGroup group2 = groups2.at(i);
1362 EXPECT_EQ(group1.semantics(), group2.semantics());
1363 const cricket::ContentNames names1 = group1.content_names();
1364 const cricket::ContentNames names2 = group2.content_names();
1365 EXPECT_EQ(names1.size(), names2.size());
1366 if (names1.size() != names2.size()) {
1367 ADD_FAILURE();
1368 return;
1369 }
1370 cricket::ContentNames::const_iterator iter1 = names1.begin();
1371 cricket::ContentNames::const_iterator iter2 = names2.begin();
1372 while (iter1 != names1.end()) {
1373 EXPECT_EQ(*iter1++, *iter2++);
1374 }
1375 }
1376
1377 // transport info
1378 const cricket::TransportInfos transports1 = desc1.transport_infos();
1379 const cricket::TransportInfos transports2 = desc2.transport_infos();
1380 EXPECT_EQ(transports1.size(), transports2.size());
1381 if (transports1.size() != transports2.size()) {
1382 ADD_FAILURE();
1383 return;
1384 }
1385 for (size_t i = 0; i < transports1.size(); ++i) {
1386 const cricket::TransportInfo transport1 = transports1.at(i);
1387 const cricket::TransportInfo transport2 = transports2.at(i);
1388 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_EQ(transport1.description.ice_ufrag,
1390 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001391 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001392 EXPECT_EQ(transport1.description.ice_mode,
1393 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 if (transport1.description.identity_fingerprint) {
1395 EXPECT_EQ(*transport1.description.identity_fingerprint,
1396 *transport2.description.identity_fingerprint);
1397 } else {
1398 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1399 transport2.description.identity_fingerprint.get());
1400 }
1401 EXPECT_EQ(transport1.description.transport_options,
1402 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 }
deadbeefc80741f2015-10-22 13:14:45 -07001404
1405 // global attributes
1406 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9ac3c912018-10-12 10:54:26 +02001407 EXPECT_EQ(desc1.extmap_allow_mixed_headers(),
1408 desc2.extmap_allow_mixed_headers());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 }
1410
Yves Gerey665174f2018-06-19 15:03:05 +02001411 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1412 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1414 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1415 CompareSessionDescription(*desc1.description(), *desc2.description());
1416 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1417 return false;
1418 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1419 const IceCandidateCollection* cc1 = desc1.candidates(i);
1420 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001421 if (cc1->count() != cc2->count()) {
1422 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 for (size_t j = 0; j < cc1->count(); ++j) {
1426 const IceCandidateInterface* c1 = cc1->at(j);
1427 const IceCandidateInterface* c2 = cc2->at(j);
1428 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1429 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1430 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1431 }
1432 }
1433 return true;
1434 }
1435
1436 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1437 // them with invalid keywords so that the parser will just ignore them.
1438 bool RemoveCandidateUfragPwd(std::string* sdp) {
1439 const char ice_ufrag[] = "a=ice-ufrag";
1440 const char ice_ufragx[] = "a=xice-ufrag";
1441 const char ice_pwd[] = "a=ice-pwd";
1442 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001443 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1444 strlen(ice_ufragx), sdp);
1445 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1446 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 return true;
1448 }
1449
1450 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001451 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1452 int mline_index,
1453 const std::string& ufrag,
1454 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 std::string content_name;
1456 if (mline_index == 0) {
1457 content_name = kAudioContentName;
1458 } else if (mline_index == 1) {
1459 content_name = kVideoContentName;
1460 } else {
nissec80e7412017-01-11 05:56:46 -08001461 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 }
Yves Gerey665174f2018-06-19 15:03:05 +02001463 TransportInfo transport_info(content_name,
1464 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SessionDescription* desc =
1466 const_cast<SessionDescription*>(jdesc->description());
1467 desc->RemoveTransportInfoByName(content_name);
1468 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1469 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1470 const IceCandidateCollection* cc = jdesc_.candidates(i);
1471 for (size_t j = 0; j < cc->count(); ++j) {
1472 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001473 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1474 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 }
1476 }
1477 }
1478 return true;
1479 }
1480
1481 void AddIceOptions(const std::string& content_name,
1482 const std::vector<std::string>& transport_options) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.transport_options = transport_options;
1488 desc_.AddTransportInfo(transport_info);
1489 }
1490
deadbeef3f7219b2015-12-28 15:17:14 -08001491 void SetIceUfragPwd(const std::string& content_name,
1492 const std::string& ice_ufrag,
1493 const std::string& ice_pwd) {
1494 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1495 cricket::TransportInfo transport_info =
1496 *(desc_.GetTransportInfoByName(content_name));
1497 desc_.RemoveTransportInfoByName(content_name);
1498 transport_info.description.ice_ufrag = ice_ufrag;
1499 transport_info.description.ice_pwd = ice_pwd;
1500 desc_.AddTransportInfo(transport_info);
1501 }
1502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 void AddFingerprint() {
1504 desc_.RemoveTransportInfoByName(kAudioContentName);
1505 desc_.RemoveTransportInfoByName(kVideoContentName);
Mirko Bonadei6932fb22018-10-15 14:18:03 +00001506 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1507 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001508 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1509 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001510 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1511 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001512 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1513 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1514 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001515 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1516 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001517 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 }
1519
jbauch5869f502017-06-29 12:31:36 -07001520 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001521 audio_desc_ = audio_desc_->Copy();
1522 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001523 audio_desc_->AddRtpHeaderExtension(
1524 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1525 video_desc_->AddRtpHeaderExtension(
1526 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 desc_.RemoveContentByName(kAudioContentName);
1528 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001529 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1530 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 }
1532
1533 void RemoveCryptos() {
1534 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1535 video_desc_->set_cryptos(std::vector<CryptoParams>());
1536 }
1537
Seth Hampson5897a6e2018-04-03 11:16:33 -07001538 // Removes everything in StreamParams from the session description that is
1539 // used for a=ssrc lines.
1540 void RemoveSsrcSignalingFromStreamParams() {
1541 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1542 // With Unified Plan there should be one StreamParams per m= section.
1543 StreamParams& stream =
1544 content_info.media_description()->mutable_streams()[0];
1545 stream.ssrcs.clear();
1546 stream.ssrc_groups.clear();
1547 stream.cname.clear();
1548 }
1549 }
1550
1551 // Removes all a=ssrc lines from the SDP string.
1552 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1553 const char kAttributeSsrc[] = "a=ssrc";
1554 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1555 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1556 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1557 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1558 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1559 }
1560 }
1561
Steve Anton4e70a722017-11-28 14:57:10 -08001562 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 audio_desc_->set_direction(direction);
1564 video_desc_->set_direction(direction);
1565 std::string new_sdp = kSdpFullString;
1566 ReplaceDirection(direction, &new_sdp);
1567
Yves Gerey665174f2018-06-19 15:03:05 +02001568 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 jdesc_.session_version())) {
1570 return false;
1571 }
Steve Antone831b8c2018-02-01 12:22:16 -08001572 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 EXPECT_EQ(new_sdp, message);
1574 return true;
1575 }
1576
1577 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001578 audio_desc_ = audio_desc_->Copy();
1579 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 desc_.RemoveContentByName(kAudioContentName);
1582 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001583 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001585 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001587 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1588 audio_rejected ? "" : kPwdVoice);
1589 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1590 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001591
1592 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1594
Steve Antona3a92c22017-12-07 10:27:41 -08001595 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001596 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001597 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_EQ(new_sdp, message);
1599 return true;
1600 }
1601
zstein4b2e0822017-02-17 19:48:38 -08001602 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001603 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001605 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001607 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001608 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001609 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1610 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001611 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1612 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001613 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1614 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 }
1616
1617 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001618 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 data_desc_ = data.get();
1620
deadbeef67cf2c12016-04-13 10:07:16 -07001621 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 StreamParams data_stream;
1623 data_stream.id = kDataChannelMsid;
1624 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001625 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 data_stream.ssrcs.push_back(kDataChannelSsrc);
1627 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001628 data_desc_->AddCrypto(
1629 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1630 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001632 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001633 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1634 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 }
1636
Steve Anton4e70a722017-11-28 14:57:10 -08001637 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 std::string new_sdp = kSdpFullString;
1639 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001640 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641
1642 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1643
1644 audio_desc_->set_direction(direction);
1645 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001646 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 jdesc_.session_version())) {
1648 return false;
1649 }
1650 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1651 return true;
1652 }
1653
1654 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001655 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001657 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001659
Steve Antonb1c1de12017-12-21 15:14:30 -08001660 audio_desc_ = audio_desc_->Copy();
1661 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 desc_.RemoveContentByName(kAudioContentName);
1663 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001664 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001666 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001668 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1669 audio_rejected ? "" : kPwdVoice);
1670 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1671 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001672 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001673 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1674 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 return false;
1676 }
deadbeef3f7219b2015-12-28 15:17:14 -08001677 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 return true;
1679 }
1680
Yves Gerey665174f2018-06-19 15:03:05 +02001681 void TestDeserializeExtmap(bool session_level,
1682 bool media_level,
1683 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001684 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001685 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001686 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001688 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 std::string sdp_with_extmap = kSdpString;
1690 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001691 InjectAfter(kSessionTime,
1692 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1693 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 &sdp_with_extmap);
1695 }
1696 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001697 InjectAfter(kAttributeIcePwdVoice,
1698 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1699 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001701 InjectAfter(kAttributeIcePwdVideo,
1702 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1703 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 &sdp_with_extmap);
1705 }
1706 // The extmap can't be present at the same time in both session level and
1707 // media level.
1708 if (session_level && media_level) {
1709 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001710 EXPECT_FALSE(
1711 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1713 } else {
1714 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1715 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1716 }
1717 }
1718
1719 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001720 const std::string& name,
1721 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 cricket::CodecParameterMap::const_iterator found = params.find(name);
1723 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001724 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 }
1726
1727 void TestDeserializeCodecParams(const CodecParams& params,
1728 JsepSessionDescription* jdesc_output) {
1729 std::string sdp =
1730 "v=0\r\n"
1731 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1732 "s=-\r\n"
1733 "t=0 0\r\n"
1734 // Include semantics for WebRTC Media Streams since it is supported by
1735 // this parser, and will be added to the SDP when serializing a session
1736 // description.
1737 "a=msid-semantic: WMS\r\n"
1738 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001739 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 // Pltype 111 listed before 103 and 104 in the map.
1741 "a=rtpmap:111 opus/48000/2\r\n"
1742 // Pltype 103 listed before 104.
1743 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001744 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001745 "a=fmtp:111 0-15,66,70\r\n"
1746 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001748 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001749 << "; sprop-stereo=" << params.sprop_stereo
1750 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001751 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 << "a=ptime:" << params.ptime << "\r\n"
1753 << "a=maxptime:" << params.max_ptime << "\r\n";
1754 sdp += os.str();
1755
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001756 os.clear();
1757 os.str("");
1758 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001759 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001760 << "a=rtpmap:99 VP8/90000\r\n"
1761 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001762 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001763 sdp += os.str();
1764
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 // Deserialize
1766 SdpParseError error;
1767 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001770 GetFirstAudioContentDescription(jdesc_output->description());
1771 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 ASSERT_FALSE(acd->codecs().empty());
1773 cricket::AudioCodec opus = acd->codecs()[0];
1774 EXPECT_EQ("opus", opus.name);
1775 EXPECT_EQ(111, opus.id);
1776 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1777 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1778 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1779 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001780 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1781 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1783 cricket::AudioCodec codec = acd->codecs()[i];
1784 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1785 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001787
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001788 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001789 GetFirstVideoContentDescription(jdesc_output->description());
1790 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001791 ASSERT_FALSE(vcd->codecs().empty());
1792 cricket::VideoCodec vp8 = vcd->codecs()[0];
1793 EXPECT_EQ("VP8", vp8.name);
1794 EXPECT_EQ(99, vp8.id);
1795 cricket::VideoCodec rtx = vcd->codecs()[1];
1796 EXPECT_EQ("RTX", rtx.name);
1797 EXPECT_EQ(95, rtx.id);
1798 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 }
1800
1801 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1802 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001803 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 "v=0\r\n"
1805 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1806 "s=-\r\n"
1807 "t=0 0\r\n"
1808 // Include semantics for WebRTC Media Streams since it is supported by
1809 // this parser, and will be added to the SDP when serializing a session
1810 // description.
1811 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001812 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001813 "a=rtpmap:111 opus/48000/2\r\n";
1814 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 "m=video 3457 RTP/SAVPF 101\r\n"
1816 "a=rtpmap:101 VP8/90000\r\n"
1817 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001818 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001819 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001821 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001822 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001823 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001824 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001825 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 // Deserialize
1827 SdpParseError error;
1828 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001830 GetFirstAudioContentDescription(jdesc_output->description());
1831 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 ASSERT_FALSE(acd->codecs().empty());
1833 cricket::AudioCodec opus = acd->codecs()[0];
1834 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001835 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1836 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001839 GetFirstVideoContentDescription(jdesc_output->description());
1840 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 ASSERT_FALSE(vcd->codecs().empty());
1842 cricket::VideoCodec vp8 = vcd->codecs()[0];
1843 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1844 vp8.name.c_str());
1845 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001846 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1847 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1848 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1849 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1850 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1851 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1852 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1853 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 }
1855
1856 // Two SDP messages can mean the same thing but be different strings, e.g.
1857 // some of the lines can be serialized in different order.
1858 // However, a deserialized description can be compared field by field and has
1859 // no order. If deserializer has already been tested, serializing then
1860 // deserializing and comparing JsepSessionDescription will test
1861 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001862 void TestSerialize(const JsepSessionDescription& jdesc) {
1863 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001864 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 SdpParseError error;
1866 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1867 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1868 }
1869
zhihuang38989e52017-03-21 11:04:53 -07001870 // Calling 'Initialize' with a copy of the inner SessionDescription will
1871 // create a copy of the JsepSessionDescription without candidates. The
1872 // 'connection address' field, previously set from the candidates, must also
1873 // be reset.
1874 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1875 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1876 rtc::SocketAddress video_addr("0.0.0.0", 9);
1877 audio_desc_->set_connection_address(audio_addr);
1878 video_desc_->set_connection_address(video_addr);
1879 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1880 }
1881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 protected:
1883 SessionDescription desc_;
1884 AudioContentDescription* audio_desc_;
1885 VideoContentDescription* video_desc_;
1886 DataContentDescription* data_desc_;
1887 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001888 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 JsepSessionDescription jdesc_;
1890};
1891
1892void TestMismatch(const std::string& string1, const std::string& string2) {
1893 int position = 0;
1894 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1895 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001896 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 break;
1898 }
1899 }
1900 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1901 << " character\n"
1902 << " 1: " << string1.substr(position, 20) << "\n"
1903 << " 2: " << string2.substr(position, 20) << "\n";
1904}
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1907 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001908 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 TestMismatch(std::string(kSdpFullString), message);
1910}
1911
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001913 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001914 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915}
1916
1917// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1918// the case in a DTLS offer.
1919TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1920 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001921 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001922 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001923 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924
1925 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001926 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1927 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
1929 EXPECT_EQ(sdp_with_fingerprint, message);
1930}
1931
1932// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1933// be the case in a DTLS answer.
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1935 AddFingerprint();
1936 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001937 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001938 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001939 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940
1941 std::string sdp_with_fingerprint = kSdpString;
1942 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1943 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001944 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1945 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946
1947 EXPECT_EQ(sdp_with_fingerprint, message);
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1951 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001952 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001953 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 EXPECT_EQ(std::string(kSdpString), message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1959 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1960 group.AddContentName(kAudioContentName);
1961 group.AddContentName(kVideoContentName);
1962 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001963 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001965 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 std::string sdp_with_bundle = kSdpFullString;
1967 InjectAfter(kSessionTime,
1968 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1969 &sdp_with_bundle);
1970 EXPECT_EQ(sdp_with_bundle, message);
1971}
1972
1973TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001974 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001976 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001978 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001980 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001982 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001984 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 &sdp_with_bandwidth);
1986 EXPECT_EQ(sdp_with_bandwidth, message);
1987}
1988
1989TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1990 std::vector<std::string> transport_options;
1991 transport_options.push_back(kIceOption1);
1992 transport_options.push_back(kIceOption3);
1993 AddIceOptions(kAudioContentName, transport_options);
1994 transport_options.clear();
1995 transport_options.push_back(kIceOption2);
1996 transport_options.push_back(kIceOption3);
1997 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001998 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002000 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002002 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002004 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 &sdp_with_ice_options);
2006 EXPECT_EQ(sdp_with_ice_options, message);
2007}
2008
2009TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002010 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011}
2012
2013TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002014 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015}
2016
2017TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002018 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019}
2020
2021TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2022 EXPECT_TRUE(TestSerializeRejected(true, false));
2023}
2024
2025TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2026 EXPECT_TRUE(TestSerializeRejected(false, true));
2027}
2028
2029TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2030 EXPECT_TRUE(TestSerializeRejected(true, true));
2031}
2032
2033TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2034 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002035 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036
zhihuang38989e52017-03-21 11:04:53 -07002037 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002038 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 std::string expected_sdp = kSdpString;
2041 expected_sdp.append(kSdpRtpDataChannelString);
2042 EXPECT_EQ(expected_sdp, message);
2043}
2044
2045TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002046 bool use_sctpmap = true;
2047 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002048 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
zhihuang38989e52017-03-21 11:04:53 -07002050 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002051 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
2053 std::string expected_sdp = kSdpString;
2054 expected_sdp.append(kSdpSctpDataChannelString);
2055 EXPECT_EQ(message, expected_sdp);
2056}
2057
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002058TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002059 bool use_sctpmap = true;
2060 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002061 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002062 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002063 DataContentDescription* dcdesc =
2064 jsep_desc.description()
2065 ->GetContentDescriptionByName(kDataContentName)
2066 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002067
2068 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002069 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002070 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002071 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2072 dcdesc->AddOrReplaceCodec(codec);
2073
Steve Antone831b8c2018-02-01 12:22:16 -08002074 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002075
2076 std::string expected_sdp = kSdpString;
2077 expected_sdp.append(kSdpSctpDataChannelString);
2078
2079 char default_portstr[16];
2080 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002081 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2082 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002083 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2084 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002085
2086 EXPECT_EQ(expected_sdp, message);
2087}
2088
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002089TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002090 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002091 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002092 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002093 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002094 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002095
2096 std::string expected_sdp = kSdpString;
2097 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002098 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002099 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002100 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002101 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002102}
2103
Johannes Kron0854eb62018-10-10 22:33:20 +02002104TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002105 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002106 TestSerialize(jdesc_);
2107}
2108
2109TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2110 cricket::MediaContentDescription* video_desc =
2111 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2112 ASSERT_TRUE(video_desc);
2113 cricket::MediaContentDescription* audio_desc =
2114 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2115 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002116 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002117 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002118 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002119 cricket::MediaContentDescription::kMedia);
2120 TestSerialize(jdesc_);
2121}
2122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002124 bool encrypted = false;
2125 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002126 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002127 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002128 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129
2130 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002131 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2132 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
2134 EXPECT_EQ(sdp_with_extmap, message);
2135}
2136
jbauch5869f502017-06-29 12:31:36 -07002137TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2138 bool encrypted = true;
2139 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002140 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002141 ASSERT_TRUE(
2142 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002143 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002144}
2145
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146TEST_F(WebRtcSdpTest, SerializeCandidates) {
2147 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002148 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002149
2150 Candidate candidate_with_ufrag(candidates_.front());
2151 candidate_with_ufrag.set_username("ABC");
2152 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2153 candidate_with_ufrag));
2154 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2155 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002156
2157 Candidate candidate_with_network_info(candidates_.front());
2158 candidate_with_network_info.set_network_id(1);
2159 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2160 candidate_with_network_info));
2161 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2162 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2163 candidate_with_network_info.set_network_cost(999);
2164 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2165 candidate_with_network_info));
2166 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2167 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2168 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169}
2170
Zach Steinb336c272018-08-09 01:16:13 -07002171TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2172 rtc::SocketAddress address("a.test", 1234);
2173 cricket::Candidate candidate(
2174 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2175 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2176 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2177 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2178 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2179}
2180
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002181// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2182// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002183TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002184 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002185 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2186 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2187 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002188 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002189 std::unique_ptr<IceCandidateInterface> jcandidate(
2190 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002191
2192 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2193 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2194}
2195
htaa6b99442016-04-12 10:29:17 -07002196TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002197 cricket::VideoCodec h264_codec("H264");
2198 h264_codec.SetParam("profile-level-id", "42e01f");
2199 h264_codec.SetParam("level-asymmetry-allowed", "1");
2200 h264_codec.SetParam("packetization-mode", "1");
2201 video_desc_->AddCodec(h264_codec);
2202
htaa6b99442016-04-12 10:29:17 -07002203 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2204
Steve Antone831b8c2018-02-01 12:22:16 -08002205 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002206 size_t after_pt = message.find(" H264/90000");
2207 ASSERT_NE(after_pt, std::string::npos);
2208 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2209 ASSERT_NE(before_pt, std::string::npos);
2210 before_pt += strlen("a=rtpmap:");
2211 std::string pt = message.substr(before_pt, after_pt - before_pt);
2212 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2213 std::string to_find = "a=fmtp:" + pt + " ";
2214 size_t fmtp_pos = message.find(to_find);
2215 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2216 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2217 ASSERT_NE(std::string::npos, fmtp_endpos);
2218 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2219 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2220 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2221 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002222 // Check that there are no spaces after semicolons.
2223 // https://bugs.webrtc.org/5793
2224 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002225}
2226
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002228 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 // Deserialize
2230 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2231 // Verify
2232 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2233}
2234
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002235TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002236 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002237 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002238 "v=0\r\n"
2239 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2240 "s=-\r\n"
2241 "t=0 0\r\n"
2242 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002243 // Deserialize
2244 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2245 EXPECT_EQ(0u, jdesc.description()->contents().size());
2246}
2247
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002249 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 std::string sdp_without_carriage_return = kSdpFullString;
2251 Replace("\r\n", "\n", &sdp_without_carriage_return);
2252 // Deserialize
2253 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2254 // Verify
2255 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2256}
2257
2258TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2259 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002260 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002261 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2262 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002263 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2265 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2266}
2267
2268TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2269 static const char kSdpNoRtpmapString[] =
2270 "v=0\r\n"
2271 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2272 "s=-\r\n"
2273 "t=0 0\r\n"
2274 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2275 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002276 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 // The rtpmap line for static payload codec is optional.
2278 "a=rtpmap:18 G729/16000\r\n"
2279 "a=rtpmap:103 ISAC/16000\r\n";
2280
Steve Antona3a92c22017-12-07 10:27:41 -08002281 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2283 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002284 jdesc.description()
2285 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2286 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002288 // The codecs in the AudioContentDescription should be in the same order as
2289 // the payload types (<fmt>s) on the m= line.
2290 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2291 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002292 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 EXPECT_EQ(ref_codecs, audio->codecs());
2294}
2295
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002296TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2297 static const char kSdpNoRtpmapString[] =
2298 "v=0\r\n"
2299 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2300 "s=-\r\n"
2301 "t=0 0\r\n"
2302 "m=audio 49232 RTP/AVP 18 103\r\n"
2303 "a=fmtp:18 annexb=yes\r\n"
2304 "a=rtpmap:103 ISAC/16000\r\n";
2305
Steve Antona3a92c22017-12-07 10:27:41 -08002306 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002307 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2308 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002309 jdesc.description()
2310 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2311 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002312
2313 cricket::AudioCodec g729 = audio->codecs()[0];
2314 EXPECT_EQ("G729", g729.name);
2315 EXPECT_EQ(8000, g729.clockrate);
2316 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002317 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002318 ASSERT_TRUE(found != g729.params.end());
2319 EXPECT_EQ(found->second, "yes");
2320
2321 cricket::AudioCodec isac = audio->codecs()[1];
2322 EXPECT_EQ("ISAC", isac.name);
2323 EXPECT_EQ(103, isac.id);
2324 EXPECT_EQ(16000, isac.clockrate);
2325}
2326
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327// Ensure that we can deserialize SDP with a=fingerprint properly.
2328TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2329 // Add a DTLS a=fingerprint attribute to our session description.
2330 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002331 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002332 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 jdesc_.session_version()));
2334
Steve Antona3a92c22017-12-07 10:27:41 -08002335 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 std::string sdp_with_fingerprint = kSdpString;
2337 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2338 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2339 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2340 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2341}
2342
2343TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002344 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 std::string sdp_with_bundle = kSdpFullString;
2346 InjectAfter(kSessionTime,
2347 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2348 &sdp_with_bundle);
2349 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2350 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2351 group.AddContentName(kAudioContentName);
2352 group.AddContentName(kVideoContentName);
2353 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002354 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 jdesc_.session_version()));
2356 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2357}
2358
2359TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002360 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002362 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002364 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002366 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002367 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002369 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002371 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 jdesc_.session_version()));
2373 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2374}
2375
2376TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002377 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002379 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002381 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002383 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 &sdp_with_ice_options);
2385 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2386 std::vector<std::string> transport_options;
2387 transport_options.push_back(kIceOption3);
2388 transport_options.push_back(kIceOption1);
2389 AddIceOptions(kAudioContentName, transport_options);
2390 transport_options.clear();
2391 transport_options.push_back(kIceOption3);
2392 transport_options.push_back(kIceOption2);
2393 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002394 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 jdesc_.session_version()));
2396 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2397}
2398
2399TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2400 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002401 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 std::string sdp_with_ufrag_pwd = kSdpFullString;
2403 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2404 // Add session level ufrag and pwd
2405 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002406 "a=ice-pwd:session+level+icepwd\r\n"
2407 "a=ice-ufrag:session+level+iceufrag\r\n",
2408 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002410 InjectAfter(
2411 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2413 &sdp_with_ufrag_pwd);
2414 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002415 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2416 "media+level+icepwd"));
2417 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2418 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2420 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2421}
2422
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002424 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425}
2426
2427TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002428 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429}
2430
2431TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002432 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433}
2434
2435TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2436 EXPECT_TRUE(TestDeserializeRejected(true, false));
2437}
2438
2439TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2440 EXPECT_TRUE(TestDeserializeRejected(false, true));
2441}
2442
2443TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2444 EXPECT_TRUE(TestDeserializeRejected(true, true));
2445}
2446
2447// Tests that we can still handle the sdp uses mslabel and label instead of
2448// msid for backward compatibility.
2449TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002450 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002451 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 std::string sdp_without_msid = kSdpFullString;
2453 Replace("msid", "xmsid", &sdp_without_msid);
2454 // Deserialize
2455 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2456 // Verify
2457 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2458}
2459
Johannes Kron0854eb62018-10-10 22:33:20 +02002460TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002461 jdesc_.description()->set_extmap_allow_mixed_headers(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002462 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2463 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2464 // Deserialize
2465 JsepSessionDescription jdesc_deserialized(kDummyType);
2466 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2467 // Verify
2468 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2469}
2470
2471TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +02002472 jdesc_.description()->set_extmap_allow_mixed_headers(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002473 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2474 // Deserialize
2475 JsepSessionDescription jdesc_deserialized(kDummyType);
2476 EXPECT_TRUE(
2477 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2478 // Verify
2479 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2480}
2481
2482TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2483 cricket::MediaContentDescription* video_desc =
2484 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2485 ASSERT_TRUE(video_desc);
2486 cricket::MediaContentDescription* audio_desc =
2487 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2488 ASSERT_TRUE(audio_desc);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002489 video_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002490 cricket::MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +02002491 audio_desc->set_extmap_allow_mixed_headers(
Johannes Kron0854eb62018-10-10 22:33:20 +02002492 cricket::MediaContentDescription::kMedia);
2493
2494 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2495 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2496 &sdp_with_extmap_allow_mixed);
2497 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2498 &sdp_with_extmap_allow_mixed);
2499
2500 // Deserialize
2501 JsepSessionDescription jdesc_deserialized(kDummyType);
2502 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2503 // Verify
2504 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2505}
2506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2508 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2509
2510 std::string sdp = kSdpOneCandidate;
2511 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2512 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2513 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2514 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002515 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516
2517 // Candidate line without generation extension.
2518 sdp = kSdpOneCandidate;
2519 Replace(" generation 2", "", &sdp);
2520 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2521 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2522 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2523 Candidate expected = jcandidate_->candidate();
2524 expected.set_generation(0);
2525 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2526
honghaiza0c44ea2016-03-23 16:07:48 -07002527 // Candidate with network id and/or cost.
2528 sdp = kSdpOneCandidate;
2529 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2530 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2531 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2532 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2533 expected = jcandidate_->candidate();
2534 expected.set_network_id(2);
2535 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2536 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2537 // Add network cost
2538 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2539 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2540 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2541 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2542
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002543 sdp = kSdpTcpActiveCandidate;
2544 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2545 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002546 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002547 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2548 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2549 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002550 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2551 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002552 EXPECT_TRUE(
2553 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002554 sdp = kSdpTcpPassiveCandidate;
2555 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2556 sdp = kSdpTcpSOCandidate;
2557 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558}
2559
2560// This test verifies the deserialization of candidate-attribute
2561// as per RFC 5245. Candiate-attribute will be of the format
2562// candidate:<blah>. This format will be used when candidates
2563// are trickled.
2564TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2565 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2566
2567 std::string candidate_attribute = kRawCandidate;
2568 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2569 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2570 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2571 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2572 EXPECT_EQ(2u, jcandidate.candidate().generation());
2573
2574 // Candidate line without generation extension.
2575 candidate_attribute = kRawCandidate;
2576 Replace(" generation 2", "", &candidate_attribute);
2577 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2578 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2579 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2580 Candidate expected = jcandidate_->candidate();
2581 expected.set_generation(0);
2582 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2583
2584 // Candidate line without candidate:
2585 candidate_attribute = kRawCandidate;
2586 Replace("candidate:", "", &candidate_attribute);
2587 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2588
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002589 // Candidate line with IPV6 address.
2590 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002591
2592 // Candidate line with hostname address.
2593 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002594}
2595
2596// This test verifies that the deserialization of an invalid candidate string
2597// fails.
2598TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002599 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002600
2601 std::string candidate_attribute = kRawCandidate;
2602 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002604
2605 candidate_attribute = kSdpOneCandidate;
2606 candidate_attribute.replace(0, 1, "x");
2607 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2608
2609 candidate_attribute = kRawCandidate;
2610 candidate_attribute.append("\r\n");
2611 candidate_attribute.append(kRawCandidate);
2612 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2613
2614 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615}
2616
2617TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2618 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002619 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2621
2622 std::string sdp_with_data = kSdpString;
2623 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002624 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625
2626 // Deserialize
2627 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2628 // Verify
2629 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2630}
2631
2632TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002633 bool use_sctpmap = true;
2634 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002635 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2637
2638 std::string sdp_with_data = kSdpString;
2639 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002640 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641
lally@webrtc.org36300852015-02-24 20:19:35 +00002642 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2643 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2644 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2645
2646 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002647 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2648 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002649 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2650 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2651
2652 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002653 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2654 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2656 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2657}
2658
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002659TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002660 bool use_sctpmap = false;
2661 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002662 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002663 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2664
2665 std::string sdp_with_data = kSdpString;
2666 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002667 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002668
lally@webrtc.org36300852015-02-24 20:19:35 +00002669 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002670 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2671 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002672
lally@webrtc.org36300852015-02-24 20:19:35 +00002673 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002674 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2675 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002676 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2677 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002678
lally@webrtc.org36300852015-02-24 20:19:35 +00002679 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002680 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2681 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002682 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2683 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2684}
2685
lally69f57602015-10-08 10:15:04 -07002686TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002687 bool use_sctpmap = false;
2688 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002689 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002690 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2691
2692 std::string sdp_with_data = kSdpString;
2693 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002694 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002695
2696 // Verify with DTLS/SCTP.
2697 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2699
2700 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002701 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2702 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002703 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2704 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2705
2706 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002707 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2708 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002709 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2710 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2711}
2712
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002713// Test to check the behaviour if sctp-port is specified
2714// on the m= line and in a=sctp-port.
2715TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002716 bool use_sctpmap = true;
2717 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002718 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002719 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2720
2721 std::string sdp_with_data = kSdpString;
2722 // Append m= attributes
2723 sdp_with_data.append(kSdpSctpDataChannelString);
2724 // Append a=sctp-port attribute
2725 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002726 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002727
2728 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2729}
2730
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002731// For crbug/344475.
2732TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2733 std::string sdp_with_data = kSdpString;
2734 sdp_with_data.append(kSdpSctpDataChannelString);
2735 // Remove the "\n" at the end.
2736 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002737 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002738
2739 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2740 // No crash is a pass.
2741}
2742
Steve Anton36b29d12017-10-30 09:57:42 -07002743void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002744 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002745 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002746 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002747 DataContentDescription* dcdesc =
2748 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002749 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002750 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002751 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002752 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002753 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002754
2755 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002756 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002757 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002758}
2759
2760TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2761 bool use_sctpmap = true;
2762 AddSctpDataChannel(use_sctpmap);
2763
2764 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002765 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002766 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002767
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002768 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002769 std::string sdp_with_data = kSdpString;
2770 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002771 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2772 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2773 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002774 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002775
2776 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2777 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002778}
2779
2780TEST_F(WebRtcSdpTest,
2781 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2782 bool use_sctpmap = false;
2783 AddSctpDataChannel(use_sctpmap);
2784
Steve Antona3a92c22017-12-07 10:27:41 -08002785 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002786 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002787
2788 // We need to test the deserialized JsepSessionDescription from
2789 // kSdpSctpDataChannelStringWithSctpPort for
2790 // draft-ietf-mmusic-sctp-sdp-07
2791 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002792 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002793 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002794 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2795 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2796 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002797 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002798
2799 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2800 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002801}
2802
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002803TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002804 // We want to test that deserializing data content limits bandwidth
2805 // settings (it should never be greater than the default).
2806 // This should prevent someone from using unlimited data bandwidth through
2807 // JS and "breaking the Internet".
2808 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002809 std::string sdp_with_bandwidth = kSdpString;
2810 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002811 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002812 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002813 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002814
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002815 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2816}
2817
2818TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002819 bool use_sctpmap = true;
2820 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002821 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002822 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002823 dcd->set_bandwidth(100 * 1000);
2824 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2825
2826 std::string sdp_with_bandwidth = kSdpString;
2827 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002828 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002829 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002830 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002831
2832 // SCTP has congestion control, so we shouldn't limit the bandwidth
2833 // as we do for RTP.
2834 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002835 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2836}
2837
Yves Gerey665174f2018-06-19 15:03:05 +02002838class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2839 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002840
2841TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002842 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002843 bool encrypted = GetParam();
2844 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845}
2846
Yves Gerey665174f2018-06-19 15:03:05 +02002847TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002848 bool encrypted = GetParam();
2849 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850}
2851
Yves Gerey665174f2018-06-19 15:03:05 +02002852TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002853 bool encrypted = GetParam();
2854 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855}
2856
jbauch5869f502017-06-29 12:31:36 -07002857INSTANTIATE_TEST_CASE_P(Encrypted,
2858 WebRtcSdpExtmapTest,
2859 ::testing::Values(false, true));
2860
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002861TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002862 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002863 std::string sdp = kSdpFullString;
2864 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2865 // Deserialize
2866 SdpParseError error;
2867 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002868 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002869 EXPECT_EQ(lastline, error.line);
2870 EXPECT_EQ("Invalid SDP line.", error.description);
2871}
2872
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2874 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2875 std::string new_sdp = kSdpOneCandidate;
2876 Replace("udp", "unsupported_transport", &new_sdp);
2877 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2878 new_sdp = kSdpOneCandidate;
2879 Replace("udp", "uDP", &new_sdp);
2880 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2881 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2882 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2883 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2884}
2885
honghaiza54a0802015-12-16 18:37:23 -08002886TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002888 EXPECT_TRUE(
2889 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2891 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2892 Candidate ref_candidate = jcandidate_->candidate();
2893 ref_candidate.set_username("user_rtp");
2894 ref_candidate.set_password("password_rtp");
2895 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2896}
2897
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002898TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002899 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002900
2901 // Deserialize
2902 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2903
2904 // Verify
2905 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002906 jdesc.description()
2907 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2908 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002909 EXPECT_TRUE(audio->conference_mode());
2910
2911 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002912 jdesc.description()
2913 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2914 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002915 EXPECT_TRUE(video->conference_mode());
2916}
2917
deadbeefd45aea82017-09-16 01:24:29 -07002918TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002919 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002920
2921 // We tested deserialization already above, so just test that if we serialize
2922 // and deserialize the flag doesn't disappear.
2923 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002924 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002925 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2926
2927 // Verify.
2928 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002929 jdesc.description()
2930 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2931 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002932 EXPECT_TRUE(audio->conference_mode());
2933
2934 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002935 jdesc.description()
2936 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2937 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002938 EXPECT_TRUE(video->conference_mode());
2939}
2940
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2942 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002943 const char kSdpEmptyType[] = " =candidate";
2944 const char kSdpEqualAsPlus[] = "a+candidate";
2945 const char kSdpSpaceAfterEqual[] = "a= candidate";
2946 const char kSdpUpperType[] = "A=candidate";
2947 const char kSdpEmptyLine[] = "";
2948 const char kSdpMissingValue[] = "a=";
2949
Yves Gerey665174f2018-06-19 15:03:05 +02002950 const char kSdpBrokenFingerprint[] =
2951 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 "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 +02002953 const char kSdpExtraField[] =
2954 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 "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 +02002956 const char kSdpMissingSpace[] =
2957 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958 "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 +00002959 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002960 const char kSdpMd5[] =
2961 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002962 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963
2964 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002965 ExpectParseFailure("v=", kSdpDestroyer);
2966 ExpectParseFailure("o=", kSdpDestroyer);
2967 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002969 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970
2971 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002972 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2973 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974
2975 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002976 ExpectParseFailure("a=candidate", kSdpEmptyType);
2977 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2978 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2979 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980
2981 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2982 // because it's orthogonal to what we are replacing and hence
2983 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002984 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2985 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2986 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2987 ExpectParseFailure("a=sendrecv", kSdpMd5);
2988
2989 // Empty Line
2990 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2991 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002992}
2993
2994TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2995 // ssrc
2996 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002997 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002998 // crypto
2999 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3000 // rtpmap
3001 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3002 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3003 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3004 // candidate
3005 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3006 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3007 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3008 ExpectParseFailure("rport 2346", "rport badvalue");
3009 ExpectParseFailure("rport 2346 generation 2",
3010 "rport 2346 generation badvalue");
3011 // m line
3012 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3013 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3014
3015 // bandwidth
3016 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003017 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003018 // rtcp-fb
3019 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3020 "a=rtcp-fb:badvalue nack\r\n",
3021 "a=rtcp-fb:badvalue nack");
3022 // extmap
3023 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3024 "a=extmap:badvalue http://example.com\r\n",
3025 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026}
3027
3028TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003029 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030
3031 const char kSdpWithReorderedPlTypesString[] =
3032 "v=0\r\n"
3033 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3034 "s=-\r\n"
3035 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003036 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003037 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3038 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003039 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003040 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003041
3042 // Deserialize
3043 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3044
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003045 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003046 GetFirstAudioContentDescription(jdesc_output.description());
3047 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003049 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3050 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051 EXPECT_EQ(104, acd->codecs()[0].id);
3052}
3053
3054TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003055 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056 CodecParams params;
3057 params.max_ptime = 40;
3058 params.ptime = 30;
3059 params.min_ptime = 10;
3060 params.sprop_stereo = 1;
3061 params.stereo = 1;
3062 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003063 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003064 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003065 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003066}
3067
3068TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3069 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003070 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003072 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003073}
3074
3075TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3076 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003077 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003079 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080}
3081
3082TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003083 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084
3085 const char kSdpWithFmtpString[] =
3086 "v=0\r\n"
3087 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3088 "s=-\r\n"
3089 "t=0 0\r\n"
3090 "m=video 3457 RTP/SAVPF 120\r\n"
3091 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003092 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3093
3094 // Deserialize
3095 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003096 EXPECT_TRUE(
3097 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003098
Donald Curtis0e07f922015-05-15 09:21:23 -07003099 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003100 GetFirstVideoContentDescription(jdesc_output.description());
3101 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003102 ASSERT_FALSE(vcd->codecs().empty());
3103 cricket::VideoCodec vp8 = vcd->codecs()[0];
3104 EXPECT_EQ("VP8", vp8.name);
3105 EXPECT_EQ(120, vp8.id);
3106 cricket::CodecParameterMap::iterator found =
3107 vp8.params.find("x-google-min-bitrate");
3108 ASSERT_TRUE(found != vp8.params.end());
3109 EXPECT_EQ(found->second, "10");
3110 found = vp8.params.find("x-google-max-quantization");
3111 ASSERT_TRUE(found != vp8.params.end());
3112 EXPECT_EQ(found->second, "40");
3113}
3114
johan2d8d23e2016-06-03 01:22:42 -07003115TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003116 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003117
3118 const char kSdpWithFmtpString[] =
3119 "v=0\r\n"
3120 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3121 "s=-\r\n"
3122 "t=0 0\r\n"
3123 "m=video 49170 RTP/AVP 98\r\n"
3124 "a=rtpmap:98 H264/90000\r\n"
3125 "a=fmtp:98 profile-level-id=42A01E; "
3126 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3127
3128 // Deserialize.
3129 SdpParseError error;
3130 EXPECT_TRUE(
3131 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3132
johan2d8d23e2016-06-03 01:22:42 -07003133 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003134 GetFirstVideoContentDescription(jdesc_output.description());
3135 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003136 ASSERT_FALSE(vcd->codecs().empty());
3137 cricket::VideoCodec h264 = vcd->codecs()[0];
3138 EXPECT_EQ("H264", h264.name);
3139 EXPECT_EQ(98, h264.id);
3140 cricket::CodecParameterMap::const_iterator found =
3141 h264.params.find("profile-level-id");
3142 ASSERT_TRUE(found != h264.params.end());
3143 EXPECT_EQ(found->second, "42A01E");
3144 found = h264.params.find("sprop-parameter-sets");
3145 ASSERT_TRUE(found != h264.params.end());
3146 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3147}
3148
Donald Curtis0e07f922015-05-15 09:21:23 -07003149TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003150 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003151
3152 const char kSdpWithFmtpString[] =
3153 "v=0\r\n"
3154 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3155 "s=-\r\n"
3156 "t=0 0\r\n"
3157 "m=video 3457 RTP/SAVPF 120\r\n"
3158 "a=rtpmap:120 VP8/90000\r\n"
3159 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003160
3161 // Deserialize
3162 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003163 EXPECT_TRUE(
3164 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003165
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003167 GetFirstVideoContentDescription(jdesc_output.description());
3168 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169 ASSERT_FALSE(vcd->codecs().empty());
3170 cricket::VideoCodec vp8 = vcd->codecs()[0];
3171 EXPECT_EQ("VP8", vp8.name);
3172 EXPECT_EQ(120, vp8.id);
3173 cricket::CodecParameterMap::iterator found =
3174 vp8.params.find("x-google-min-bitrate");
3175 ASSERT_TRUE(found != vp8.params.end());
3176 EXPECT_EQ(found->second, "10");
3177 found = vp8.params.find("x-google-max-quantization");
3178 ASSERT_TRUE(found != vp8.params.end());
3179 EXPECT_EQ(found->second, "40");
3180}
3181
ossuaa4b0772017-01-30 07:41:18 -08003182TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003183 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003184
3185 cricket::AudioCodecs codecs = acd->codecs();
3186 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3187 acd->set_codecs(codecs);
3188
Yves Gerey665174f2018-06-19 15:03:05 +02003189 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003190 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003191 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003192 std::string sdp_with_fmtp = kSdpFullString;
3193 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3194 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3195 &sdp_with_fmtp);
3196 EXPECT_EQ(sdp_with_fmtp, message);
3197}
3198
3199TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003200 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003201
3202 cricket::AudioCodecs codecs = acd->codecs();
3203 codecs[0].params["stereo"] = "1";
3204 acd->set_codecs(codecs);
3205
Yves Gerey665174f2018-06-19 15:03:05 +02003206 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003207 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003208 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003209 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003210 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003211 &sdp_with_fmtp);
3212 EXPECT_EQ(sdp_with_fmtp, message);
3213}
3214
3215TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003216 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003217
3218 cricket::AudioCodecs codecs = acd->codecs();
3219 codecs[0].params["ptime"] = "20";
3220 codecs[0].params["maxptime"] = "120";
3221 acd->set_codecs(codecs);
3222
Yves Gerey665174f2018-06-19 15:03:05 +02003223 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003224 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003225 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003226 std::string sdp_with_fmtp = kSdpFullString;
3227 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3228 "a=maxptime:120\r\n" // No comma here. String merging!
3229 "a=ptime:20\r\n",
3230 &sdp_with_fmtp);
3231 EXPECT_EQ(sdp_with_fmtp, message);
3232}
3233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003235 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236
3237 cricket::VideoCodecs codecs = vcd->codecs();
3238 codecs[0].params["x-google-min-bitrate"] = "10";
3239 vcd->set_codecs(codecs);
3240
Yves Gerey665174f2018-06-19 15:03:05 +02003241 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003243 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244 std::string sdp_with_fmtp = kSdpFullString;
3245 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003246 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247 EXPECT_EQ(sdp_with_fmtp, message);
3248}
3249
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003250TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3251 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003252 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253 std::string sdp_with_icelite = kSdpFullString;
3254 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3255 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3256 const cricket::TransportInfo* tinfo1 =
3257 desc->GetTransportInfoByName("audio_content_name");
3258 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3259 const cricket::TransportInfo* tinfo2 =
3260 desc->GetTransportInfoByName("video_content_name");
3261 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003262
3263 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003264 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3266 desc = jdesc_with_icelite.description();
3267 const cricket::TransportInfo* atinfo =
3268 desc->GetTransportInfoByName("audio_content_name");
3269 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3270 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003271 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003273
3274 // Now that we know deserialization works, we can use TestSerialize to test
3275 // serialization.
3276 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277}
3278
3279// Verifies that the candidates in the input SDP are parsed and serialized
3280// correctly in the output SDP.
3281TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3282 std::string sdp_with_data = kSdpString;
3283 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003284 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285
3286 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003287 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003289
3290TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3291 AddFingerprint();
3292 TransportInfo audio_transport_info =
3293 *(desc_.GetTransportInfoByName(kAudioContentName));
3294 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3295 audio_transport_info.description.connection_role);
3296 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003297 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003298
3299 TransportInfo video_transport_info =
3300 *(desc_.GetTransportInfoByName(kVideoContentName));
3301 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3302 video_transport_info.description.connection_role);
3303 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003304 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003305
3306 desc_.RemoveTransportInfoByName(kAudioContentName);
3307 desc_.RemoveTransportInfoByName(kVideoContentName);
3308
3309 desc_.AddTransportInfo(audio_transport_info);
3310 desc_.AddTransportInfo(video_transport_info);
3311
Yves Gerey665174f2018-06-19 15:03:05 +02003312 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003313 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003314 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003315 std::string sdp_with_dtlssetup = kSdpFullString;
3316
3317 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003318 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3319 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003320 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003321 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003322 EXPECT_EQ(sdp_with_dtlssetup, message);
3323}
3324
3325TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003326 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003327 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003328 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003329 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3330 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3331 const cricket::TransportInfo* atinfo =
3332 desc->GetTransportInfoByName("audio_content_name");
3333 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3334 atinfo->description.connection_role);
3335 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003336 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003337 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3338 vtinfo->description.connection_role);
3339}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003340
3341// Verifies that the order of the serialized m-lines follows the order of the
3342// ContentInfo in SessionDescription, and vise versa for deserialization.
3343TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003344 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003345 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3346 kSdpSctpDataChannelString};
3347 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3348 cricket::MEDIA_TYPE_VIDEO,
3349 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003350
3351 // Verifies all 6 permutations.
3352 for (size_t i = 0; i < 6; ++i) {
3353 size_t media_content_in_sdp[3];
3354 // The index of the first media content.
3355 media_content_in_sdp[0] = i / 2;
3356 // The index of the second media content.
3357 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3358 // The index of the third media content.
3359 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3360
3361 std::string sdp_string = kSdpSessionString;
3362 for (size_t i = 0; i < 3; ++i)
3363 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3364
3365 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3366 cricket::SessionDescription* desc = jdesc.description();
3367 EXPECT_EQ(3u, desc->contents().size());
3368
3369 for (size_t i = 0; i < 3; ++i) {
3370 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003371 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003372 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3373 }
3374
Steve Antone831b8c2018-02-01 12:22:16 -08003375 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003376 EXPECT_EQ(sdp_string, serialized_sdp);
3377 }
3378}
deadbeef9d3584c2016-02-16 17:54:10 -08003379
deadbeef25ed4352016-12-12 18:37:36 -08003380TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3381 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003382 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003383 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003384 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3385 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3386}
3387
deadbeef12771a12017-01-03 13:53:47 -08003388// The semantics of "a=bundle-only" are only defined when it's used in
3389// combination with a 0 port on the m= line. We should ignore it if used with a
3390// nonzero port.
3391TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3392 // Make the base bundle-only description but unset the bundle-only flag.
3393 MakeBundleOnlyDescription();
3394 jdesc_.description()->contents()[1].bundle_only = false;
3395
3396 std::string modified_sdp = kBundleOnlySdpFullString;
3397 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003398 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003399 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3400 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003401}
3402
3403TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3404 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003405 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003406}
3407
deadbeef9d3584c2016-02-16 17:54:10 -08003408TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3409 MakePlanBDescription();
3410
Steve Antona3a92c22017-12-07 10:27:41 -08003411 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003412 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3413
3414 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3415}
3416
3417TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3418 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003419 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003420}
3421
3422TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3423 MakeUnifiedPlanDescription();
3424
Steve Antona3a92c22017-12-07 10:27:41 -08003425 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003426 EXPECT_TRUE(
3427 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3428
3429 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3430}
3431
3432TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3433 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003434 TestSerialize(jdesc_);
3435}
3436
Seth Hampson5b4f0752018-04-02 16:31:36 -07003437// This tests deserializing a Unified Plan SDP that is compatible with both
3438// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3439// with no stream ids and multiple stream ids. For parsing this, the Unified
3440// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3441// lines do not support multiple stream ids and no stream ids.
3442TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3443 MakeUnifiedPlanDescriptionMultipleStreamIds();
3444
3445 JsepSessionDescription deserialized_description(kDummyType);
3446 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3447 &deserialized_description));
3448
3449 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3450}
3451
3452TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3453 MakeUnifiedPlanDescriptionMultipleStreamIds();
3454 TestSerialize(jdesc_);
3455}
3456
Seth Hampson5897a6e2018-04-03 11:16:33 -07003457// This tests that a Unified Plan SDP with no a=ssrc lines is
3458// serialized/deserialized appropriately. In this case the
3459// MediaContentDescription will contain a StreamParams object that doesn't have
3460// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3461// SSRC lines.
3462TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3463 MakeUnifiedPlanDescription();
3464 RemoveSsrcSignalingFromStreamParams();
3465 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3466 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3467
3468 JsepSessionDescription deserialized_description(kDummyType);
3469 EXPECT_TRUE(
3470 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3471 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3472}
3473
3474TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3475 MakeUnifiedPlanDescription();
3476 RemoveSsrcSignalingFromStreamParams();
3477
3478 TestSerialize(jdesc_);
3479}
3480
Steve Antone831b8c2018-02-01 12:22:16 -08003481TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3482 JsepSessionDescription jsep_desc(kDummyType);
3483 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3484 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3485}
3486
3487TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3488 JsepSessionDescription jsep_desc(kDummyType);
3489 std::string sdp = kSdpSessionString;
3490 sdp += kSdpSctpDataChannelString;
3491 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3492 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3493}
3494
3495TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3496 JsepSessionDescription jsep_desc(kDummyType);
3497 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3498 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3499 jsep_desc.description()->msid_signaling());
3500}
3501
3502TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3503 JsepSessionDescription jsep_desc(kDummyType);
3504 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3505 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3506 jsep_desc.description()->msid_signaling());
3507}
3508
3509const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3510const char kSsrcAttributeMsidLine[] =
3511 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3512
3513TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3514 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3515 std::string sdp = webrtc::SdpSerialize(jdesc_);
3516
3517 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3518 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3519}
3520
3521TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3522 jdesc_.description()->set_msid_signaling(
3523 cricket::kMsidSignalingSsrcAttribute);
3524 std::string sdp = webrtc::SdpSerialize(jdesc_);
3525
3526 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3527 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3528}
3529
3530TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3531 jdesc_.description()->set_msid_signaling(
3532 cricket::kMsidSignalingMediaSection |
3533 cricket::kMsidSignalingSsrcAttribute);
3534 std::string sdp = webrtc::SdpSerialize(jdesc_);
3535
3536 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3537 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003538}
deadbeef7e146cb2016-09-28 10:04:34 -07003539
3540// Regression test for heap overflow bug:
3541// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3542TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003543 // The issue occurs when the sctp-port attribute is found in a video
3544 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003545 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003546 "v=0\r\n"
3547 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3548 "s=-\r\n"
3549 "t=0 0\r\n"
3550 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3551 "a=sctp-port 5000\r\n"
3552 "a=fmtp:108 foo=10\r\n";
3553
3554 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3555 "sctp-port");
3556}
deadbeefb2362572016-12-13 16:37:06 -08003557
3558// Regression test for integer overflow bug:
3559// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3560TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003561 // Bandwidth attribute is the max signed 32-bit int, which will get
3562 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003563 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003564 "v=0\r\n"
3565 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3566 "s=-\r\n"
3567 "t=0 0\r\n"
3568 "m=video 3457 RTP/SAVPF 120\r\n"
3569 "b=AS:2147483647\r\n"
3570 "foo=fail\r\n";
3571
3572 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3573}
deadbeef7bcdb692017-01-20 12:43:58 -08003574
deadbeefbc88c6b2017-08-02 11:26:34 -07003575// Similar to the above, except that negative values are illegal, not just
3576// error-prone as large values are.
3577// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3578TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3579 static const char kSdpWithNegativeBandwidth[] =
3580 "v=0\r\n"
3581 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3582 "s=-\r\n"
3583 "t=0 0\r\n"
3584 "m=video 3457 RTP/SAVPF 120\r\n"
3585 "b=AS:-1000\r\n";
3586
3587 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3588}
3589
deadbeef3e8016e2017-08-03 17:49:30 -07003590// An exception to the above rule: a value of -1 for b=AS should just be
3591// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3592// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3593// limit", but this is now what ommitting the attribute entirely will do, so
3594// ignoring it will have the intended effect.
3595TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3596 static const char kSdpWithBandwidthOfNegativeOne[] =
3597 "v=0\r\n"
3598 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3599 "s=-\r\n"
3600 "t=0 0\r\n"
3601 "m=video 3457 RTP/SAVPF 120\r\n"
3602 "b=AS:-1\r\n";
3603
Steve Antona3a92c22017-12-07 10:27:41 -08003604 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003605 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003606 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003607 GetFirstVideoContentDescription(jdesc_output.description());
3608 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003609 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3610}
3611
deadbeef7bcdb692017-01-20 12:43:58 -08003612// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3613// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3614// Regression test for:
3615// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3616TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3617 // Important piece is "ufrag foo pwd bar".
3618 static const char kSdpWithIceCredentialsInCandidateString[] =
3619 "v=0\r\n"
3620 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3621 "s=-\r\n"
3622 "t=0 0\r\n"
3623 "m=audio 9 RTP/SAVPF 111\r\n"
3624 "c=IN IP4 0.0.0.0\r\n"
3625 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3626 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3627 "a=rtpmap:111 opus/48000/2\r\n"
3628 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3629 "generation 2 ufrag foo pwd bar\r\n";
3630
Steve Antona3a92c22017-12-07 10:27:41 -08003631 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003632 EXPECT_TRUE(
3633 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3634 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3635 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003636 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003637 cricket::Candidate c = candidates->at(0)->candidate();
3638 EXPECT_EQ("ufrag_voice", c.username());
3639 EXPECT_EQ("pwd_voice", c.password());
3640}
deadbeef90f1e1e2017-02-10 12:35:05 -08003641
Johannes Kron211856b2018-09-06 12:12:28 +02003642// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3643// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3644// Regression test for:
3645// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3646TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3647 static const char kSdpWithFooIceCredentials[] =
3648 "v=0\r\n"
3649 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3650 "s=-\r\n"
3651 "t=0 0\r\n"
3652 "m=audio 9 RTP/SAVPF 111\r\n"
3653 "c=IN IP4 0.0.0.0\r\n"
3654 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3655 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3656 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3657 "a=rtpmap:111 opus/48000/2\r\n"
3658 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3659 "generation 2\r\n";
3660
3661 JsepSessionDescription jdesc_output(kDummyType);
3662 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3663 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3664 ASSERT_NE(nullptr, candidates);
3665 ASSERT_EQ(1U, candidates->count());
3666 cricket::Candidate c = candidates->at(0)->candidate();
3667 EXPECT_EQ("ufrag_voice", c.username());
3668 EXPECT_EQ("pwd_voice", c.password());
3669}
3670
deadbeef90f1e1e2017-02-10 12:35:05 -08003671// Test that SDP with an invalid port number in "a=candidate" lines is
3672// rejected, without crashing.
3673// Regression test for:
3674// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3675TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3676 static const char kSdpWithInvalidCandidatePort[] =
3677 "v=0\r\n"
3678 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3679 "s=-\r\n"
3680 "t=0 0\r\n"
3681 "m=audio 9 RTP/SAVPF 111\r\n"
3682 "c=IN IP4 0.0.0.0\r\n"
3683 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3684 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3685 "a=rtpmap:111 opus/48000/2\r\n"
3686 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3687 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3688
Steve Antona3a92c22017-12-07 10:27:41 -08003689 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003690 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3691}
deadbeefa4549d62017-02-10 17:26:22 -08003692
3693// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3694// Regression test for:
3695// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3696TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3697 static const char kSdpWithMissingTrackId[] =
3698 "v=0\r\n"
3699 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3700 "s=-\r\n"
3701 "t=0 0\r\n"
3702 "m=audio 9 RTP/SAVPF 111\r\n"
3703 "c=IN IP4 0.0.0.0\r\n"
3704 "a=rtpmap:111 opus/48000/2\r\n"
3705 "a=msid:stream_id \r\n";
3706
Steve Antona3a92c22017-12-07 10:27:41 -08003707 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003708 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3709}
3710
3711TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3712 static const char kSdpWithMissingStreamId[] =
3713 "v=0\r\n"
3714 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3715 "s=-\r\n"
3716 "t=0 0\r\n"
3717 "m=audio 9 RTP/SAVPF 111\r\n"
3718 "c=IN IP4 0.0.0.0\r\n"
3719 "a=rtpmap:111 opus/48000/2\r\n"
3720 "a=msid: track_id\r\n";
3721
Steve Antona3a92c22017-12-07 10:27:41 -08003722 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003723 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3724}
zhihuang38989e52017-03-21 11:04:53 -07003725
3726// Tests that if both session-level address and media-level address exist, use
3727// the media-level address.
3728TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003729 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003730
3731 // Sesssion-level address.
3732 std::string sdp = kSdpFullString;
3733 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3734 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3735
3736 const auto& content1 = jsep_desc.description()->contents()[0];
3737 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003738 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003739 const auto& content2 = jsep_desc.description()->contents()[1];
3740 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003741 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003742}
3743
3744// Tests that the session-level connection address will be used if the media
3745// level-addresses are not specified.
3746TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003747 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003748
3749 // Sesssion-level address.
3750 std::string sdp = kSdpString;
3751 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3752 // Remove the media level addresses.
3753 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3754 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3755 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3756
3757 const auto& content1 = jsep_desc.description()->contents()[0];
3758 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003759 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003760 const auto& content2 = jsep_desc.description()->contents()[1];
3761 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003762 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003763}
3764
3765TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003766 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003767
3768 std::string sdp = kSdpString;
3769 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3770 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3771 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3772 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3773 &sdp);
3774 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3775 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3776 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3777 &sdp);
3778 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3779 const auto& content1 = jsep_desc.description()->contents()[0];
3780 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003781 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003782 const auto& content2 = jsep_desc.description()->contents()[1];
3783 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003784 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003785}
3786
3787// Test that the invalid or unsupprted connection data cannot be parsed.
3788TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003789 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003790 std::string sdp = kSdpString;
3791 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3792
3793 // Unsupported multicast IPv4 address.
3794 sdp = kSdpFullString;
3795 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3796 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3797
3798 // Unsupported multicast IPv6 address.
3799 sdp = kSdpFullString;
3800 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3801 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3802
3803 // Mismatched address type.
3804 sdp = kSdpFullString;
3805 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3806 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3807
3808 sdp = kSdpFullString;
3809 Replace("c=IN IP4 74.125.224.39\r\n",
3810 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3811 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3812}
3813
3814TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003815 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003816 MakeDescriptionWithoutCandidates(&expected_jsep);
3817 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003818 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003819 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003820 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003821 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003822 auto audio_desc = jdesc.description()
3823 ->GetContentByName(kAudioContentName)
3824 ->media_description();
3825 auto video_desc = jdesc.description()
3826 ->GetContentByName(kVideoContentName)
3827 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003828 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3829 audio_desc->connection_address().ToString());
3830 EXPECT_EQ(video_desc_->connection_address().ToString(),
3831 video_desc->connection_address().ToString());
3832}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003833
3834// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3835// used (i.e., a single space as the session name)." So we should accept that.
3836TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3837 JsepSessionDescription jsep_desc(kDummyType);
3838 std::string sdp = kSdpString;
3839 Replace("s=-\r\n", "s= \r\n", &sdp);
3840 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3841}