blob: 9c1055463153be712254a0342127a80046ef66ee [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/stringencode.h"
26#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020027
ossu7bb87ee2017-01-23 04:56:25 -080028#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080030#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33using cricket::AudioCodec;
34using cricket::AudioContentDescription;
35using cricket::Candidate;
36using cricket::ContentInfo;
37using cricket::CryptoParams;
38using cricket::ContentGroup;
39using cricket::DataCodec;
40using cricket::DataContentDescription;
41using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
42using cricket::ICE_CANDIDATE_COMPONENT_RTP;
43using cricket::kFecSsrcGroupSemantics;
44using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045using cricket::RELAY_PORT_TYPE;
46using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080047using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070058using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080059using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080061using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::SessionDescriptionInterface;
63
64typedef std::vector<AudioCodec> AudioCodecs;
65typedef std::vector<Candidate> Candidates;
66
Peter Boström0c4e06b2015-10-07 12:23:21 +020067static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080068static const char kDefaultSctpPortStr[] = "5000";
69static const uint16_t kUnusualSctpPort = 9556;
70static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020072static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080073static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080075static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020077static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078static const char kCandidateFoundation1[] = "a0+B/1";
79static const char kCandidateFoundation2[] = "a0+B/2";
80static const char kCandidateFoundation3[] = "a0+B/3";
81static const char kCandidateFoundation4[] = "a0+B/4";
82static const char kAttributeCryptoVoice[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
84 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
85 "dummy_session_params\r\n";
86static const char kAttributeCryptoVideo[] =
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020089static const char kFingerprint[] =
90 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
92static const int kExtmapId = 1;
93static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
94static const char kExtmap[] =
95 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
96static const char kExtmapWithDirectionAndAttribute[] =
97 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -070098static const char kExtmapWithDirectionAndAttributeEncrypted[] =
99 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
100 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint8_t kIdentityDigest[] = {
103 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
104 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
lally@webrtc.org34807282015-02-24 20:19:39 +0000106static const char kDtlsSctp[] = "DTLS/SCTP";
107static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
108static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000109
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110struct CodecParams {
111 int max_ptime;
112 int ptime;
113 int min_ptime;
114 int sprop_stereo;
115 int stereo;
116 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000117 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118};
119
deadbeef9d3584c2016-02-16 17:54:10 -0800120// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
121// instead of "a=crypto", and have an explicit test for adding "a=crypto".
122// Currently it's the other way around.
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Reference sdp string
125static const char kSdpFullString[] =
126 "v=0\r\n"
127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
128 "s=-\r\n"
129 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800130 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
132 "c=IN IP4 74.125.127.126\r\n"
133 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
134 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
135 "generation 2\r\n"
136 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
139 "generation 2\r\n"
140 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
141 "generation 2\r\n"
142 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
143 "raddr 192.168.1.5 rport 2346 "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
146 "raddr 192.168.1.5 rport 2348 "
147 "generation 2\r\n"
148 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
149 "a=mid:audio_content_name\r\n"
150 "a=sendrecv\r\n"
151 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800152 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
154 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
155 "dummy_session_params\r\n"
156 "a=rtpmap:111 opus/48000/2\r\n"
157 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000158 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 "a=ssrc:1 cname:stream_1_cname\r\n"
160 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
161 "a=ssrc:1 mslabel:local_stream_1\r\n"
162 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 "m=video 3457 RTP/SAVPF 120\r\n"
164 "c=IN IP4 74.125.224.39\r\n"
165 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
166 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
171 "generation 2\r\n"
172 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
175 "generation 2\r\n"
176 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
177 "generation 2\r\n"
178 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
179 "a=mid:video_content_name\r\n"
180 "a=sendrecv\r\n"
181 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
182 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
183 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800184 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 "a=ssrc:2 cname:stream_1_cname\r\n"
186 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
187 "a=ssrc:2 mslabel:local_stream_1\r\n"
188 "a=ssrc:2 label:video_track_id_1\r\n"
189 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800190 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193
194// SDP reference string without the candidates.
195static const char kSdpString[] =
196 "v=0\r\n"
197 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
198 "s=-\r\n"
199 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800200 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000201 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000202 "c=IN IP4 0.0.0.0\r\n"
203 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
205 "a=mid:audio_content_name\r\n"
206 "a=sendrecv\r\n"
207 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800208 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
210 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
211 "dummy_session_params\r\n"
212 "a=rtpmap:111 opus/48000/2\r\n"
213 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000214 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 "a=ssrc:1 cname:stream_1_cname\r\n"
216 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
217 "a=ssrc:1 mslabel:local_stream_1\r\n"
218 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000219 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000220 "c=IN IP4 0.0.0.0\r\n"
221 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
223 "a=mid:video_content_name\r\n"
224 "a=sendrecv\r\n"
225 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
226 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
227 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800228 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 "a=ssrc:2 cname:stream_1_cname\r\n"
230 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
231 "a=ssrc:2 mslabel:local_stream_1\r\n"
232 "a=ssrc:2 label:video_track_id_1\r\n"
233 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800234 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800236 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237
238static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000239 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000240 "c=IN IP4 0.0.0.0\r\n"
241 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 "a=ice-ufrag:ufrag_data\r\n"
243 "a=ice-pwd:pwd_data\r\n"
244 "a=mid:data_content_name\r\n"
245 "a=sendrecv\r\n"
246 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
247 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
248 "a=rtpmap:101 google-data/90000\r\n"
249 "a=ssrc:10 cname:data_channel_cname\r\n"
250 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
251 "a=ssrc:10 mslabel:data_channel\r\n"
252 "a=ssrc:10 label:data_channeld0\r\n";
253
254static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000255 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000256 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 "a=ice-ufrag:ufrag_data\r\n"
258 "a=ice-pwd:pwd_data\r\n"
259 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000260 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000262// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000263static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000264 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
265 "a=max-message-size=100000\r\n"
266 "a=sctp-port 5000\r\n"
267 "c=IN IP4 0.0.0.0\r\n"
268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n";
271
lally69f57602015-10-08 10:15:04 -0700272static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
273 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
274 "a=max-message-size=100000\r\n"
275 "a=sctp-port:5000\r\n"
276 "c=IN IP4 0.0.0.0\r\n"
277 "a=ice-ufrag:ufrag_data\r\n"
278 "a=ice-pwd:pwd_data\r\n"
279 "a=mid:data_content_name\r\n";
280
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281static const char kSdpSctpDataChannelWithCandidatesString[] =
282 "m=application 2345 DTLS/SCTP 5000\r\n"
283 "c=IN IP4 74.125.127.126\r\n"
284 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
285 "generation 2\r\n"
286 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
287 "generation 2\r\n"
288 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
289 "raddr 192.168.1.5 rport 2346 "
290 "generation 2\r\n"
291 "a=ice-ufrag:ufrag_data\r\n"
292 "a=ice-pwd:pwd_data\r\n"
293 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000294 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000296static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000297 "v=0\r\n"
298 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
299 "s=-\r\n"
300 "t=0 0\r\n"
301 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000302 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000303 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000304 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000305 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000306 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000307 "a=x-google-flag:conference\r\n";
308
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000309static const char kSdpSessionString[] =
310 "v=0\r\n"
311 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
312 "s=-\r\n"
313 "t=0 0\r\n"
314 "a=msid-semantic: WMS local_stream\r\n";
315
316static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000317 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000318 "c=IN IP4 0.0.0.0\r\n"
319 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000320 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
321 "a=mid:audio_content_name\r\n"
322 "a=sendrecv\r\n"
323 "a=rtpmap:111 opus/48000/2\r\n"
324 "a=ssrc:1 cname:stream_1_cname\r\n"
325 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
326 "a=ssrc:1 mslabel:local_stream\r\n"
327 "a=ssrc:1 label:audio_track_id_1\r\n";
328
329static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000330 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000331 "c=IN IP4 0.0.0.0\r\n"
332 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000333 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
334 "a=mid:video_content_name\r\n"
335 "a=sendrecv\r\n"
336 "a=rtpmap:120 VP8/90000\r\n"
337 "a=ssrc:2 cname:stream_1_cname\r\n"
338 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
339 "a=ssrc:2 mslabel:local_stream\r\n"
340 "a=ssrc:2 label:video_track_id_1\r\n";
341
deadbeef25ed4352016-12-12 18:37:36 -0800342// Reference sdp string using bundle-only.
343static const char kBundleOnlySdpFullString[] =
344 "v=0\r\n"
345 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
346 "s=-\r\n"
347 "t=0 0\r\n"
348 "a=group:BUNDLE audio_content_name video_content_name\r\n"
349 "a=msid-semantic: WMS local_stream_1\r\n"
350 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
351 "c=IN IP4 74.125.127.126\r\n"
352 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
353 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
354 "generation 2\r\n"
355 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
358 "generation 2\r\n"
359 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
360 "generation 2\r\n"
361 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
362 "raddr 192.168.1.5 rport 2346 "
363 "generation 2\r\n"
364 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
365 "raddr 192.168.1.5 rport 2348 "
366 "generation 2\r\n"
367 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
368 "a=mid:audio_content_name\r\n"
369 "a=sendrecv\r\n"
370 "a=rtcp-mux\r\n"
371 "a=rtcp-rsize\r\n"
372 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
373 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
374 "dummy_session_params\r\n"
375 "a=rtpmap:111 opus/48000/2\r\n"
376 "a=rtpmap:103 ISAC/16000\r\n"
377 "a=rtpmap:104 ISAC/32000\r\n"
378 "a=ssrc:1 cname:stream_1_cname\r\n"
379 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
380 "a=ssrc:1 mslabel:local_stream_1\r\n"
381 "a=ssrc:1 label:audio_track_id_1\r\n"
382 "m=video 0 RTP/SAVPF 120\r\n"
383 "c=IN IP4 0.0.0.0\r\n"
384 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
385 "a=bundle-only\r\n"
386 "a=mid:video_content_name\r\n"
387 "a=sendrecv\r\n"
388 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
389 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
390 "a=rtpmap:120 VP8/90000\r\n"
391 "a=ssrc-group:FEC 2 3\r\n"
392 "a=ssrc:2 cname:stream_1_cname\r\n"
393 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
394 "a=ssrc:2 mslabel:local_stream_1\r\n"
395 "a=ssrc:2 label:video_track_id_1\r\n"
396 "a=ssrc:3 cname:stream_1_cname\r\n"
397 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
398 "a=ssrc:3 mslabel:local_stream_1\r\n"
399 "a=ssrc:3 label:video_track_id_1\r\n";
400
deadbeef9d3584c2016-02-16 17:54:10 -0800401// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
402// tracks.
403static const char kPlanBSdpFullString[] =
404 "v=0\r\n"
405 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
406 "s=-\r\n"
407 "t=0 0\r\n"
408 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
409 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
410 "c=IN IP4 74.125.127.126\r\n"
411 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
412 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
413 "generation 2\r\n"
414 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
417 "generation 2\r\n"
418 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
419 "generation 2\r\n"
420 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
421 "raddr 192.168.1.5 rport 2346 "
422 "generation 2\r\n"
423 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
424 "raddr 192.168.1.5 rport 2348 "
425 "generation 2\r\n"
426 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
427 "a=mid:audio_content_name\r\n"
428 "a=sendrecv\r\n"
429 "a=rtcp-mux\r\n"
430 "a=rtcp-rsize\r\n"
431 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
432 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
433 "dummy_session_params\r\n"
434 "a=rtpmap:111 opus/48000/2\r\n"
435 "a=rtpmap:103 ISAC/16000\r\n"
436 "a=rtpmap:104 ISAC/32000\r\n"
437 "a=ssrc:1 cname:stream_1_cname\r\n"
438 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
439 "a=ssrc:1 mslabel:local_stream_1\r\n"
440 "a=ssrc:1 label:audio_track_id_1\r\n"
441 "a=ssrc:4 cname:stream_2_cname\r\n"
442 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
443 "a=ssrc:4 mslabel:local_stream_2\r\n"
444 "a=ssrc:4 label:audio_track_id_2\r\n"
445 "m=video 3457 RTP/SAVPF 120\r\n"
446 "c=IN IP4 74.125.224.39\r\n"
447 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
448 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
453 "generation 2\r\n"
454 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
455 "generation 2\r\n"
456 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
457 "generation 2\r\n"
458 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
459 "generation 2\r\n"
460 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
461 "a=mid:video_content_name\r\n"
462 "a=sendrecv\r\n"
463 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
464 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
465 "a=rtpmap:120 VP8/90000\r\n"
466 "a=ssrc-group:FEC 2 3\r\n"
467 "a=ssrc:2 cname:stream_1_cname\r\n"
468 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
469 "a=ssrc:2 mslabel:local_stream_1\r\n"
470 "a=ssrc:2 label:video_track_id_1\r\n"
471 "a=ssrc:3 cname:stream_1_cname\r\n"
472 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
473 "a=ssrc:3 mslabel:local_stream_1\r\n"
474 "a=ssrc:3 label:video_track_id_1\r\n"
475 "a=ssrc:5 cname:stream_2_cname\r\n"
476 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
477 "a=ssrc:5 mslabel:local_stream_2\r\n"
478 "a=ssrc:5 label:video_track_id_2\r\n"
479 "a=ssrc:6 cname:stream_2_cname\r\n"
480 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
481 "a=ssrc:6 mslabel:local_stream_2\r\n"
482 "a=ssrc:6 label:video_track_id_3\r\n";
483
484// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
485// tracks.
486static const char kUnifiedPlanSdpFullString[] =
487 "v=0\r\n"
488 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
489 "s=-\r\n"
490 "t=0 0\r\n"
491 "a=msid-semantic: WMS local_stream_1\r\n"
492 // Audio track 1, stream 1 (with candidates).
493 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
494 "c=IN IP4 74.125.127.126\r\n"
495 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
496 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
497 "generation 2\r\n"
498 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
503 "generation 2\r\n"
504 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
505 "raddr 192.168.1.5 rport 2346 "
506 "generation 2\r\n"
507 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
508 "raddr 192.168.1.5 rport 2348 "
509 "generation 2\r\n"
510 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
511 "a=mid:audio_content_name\r\n"
512 "a=msid:local_stream_1 audio_track_id_1\r\n"
513 "a=sendrecv\r\n"
514 "a=rtcp-mux\r\n"
515 "a=rtcp-rsize\r\n"
516 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
517 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
518 "dummy_session_params\r\n"
519 "a=rtpmap:111 opus/48000/2\r\n"
520 "a=rtpmap:103 ISAC/16000\r\n"
521 "a=rtpmap:104 ISAC/32000\r\n"
522 "a=ssrc:1 cname:stream_1_cname\r\n"
523 // Video track 1, stream 1 (with candidates).
524 "m=video 3457 RTP/SAVPF 120\r\n"
525 "c=IN IP4 74.125.224.39\r\n"
526 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
527 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
528 "generation 2\r\n"
529 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
538 "generation 2\r\n"
539 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
540 "a=mid:video_content_name\r\n"
541 "a=msid:local_stream_1 video_track_id_1\r\n"
542 "a=sendrecv\r\n"
543 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
544 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
545 "a=rtpmap:120 VP8/90000\r\n"
546 "a=ssrc-group:FEC 2 3\r\n"
547 "a=ssrc:2 cname:stream_1_cname\r\n"
548 "a=ssrc:3 cname:stream_1_cname\r\n"
549 // Audio track 2, stream 2.
550 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
551 "c=IN IP4 0.0.0.0\r\n"
552 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
553 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
554 "a=mid:audio_content_name_2\r\n"
555 "a=msid:local_stream_2 audio_track_id_2\r\n"
556 "a=sendrecv\r\n"
557 "a=rtcp-mux\r\n"
558 "a=rtcp-rsize\r\n"
559 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
560 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
561 "dummy_session_params\r\n"
562 "a=rtpmap:111 opus/48000/2\r\n"
563 "a=rtpmap:103 ISAC/16000\r\n"
564 "a=rtpmap:104 ISAC/32000\r\n"
565 "a=ssrc:4 cname:stream_2_cname\r\n"
566 // Video track 2, stream 2.
567 "m=video 9 RTP/SAVPF 120\r\n"
568 "c=IN IP4 0.0.0.0\r\n"
569 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
570 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
571 "a=mid:video_content_name_2\r\n"
572 "a=msid:local_stream_2 video_track_id_2\r\n"
573 "a=sendrecv\r\n"
574 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
575 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
576 "a=rtpmap:120 VP8/90000\r\n"
577 "a=ssrc:5 cname:stream_2_cname\r\n"
578 // Video track 3, stream 2.
579 "m=video 9 RTP/SAVPF 120\r\n"
580 "c=IN IP4 0.0.0.0\r\n"
581 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
582 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
583 "a=mid:video_content_name_3\r\n"
584 "a=msid:local_stream_2 video_track_id_3\r\n"
585 "a=sendrecv\r\n"
586 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
587 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
588 "a=rtpmap:120 VP8/90000\r\n"
589 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590
Seth Hampson5b4f0752018-04-02 16:31:36 -0700591// Unified Plan SDP reference string:
592// - audio track 1 has 1 a=msid lines
593// - audio track 2 has 2 a=msid lines
594// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
595// there are 0 media stream ids.
596// This Unified Plan SDP represents a SDP that signals the msid using both
597// a=msid and a=ssrc msid semantics.
598static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
599 "v=0\r\n"
600 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
601 "s=-\r\n"
602 "t=0 0\r\n"
603 "a=msid-semantic: WMS local_stream_1\r\n"
604 // Audio track 1, with 1 stream id.
605 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
606 "c=IN IP4 74.125.127.126\r\n"
607 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
608 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
609 "generation 2\r\n"
610 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
617 "raddr 192.168.1.5 rport 2346 "
618 "generation 2\r\n"
619 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
620 "raddr 192.168.1.5 rport 2348 "
621 "generation 2\r\n"
622 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
623 "a=mid:audio_content_name\r\n"
624 "a=msid:local_stream_1 audio_track_id_1\r\n"
625 "a=sendrecv\r\n"
626 "a=rtcp-mux\r\n"
627 "a=rtcp-rsize\r\n"
628 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
629 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
630 "dummy_session_params\r\n"
631 "a=rtpmap:111 opus/48000/2\r\n"
632 "a=rtpmap:103 ISAC/16000\r\n"
633 "a=rtpmap:104 ISAC/32000\r\n"
634 "a=ssrc:1 cname:stream_1_cname\r\n"
635 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
636 "a=ssrc:1 mslabel:local_stream_1\r\n"
637 "a=ssrc:1 label:audio_track_id_1\r\n"
638 // Audio track 2, with two stream ids.
639 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
640 "c=IN IP4 0.0.0.0\r\n"
641 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
642 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
643 "a=mid:audio_content_name_2\r\n"
644 "a=msid:local_stream_1 audio_track_id_2\r\n"
645 "a=msid:local_stream_2 audio_track_id_2\r\n"
646 "a=sendrecv\r\n"
647 "a=rtcp-mux\r\n"
648 "a=rtcp-rsize\r\n"
649 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
650 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
651 "dummy_session_params\r\n"
652 "a=rtpmap:111 opus/48000/2\r\n"
653 "a=rtpmap:103 ISAC/16000\r\n"
654 "a=rtpmap:104 ISAC/32000\r\n"
655 "a=ssrc:4 cname:stream_1_cname\r\n"
656 // The support for Plan B msid signaling only includes the
657 // first media stream id "local_stream_1."
658 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
659 "a=ssrc:4 mslabel:local_stream_1\r\n"
660 "a=ssrc:4 label:audio_track_id_2\r\n"
661 // Audio track 3, with no stream ids.
662 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
663 "c=IN IP4 0.0.0.0\r\n"
664 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
665 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
666 "a=mid:audio_content_name_3\r\n"
667 "a=msid:- audio_track_id_3\r\n"
668 "a=sendrecv\r\n"
669 "a=rtcp-mux\r\n"
670 "a=rtcp-rsize\r\n"
671 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
672 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
673 "dummy_session_params\r\n"
674 "a=rtpmap:111 opus/48000/2\r\n"
675 "a=rtpmap:103 ISAC/16000\r\n"
676 "a=rtpmap:104 ISAC/32000\r\n"
677 "a=ssrc:7 cname:stream_2_cname\r\n";
678
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679// One candidate reference string as per W3c spec.
680// candidate:<blah> not a=candidate:<blah>CRLF
681static const char kRawCandidate[] =
682 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
683// One candidate reference string.
684static const char kSdpOneCandidate[] =
685 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
686 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000687
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000688static const char kSdpTcpActiveCandidate[] =
689 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
690 "tcptype active generation 2";
691static const char kSdpTcpPassiveCandidate[] =
692 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
693 "tcptype passive generation 2";
694static const char kSdpTcpSOCandidate[] =
695 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
696 "tcptype so generation 2";
697static const char kSdpTcpInvalidCandidate[] =
698 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
699 "tcptype invalid generation 2";
700
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000701// One candidate reference string with IPV6 address.
702static const char kRawIPV6Candidate[] =
703 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700704 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
706// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800707static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800709 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710
Zach Steinb336c272018-08-09 01:16:13 -0700711static const char kRawHostnameCandidate[] =
712 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
713
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714// Session id and version
715static const char kSessionId[] = "18446744069414584320";
716static const char kSessionVersion[] = "18446462598732840960";
717
deadbeef9d3584c2016-02-16 17:54:10 -0800718// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719static const char kIceOption1[] = "iceoption1";
720static const char kIceOption2[] = "iceoption2";
721static const char kIceOption3[] = "iceoption3";
722
deadbeef9d3584c2016-02-16 17:54:10 -0800723// ICE ufrags/passwords.
724static const char kUfragVoice[] = "ufrag_voice";
725static const char kPwdVoice[] = "pwd_voice";
726static const char kUfragVideo[] = "ufrag_video";
727static const char kPwdVideo[] = "pwd_video";
728static const char kUfragData[] = "ufrag_data";
729static const char kPwdData[] = "pwd_data";
730
731// Extra ufrags/passwords for extra unified plan m= sections.
732static const char kUfragVoice2[] = "ufrag_voice_2";
733static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700734static const char kUfragVoice3[] = "ufrag_voice_3";
735static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800736static const char kUfragVideo2[] = "ufrag_video_2";
737static const char kPwdVideo2[] = "pwd_video_2";
738static const char kUfragVideo3[] = "ufrag_video_3";
739static const char kPwdVideo3[] = "pwd_video_3";
740
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741// Content name
742static const char kAudioContentName[] = "audio_content_name";
743static const char kVideoContentName[] = "video_content_name";
744static const char kDataContentName[] = "data_content_name";
745
deadbeef9d3584c2016-02-16 17:54:10 -0800746// Extra content names for extra unified plan m= sections.
747static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700748static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800749static const char kVideoContentName2[] = "video_content_name_2";
750static const char kVideoContentName3[] = "video_content_name_3";
751
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800753static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754static const char kStream1Cname[] = "stream_1_cname";
755static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200756static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800758static const uint32_t kVideoTrack1Ssrc1 = 2;
759static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760
761// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800762static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763static const char kStream2Cname[] = "stream_2_cname";
764static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200765static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800766static const char kVideoTrackId2[] = "video_track_id_2";
767static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800769static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700770static const char kAudioTrackId3[] = "audio_track_id_3";
771static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772
773// DataChannel
774static const char kDataChannelLabel[] = "data_channel";
775static const char kDataChannelMsid[] = "data_channeld0";
776static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200777static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778
779// Candidate
780static const char kDummyMid[] = "dummy_mid";
781static const int kDummyIndex = 123;
782
783// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800784static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785
786// Helper functions
787
788static bool SdpDeserialize(const std::string& message,
789 JsepSessionDescription* jdesc) {
790 return webrtc::SdpDeserialize(message, jdesc, NULL);
791}
792
793static bool SdpDeserializeCandidate(const std::string& message,
794 JsepIceCandidate* candidate) {
795 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
796}
797
798// Add some extra |newlines| to the |message| after |line|.
799static void InjectAfter(const std::string& line,
800 const std::string& newlines,
801 std::string* message) {
802 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200803 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
804 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805}
806
807static void Replace(const std::string& line,
808 const std::string& newlines,
809 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200810 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
811 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812}
813
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000814// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
815// message.
816static void ExpectParseFailure(const std::string& bad_sdp,
817 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800818 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000820 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000822 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
823}
824
825// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
826static void ExpectParseFailure(const char* good_part, const char* bad_part) {
827 std::string bad_sdp = kSdpFullString;
828 Replace(good_part, bad_part, &bad_sdp);
829 ExpectParseFailure(bad_sdp, bad_part);
830}
831
832// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
833static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
834 const std::string& newlines,
835 const std::string& bad_part) {
836 std::string bad_sdp = kSdpFullString;
837 InjectAfter(injectpoint, newlines, &bad_sdp);
838 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839}
840
Steve Anton4e70a722017-11-28 14:57:10 -0800841static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 std::string* message) {
843 std::string new_direction;
844 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800845 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 new_direction = "a=inactive";
847 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800848 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 new_direction = "a=sendonly";
850 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800851 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 new_direction = "a=recvonly";
853 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800854 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 default:
856 new_direction = "a=sendrecv";
857 break;
858 }
859 Replace("a=sendrecv", new_direction, message);
860}
861
Yves Gerey665174f2018-06-19 15:03:05 +0200862static void ReplaceRejected(bool audio_rejected,
863 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 std::string* message) {
865 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800866 Replace("m=audio 9", "m=audio 0", message);
867 Replace(kAttributeIceUfragVoice, "", message);
868 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
870 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800871 Replace("m=video 9", "m=video 0", message);
872 Replace(kAttributeIceUfragVideo, "", message);
873 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 }
875}
876
877// WebRtcSdpTest
878
879class WebRtcSdpTest : public testing::Test {
880 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800881 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800882#ifdef WEBRTC_ANDROID
883 webrtc::InitializeAndroidObjects();
884#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 // AudioContentDescription
886 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800887 StreamParams audio_stream;
888 audio_stream.id = kAudioTrackId1;
889 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800890 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800891 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
892 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700893 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
894 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800895 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800898 video_desc_ = CreateVideoContentDescription();
899 StreamParams video_stream;
900 video_stream.id = kVideoTrackId1;
901 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800902 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800903 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
904 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
905 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
906 video_stream.ssrc_groups.push_back(ssrc_group);
907 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700908 rtc::SocketAddress video_addr("74.125.224.39", 3457);
909 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800910 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
912 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800913 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
914 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
915 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
916 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917
918 // v4 host
919 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000920 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000921 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000922 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
923 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000925 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000926 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
927 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000929 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000930 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
931 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000933 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000934 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
935 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936
937 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000938 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000939 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
940 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000941 cricket::LOCAL_PORT_TYPE,
942 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000944 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
945 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000946 cricket::LOCAL_PORT_TYPE,
947 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000949 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
950 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 cricket::LOCAL_PORT_TYPE,
952 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000954 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
955 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000956 cricket::LOCAL_PORT_TYPE,
957 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958
959 // stun
960 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000961 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
962 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000963 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
964 address_stun, kCandidatePriority, "", "",
965 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000966 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 candidate9.set_related_address(rel_address_stun);
968
969 address_stun.SetPort(port_stun++);
970 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000971 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
972 address_stun, kCandidatePriority, "", "",
973 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000974 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 candidate10.set_related_address(rel_address_stun);
976
977 // relay
978 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000979 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000980 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
981 address_relay, kCandidatePriority, "", "",
982 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000983 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000985 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
986 address_relay, kCandidatePriority, "", "",
987 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000988 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989
990 // voice
991 candidates_.push_back(candidate1);
992 candidates_.push_back(candidate2);
993 candidates_.push_back(candidate5);
994 candidates_.push_back(candidate6);
995 candidates_.push_back(candidate9);
996 candidates_.push_back(candidate10);
997
998 // video
999 candidates_.push_back(candidate3);
1000 candidates_.push_back(candidate4);
1001 candidates_.push_back(candidate7);
1002 candidates_.push_back(candidate8);
1003 candidates_.push_back(candidate11);
1004 candidates_.push_back(candidate12);
1005
Yves Gerey665174f2018-06-19 15:03:05 +02001006 jcandidate_.reset(
1007 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008
1009 // Set up JsepSessionDescription.
1010 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1011 std::string mline_id;
1012 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001013 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 // In this test, the audio m line index will be 0, and the video m line
1015 // will be 1.
1016 bool is_video = (i > 5);
1017 mline_id = is_video ? "video_content_name" : "audio_content_name";
1018 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001019 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 jdesc_.AddCandidate(&jice);
1021 }
1022 }
1023
Seth Hampson5b4f0752018-04-02 16:31:36 -07001024 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001025 const IceCandidateCollection* video_candidates_collection =
1026 jdesc_.candidates(1);
1027 ASSERT_NE(nullptr, video_candidates_collection);
1028 std::vector<cricket::Candidate> video_candidates;
1029 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1030 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1031 c.set_transport_name("video_content_name");
1032 video_candidates.push_back(c);
1033 }
1034 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001035 }
1036
1037 // Turns the existing reference description into a description using
1038 // a=bundle-only. This means no transport attributes and a 0 port value on
1039 // the m= sections not associated with the BUNDLE-tag.
1040 void MakeBundleOnlyDescription() {
1041 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001042
1043 // And the rest of the transport attributes.
1044 desc_.transport_infos()[1].description.ice_ufrag.clear();
1045 desc_.transport_infos()[1].description.ice_pwd.clear();
1046 desc_.transport_infos()[1].description.connection_role =
1047 cricket::CONNECTIONROLE_NONE;
1048
1049 // Set bundle-only flag.
1050 desc_.contents()[1].bundle_only = true;
1051
1052 // Add BUNDLE group.
1053 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1054 group.AddContentName(kAudioContentName);
1055 group.AddContentName(kVideoContentName);
1056 desc_.AddGroup(group);
1057
1058 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1059 jdesc_.session_version()));
1060 }
1061
deadbeef9d3584c2016-02-16 17:54:10 -08001062 // Turns the existing reference description into a plan B description,
1063 // with 2 audio tracks and 3 video tracks.
1064 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001065 audio_desc_ = audio_desc_->Copy();
1066 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001067
1068 StreamParams audio_track_2;
1069 audio_track_2.id = kAudioTrackId2;
1070 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001071 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001072 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1073 audio_desc_->AddStream(audio_track_2);
1074
1075 StreamParams video_track_2;
1076 video_track_2.id = kVideoTrackId2;
1077 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001078 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001079 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1080 video_desc_->AddStream(video_track_2);
1081
1082 StreamParams video_track_3;
1083 video_track_3.id = kVideoTrackId3;
1084 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001085 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001086 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1087 video_desc_->AddStream(video_track_3);
1088
1089 desc_.RemoveContentByName(kAudioContentName);
1090 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001091 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1092 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001093
1094 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1095 jdesc_.session_version()));
1096 }
1097
1098 // Turns the existing reference description into a unified plan description,
1099 // with 2 audio tracks and 3 video tracks.
1100 void MakeUnifiedPlanDescription() {
1101 // Audio track 2.
1102 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1103 StreamParams audio_track_2;
1104 audio_track_2.id = kAudioTrackId2;
1105 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001106 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001107 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1108 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001109 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001110 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1111 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001112 // Video track 2, in stream 2.
1113 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1114 StreamParams video_track_2;
1115 video_track_2.id = kVideoTrackId2;
1116 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001117 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001118 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1119 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001120 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001121 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1122 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1123
1124 // Video track 3, in stream 2.
1125 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1126 StreamParams video_track_3;
1127 video_track_3.id = kVideoTrackId3;
1128 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001129 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001130 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1131 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001132 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001133 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1134 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001135 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001136
1137 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1138 jdesc_.session_version()));
1139 }
1140
1141 // Creates an audio content description with no streams, and some default
1142 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143 AudioContentDescription* CreateAudioContentDescription() {
1144 AudioContentDescription* audio = new AudioContentDescription();
1145 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001146 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001147 audio->AddCrypto(CryptoParams(
1148 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1150 "dummy_session_params"));
1151 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001152 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001153 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001154 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1155 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 return audio;
1157 }
1158
Seth Hampson5b4f0752018-04-02 16:31:36 -07001159 // Turns the existing reference description into a unified plan description,
1160 // with 3 audio MediaContentDescriptions with special StreamParams that
1161 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1162 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1163 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1164 desc_.RemoveContentByName(kVideoContentName);
1165 desc_.RemoveTransportInfoByName(kVideoContentName);
1166 RemoveVideoCandidates();
1167
1168 // Audio track 2 has 2 media stream ids.
1169 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1170 StreamParams audio_track_2;
1171 audio_track_2.id = kAudioTrackId2;
1172 audio_track_2.cname = kStream1Cname;
1173 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1174 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1175 audio_desc_2->AddStream(audio_track_2);
1176 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1177 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1178 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1179
1180 // Audio track 3 has no stream ids.
1181 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1182 StreamParams audio_track_3;
1183 audio_track_3.id = kAudioTrackId3;
1184 audio_track_3.cname = kStream2Cname;
1185 audio_track_3.set_stream_ids({});
1186 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1187 audio_desc_3->AddStream(audio_track_3);
1188 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1189 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1190 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1191 // Make sure to create both a=msid lines.
1192 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1193 cricket::kMsidSignalingSsrcAttribute);
1194 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1195 jdesc_.session_version()));
1196 }
1197
Seth Hampson5897a6e2018-04-03 11:16:33 -07001198 // Turns the existing reference description into a unified plan description
1199 // with one audio MediaContentDescription that contains one StreamParams with
1200 // 0 ssrcs.
1201 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1202 desc_.RemoveContentByName(kVideoContentName);
1203 desc_.RemoveContentByName(kAudioContentName);
1204 desc_.RemoveTransportInfoByName(kVideoContentName);
1205 RemoveVideoCandidates();
1206
1207 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1208 StreamParams audio_track;
1209 audio_track.id = kAudioTrackId1;
1210 audio_track.set_stream_ids({kStreamId1});
1211 audio_desc->AddStream(audio_track);
1212 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1213
1214 // Enable signaling a=msid lines.
1215 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1216 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1217 jdesc_.session_version()));
1218 }
1219
deadbeef9d3584c2016-02-16 17:54:10 -08001220 // Creates a video content description with no streams, and some default
1221 // configuration.
1222 VideoContentDescription* CreateVideoContentDescription() {
1223 VideoContentDescription* video = new VideoContentDescription();
1224 video->AddCrypto(CryptoParams(
1225 1, "AES_CM_128_HMAC_SHA1_80",
1226 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1227 video->set_protocol(cricket::kMediaProtocolSavpf);
1228 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001229 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001230 return video;
1231 }
1232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001234 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 // type
1236 EXPECT_EQ(cd1->type(), cd1->type());
1237
1238 // content direction
1239 EXPECT_EQ(cd1->direction(), cd2->direction());
1240
1241 // rtcp_mux
1242 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1243
deadbeef13871492015-12-09 12:37:51 -08001244 // rtcp_reduced_size
1245 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1246
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 // cryptos
1248 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1249 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1250 ADD_FAILURE();
1251 return;
1252 }
Yves Gerey665174f2018-06-19 15:03:05 +02001253 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 const CryptoParams c1 = cd1->cryptos().at(i);
1255 const CryptoParams c2 = cd2->cryptos().at(i);
1256 EXPECT_TRUE(c1.Matches(c2));
1257 EXPECT_EQ(c1.key_params, c2.key_params);
1258 EXPECT_EQ(c1.session_params, c2.session_params);
1259 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001262 // Use an equivalence class here, for old and new versions of the
1263 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001264 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1265 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1266 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001267 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001268 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1269 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1270 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001271 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001272 } else {
1273 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1274 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275
1276 // codecs
1277 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1278
1279 // bandwidth
1280 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1281
1282 // streams
1283 EXPECT_EQ(cd1->streams(), cd2->streams());
1284
1285 // extmap
1286 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1287 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001288 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001289 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1290 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 EXPECT_EQ(ext1.uri, ext2.uri);
1292 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001293 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 }
1296
zstein4b2e0822017-02-17 19:48:38 -08001297 void CompareDataContentDescription(const DataContentDescription* dcd1,
1298 const DataContentDescription* dcd2) {
1299 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1300 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1301 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302
1303 void CompareSessionDescription(const SessionDescription& desc1,
1304 const SessionDescription& desc2) {
1305 // Compare content descriptions.
1306 if (desc1.contents().size() != desc2.contents().size()) {
1307 ADD_FAILURE();
1308 return;
1309 }
Yves Gerey665174f2018-06-19 15:03:05 +02001310 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1312 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001313 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001315 EXPECT_EQ(c1.type, c2.type);
1316 EXPECT_EQ(c1.rejected, c2.rejected);
1317 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318
1319 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1320 if (IsAudioContent(&c1)) {
1321 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001322 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001324 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1326 }
1327
1328 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1329 if (IsVideoContent(&c1)) {
1330 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001331 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001333 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1335 }
1336
1337 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1338 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001339 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1340 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001341 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 }
1343 }
1344
1345 // group
1346 const cricket::ContentGroups groups1 = desc1.groups();
1347 const cricket::ContentGroups groups2 = desc2.groups();
1348 EXPECT_EQ(groups1.size(), groups1.size());
1349 if (groups1.size() != groups2.size()) {
1350 ADD_FAILURE();
1351 return;
1352 }
1353 for (size_t i = 0; i < groups1.size(); ++i) {
1354 const cricket::ContentGroup group1 = groups1.at(i);
1355 const cricket::ContentGroup group2 = groups2.at(i);
1356 EXPECT_EQ(group1.semantics(), group2.semantics());
1357 const cricket::ContentNames names1 = group1.content_names();
1358 const cricket::ContentNames names2 = group2.content_names();
1359 EXPECT_EQ(names1.size(), names2.size());
1360 if (names1.size() != names2.size()) {
1361 ADD_FAILURE();
1362 return;
1363 }
1364 cricket::ContentNames::const_iterator iter1 = names1.begin();
1365 cricket::ContentNames::const_iterator iter2 = names2.begin();
1366 while (iter1 != names1.end()) {
1367 EXPECT_EQ(*iter1++, *iter2++);
1368 }
1369 }
1370
1371 // transport info
1372 const cricket::TransportInfos transports1 = desc1.transport_infos();
1373 const cricket::TransportInfos transports2 = desc2.transport_infos();
1374 EXPECT_EQ(transports1.size(), transports2.size());
1375 if (transports1.size() != transports2.size()) {
1376 ADD_FAILURE();
1377 return;
1378 }
1379 for (size_t i = 0; i < transports1.size(); ++i) {
1380 const cricket::TransportInfo transport1 = transports1.at(i);
1381 const cricket::TransportInfo transport2 = transports2.at(i);
1382 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 EXPECT_EQ(transport1.description.ice_ufrag,
1384 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001385 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001386 EXPECT_EQ(transport1.description.ice_mode,
1387 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 if (transport1.description.identity_fingerprint) {
1389 EXPECT_EQ(*transport1.description.identity_fingerprint,
1390 *transport2.description.identity_fingerprint);
1391 } else {
1392 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1393 transport2.description.identity_fingerprint.get());
1394 }
1395 EXPECT_EQ(transport1.description.transport_options,
1396 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 }
deadbeefc80741f2015-10-22 13:14:45 -07001398
1399 // global attributes
1400 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 }
1402
Yves Gerey665174f2018-06-19 15:03:05 +02001403 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1404 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1406 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1407 CompareSessionDescription(*desc1.description(), *desc2.description());
1408 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1409 return false;
1410 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1411 const IceCandidateCollection* cc1 = desc1.candidates(i);
1412 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001413 if (cc1->count() != cc2->count()) {
1414 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001416 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 for (size_t j = 0; j < cc1->count(); ++j) {
1418 const IceCandidateInterface* c1 = cc1->at(j);
1419 const IceCandidateInterface* c2 = cc2->at(j);
1420 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1421 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1422 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1423 }
1424 }
1425 return true;
1426 }
1427
1428 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1429 // them with invalid keywords so that the parser will just ignore them.
1430 bool RemoveCandidateUfragPwd(std::string* sdp) {
1431 const char ice_ufrag[] = "a=ice-ufrag";
1432 const char ice_ufragx[] = "a=xice-ufrag";
1433 const char ice_pwd[] = "a=ice-pwd";
1434 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001435 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1436 strlen(ice_ufragx), sdp);
1437 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1438 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 return true;
1440 }
1441
1442 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001443 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1444 int mline_index,
1445 const std::string& ufrag,
1446 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 std::string content_name;
1448 if (mline_index == 0) {
1449 content_name = kAudioContentName;
1450 } else if (mline_index == 1) {
1451 content_name = kVideoContentName;
1452 } else {
nissec80e7412017-01-11 05:56:46 -08001453 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 }
Yves Gerey665174f2018-06-19 15:03:05 +02001455 TransportInfo transport_info(content_name,
1456 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 SessionDescription* desc =
1458 const_cast<SessionDescription*>(jdesc->description());
1459 desc->RemoveTransportInfoByName(content_name);
1460 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1461 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1462 const IceCandidateCollection* cc = jdesc_.candidates(i);
1463 for (size_t j = 0; j < cc->count(); ++j) {
1464 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001465 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1466 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 }
1468 }
1469 }
1470 return true;
1471 }
1472
1473 void AddIceOptions(const std::string& content_name,
1474 const std::vector<std::string>& transport_options) {
1475 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1476 cricket::TransportInfo transport_info =
1477 *(desc_.GetTransportInfoByName(content_name));
1478 desc_.RemoveTransportInfoByName(content_name);
1479 transport_info.description.transport_options = transport_options;
1480 desc_.AddTransportInfo(transport_info);
1481 }
1482
deadbeef3f7219b2015-12-28 15:17:14 -08001483 void SetIceUfragPwd(const std::string& content_name,
1484 const std::string& ice_ufrag,
1485 const std::string& ice_pwd) {
1486 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1487 cricket::TransportInfo transport_info =
1488 *(desc_.GetTransportInfoByName(content_name));
1489 desc_.RemoveTransportInfoByName(content_name);
1490 transport_info.description.ice_ufrag = ice_ufrag;
1491 transport_info.description.ice_pwd = ice_pwd;
1492 desc_.AddTransportInfo(transport_info);
1493 }
1494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 void AddFingerprint() {
1496 desc_.RemoveTransportInfoByName(kAudioContentName);
1497 desc_.RemoveTransportInfoByName(kVideoContentName);
Yves Gerey665174f2018-06-19 15:03:05 +02001498 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1499 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001500 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1501 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001502 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1503 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001504 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1505 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1506 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001507 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1508 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001509 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 }
1511
jbauch5869f502017-06-29 12:31:36 -07001512 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001513 audio_desc_ = audio_desc_->Copy();
1514 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001515 audio_desc_->AddRtpHeaderExtension(
1516 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1517 video_desc_->AddRtpHeaderExtension(
1518 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 desc_.RemoveContentByName(kAudioContentName);
1520 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001521 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1522 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 }
1524
1525 void RemoveCryptos() {
1526 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1527 video_desc_->set_cryptos(std::vector<CryptoParams>());
1528 }
1529
Seth Hampson5897a6e2018-04-03 11:16:33 -07001530 // Removes everything in StreamParams from the session description that is
1531 // used for a=ssrc lines.
1532 void RemoveSsrcSignalingFromStreamParams() {
1533 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1534 // With Unified Plan there should be one StreamParams per m= section.
1535 StreamParams& stream =
1536 content_info.media_description()->mutable_streams()[0];
1537 stream.ssrcs.clear();
1538 stream.ssrc_groups.clear();
1539 stream.cname.clear();
1540 }
1541 }
1542
1543 // Removes all a=ssrc lines from the SDP string.
1544 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1545 const char kAttributeSsrc[] = "a=ssrc";
1546 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1547 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1548 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1549 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1550 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1551 }
1552 }
1553
Steve Anton4e70a722017-11-28 14:57:10 -08001554 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 audio_desc_->set_direction(direction);
1556 video_desc_->set_direction(direction);
1557 std::string new_sdp = kSdpFullString;
1558 ReplaceDirection(direction, &new_sdp);
1559
Yves Gerey665174f2018-06-19 15:03:05 +02001560 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 jdesc_.session_version())) {
1562 return false;
1563 }
Steve Antone831b8c2018-02-01 12:22:16 -08001564 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 EXPECT_EQ(new_sdp, message);
1566 return true;
1567 }
1568
1569 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001570 audio_desc_ = audio_desc_->Copy();
1571 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001572
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 desc_.RemoveContentByName(kAudioContentName);
1574 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001575 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001577 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001579 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1580 audio_rejected ? "" : kPwdVoice);
1581 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1582 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001583
1584 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1586
Steve Antona3a92c22017-12-07 10:27:41 -08001587 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001588 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001589 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 EXPECT_EQ(new_sdp, message);
1591 return true;
1592 }
1593
zstein4b2e0822017-02-17 19:48:38 -08001594 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001595 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001597 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001599 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001600 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001601 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1602 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001603 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1604 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001605 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1606 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 }
1608
1609 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001610 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 data_desc_ = data.get();
1612
deadbeef67cf2c12016-04-13 10:07:16 -07001613 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 StreamParams data_stream;
1615 data_stream.id = kDataChannelMsid;
1616 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001617 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 data_stream.ssrcs.push_back(kDataChannelSsrc);
1619 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001620 data_desc_->AddCrypto(
1621 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1622 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001624 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001625 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1626 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 }
1628
Steve Anton4e70a722017-11-28 14:57:10 -08001629 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 std::string new_sdp = kSdpFullString;
1631 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001632 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
1634 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1635
1636 audio_desc_->set_direction(direction);
1637 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001638 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 jdesc_.session_version())) {
1640 return false;
1641 }
1642 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1643 return true;
1644 }
1645
1646 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001647 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001649 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001651
Steve Antonb1c1de12017-12-21 15:14:30 -08001652 audio_desc_ = audio_desc_->Copy();
1653 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 desc_.RemoveContentByName(kAudioContentName);
1655 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001656 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001658 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001660 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1661 audio_rejected ? "" : kPwdVoice);
1662 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1663 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001664 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001665 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1666 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 return false;
1668 }
deadbeef3f7219b2015-12-28 15:17:14 -08001669 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 return true;
1671 }
1672
Yves Gerey665174f2018-06-19 15:03:05 +02001673 void TestDeserializeExtmap(bool session_level,
1674 bool media_level,
1675 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001676 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001677 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001678 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001680 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 std::string sdp_with_extmap = kSdpString;
1682 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001683 InjectAfter(kSessionTime,
1684 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1685 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 &sdp_with_extmap);
1687 }
1688 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001689 InjectAfter(kAttributeIcePwdVoice,
1690 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1691 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001693 InjectAfter(kAttributeIcePwdVideo,
1694 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1695 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 &sdp_with_extmap);
1697 }
1698 // The extmap can't be present at the same time in both session level and
1699 // media level.
1700 if (session_level && media_level) {
1701 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001702 EXPECT_FALSE(
1703 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1705 } else {
1706 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1707 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1708 }
1709 }
1710
1711 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001712 const std::string& name,
1713 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 cricket::CodecParameterMap::const_iterator found = params.find(name);
1715 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001716 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 }
1718
1719 void TestDeserializeCodecParams(const CodecParams& params,
1720 JsepSessionDescription* jdesc_output) {
1721 std::string sdp =
1722 "v=0\r\n"
1723 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1724 "s=-\r\n"
1725 "t=0 0\r\n"
1726 // Include semantics for WebRTC Media Streams since it is supported by
1727 // this parser, and will be added to the SDP when serializing a session
1728 // description.
1729 "a=msid-semantic: WMS\r\n"
1730 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001731 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 // Pltype 111 listed before 103 and 104 in the map.
1733 "a=rtpmap:111 opus/48000/2\r\n"
1734 // Pltype 103 listed before 104.
1735 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001736 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001737 "a=fmtp:111 0-15,66,70\r\n"
1738 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001740 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001741 << "; sprop-stereo=" << params.sprop_stereo
1742 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001743 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 << "a=ptime:" << params.ptime << "\r\n"
1745 << "a=maxptime:" << params.max_ptime << "\r\n";
1746 sdp += os.str();
1747
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001748 os.clear();
1749 os.str("");
1750 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001751 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001752 << "a=rtpmap:99 VP8/90000\r\n"
1753 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001754 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001755 sdp += os.str();
1756
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 // Deserialize
1758 SdpParseError error;
1759 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1760
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001762 GetFirstAudioContentDescription(jdesc_output->description());
1763 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 ASSERT_FALSE(acd->codecs().empty());
1765 cricket::AudioCodec opus = acd->codecs()[0];
1766 EXPECT_EQ("opus", opus.name);
1767 EXPECT_EQ(111, opus.id);
1768 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1769 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1770 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1771 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001772 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1773 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1775 cricket::AudioCodec codec = acd->codecs()[i];
1776 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1777 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001779
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001780 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001781 GetFirstVideoContentDescription(jdesc_output->description());
1782 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001783 ASSERT_FALSE(vcd->codecs().empty());
1784 cricket::VideoCodec vp8 = vcd->codecs()[0];
1785 EXPECT_EQ("VP8", vp8.name);
1786 EXPECT_EQ(99, vp8.id);
1787 cricket::VideoCodec rtx = vcd->codecs()[1];
1788 EXPECT_EQ("RTX", rtx.name);
1789 EXPECT_EQ(95, rtx.id);
1790 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 }
1792
1793 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1794 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001795 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 "v=0\r\n"
1797 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1798 "s=-\r\n"
1799 "t=0 0\r\n"
1800 // Include semantics for WebRTC Media Streams since it is supported by
1801 // this parser, and will be added to the SDP when serializing a session
1802 // description.
1803 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001804 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001805 "a=rtpmap:111 opus/48000/2\r\n";
1806 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 "m=video 3457 RTP/SAVPF 101\r\n"
1808 "a=rtpmap:101 VP8/90000\r\n"
1809 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001810 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001811 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001813 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001814 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001815 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001816 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001817 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 // Deserialize
1819 SdpParseError error;
1820 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001822 GetFirstAudioContentDescription(jdesc_output->description());
1823 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 ASSERT_FALSE(acd->codecs().empty());
1825 cricket::AudioCodec opus = acd->codecs()[0];
1826 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001827 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1828 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001831 GetFirstVideoContentDescription(jdesc_output->description());
1832 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 ASSERT_FALSE(vcd->codecs().empty());
1834 cricket::VideoCodec vp8 = vcd->codecs()[0];
1835 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1836 vp8.name.c_str());
1837 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001838 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1839 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1840 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1841 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1842 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1843 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1844 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1845 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 }
1847
1848 // Two SDP messages can mean the same thing but be different strings, e.g.
1849 // some of the lines can be serialized in different order.
1850 // However, a deserialized description can be compared field by field and has
1851 // no order. If deserializer has already been tested, serializing then
1852 // deserializing and comparing JsepSessionDescription will test
1853 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001854 void TestSerialize(const JsepSessionDescription& jdesc) {
1855 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001856 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 SdpParseError error;
1858 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1859 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1860 }
1861
zhihuang38989e52017-03-21 11:04:53 -07001862 // Calling 'Initialize' with a copy of the inner SessionDescription will
1863 // create a copy of the JsepSessionDescription without candidates. The
1864 // 'connection address' field, previously set from the candidates, must also
1865 // be reset.
1866 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1867 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1868 rtc::SocketAddress video_addr("0.0.0.0", 9);
1869 audio_desc_->set_connection_address(audio_addr);
1870 video_desc_->set_connection_address(video_addr);
1871 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1872 }
1873
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 protected:
1875 SessionDescription desc_;
1876 AudioContentDescription* audio_desc_;
1877 VideoContentDescription* video_desc_;
1878 DataContentDescription* data_desc_;
1879 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001880 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 JsepSessionDescription jdesc_;
1882};
1883
1884void TestMismatch(const std::string& string1, const std::string& string2) {
1885 int position = 0;
1886 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1887 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001888 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 break;
1890 }
1891 }
1892 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1893 << " character\n"
1894 << " 1: " << string1.substr(position, 20) << "\n"
1895 << " 2: " << string2.substr(position, 20) << "\n";
1896}
1897
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1899 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001900 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 TestMismatch(std::string(kSdpFullString), message);
1902}
1903
1904TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001905 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001906 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907}
1908
1909// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1910// the case in a DTLS offer.
1911TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1912 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001913 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001914 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001915 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916
1917 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001918 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1919 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920
1921 EXPECT_EQ(sdp_with_fingerprint, message);
1922}
1923
1924// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1925// be the case in a DTLS answer.
1926TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1927 AddFingerprint();
1928 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001929 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001930 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001931 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932
1933 std::string sdp_with_fingerprint = kSdpString;
1934 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1935 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001936 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1937 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938
1939 EXPECT_EQ(sdp_with_fingerprint, message);
1940}
1941
1942TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1943 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001944 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001945 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001946 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 EXPECT_EQ(std::string(kSdpString), message);
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1951 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1952 group.AddContentName(kAudioContentName);
1953 group.AddContentName(kVideoContentName);
1954 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001955 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001957 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 std::string sdp_with_bundle = kSdpFullString;
1959 InjectAfter(kSessionTime,
1960 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1961 &sdp_with_bundle);
1962 EXPECT_EQ(sdp_with_bundle, message);
1963}
1964
1965TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001966 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001968 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001970 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001972 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001974 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001976 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 &sdp_with_bandwidth);
1978 EXPECT_EQ(sdp_with_bandwidth, message);
1979}
1980
1981TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1982 std::vector<std::string> transport_options;
1983 transport_options.push_back(kIceOption1);
1984 transport_options.push_back(kIceOption3);
1985 AddIceOptions(kAudioContentName, transport_options);
1986 transport_options.clear();
1987 transport_options.push_back(kIceOption2);
1988 transport_options.push_back(kIceOption3);
1989 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001990 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001992 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001994 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001996 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 &sdp_with_ice_options);
1998 EXPECT_EQ(sdp_with_ice_options, message);
1999}
2000
2001TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002002 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003}
2004
2005TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002006 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007}
2008
2009TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002010 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011}
2012
2013TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2014 EXPECT_TRUE(TestSerializeRejected(true, false));
2015}
2016
2017TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2018 EXPECT_TRUE(TestSerializeRejected(false, true));
2019}
2020
2021TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2022 EXPECT_TRUE(TestSerializeRejected(true, true));
2023}
2024
2025TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2026 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002027 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028
zhihuang38989e52017-03-21 11:04:53 -07002029 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002030 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031
2032 std::string expected_sdp = kSdpString;
2033 expected_sdp.append(kSdpRtpDataChannelString);
2034 EXPECT_EQ(expected_sdp, message);
2035}
2036
2037TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002038 bool use_sctpmap = true;
2039 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002040 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
zhihuang38989e52017-03-21 11:04:53 -07002042 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002043 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044
2045 std::string expected_sdp = kSdpString;
2046 expected_sdp.append(kSdpSctpDataChannelString);
2047 EXPECT_EQ(message, expected_sdp);
2048}
2049
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002050TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002051 bool use_sctpmap = true;
2052 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002053 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002054 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002055 DataContentDescription* dcdesc =
2056 jsep_desc.description()
2057 ->GetContentDescriptionByName(kDataContentName)
2058 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002059
2060 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002061 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002062 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002063 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2064 dcdesc->AddOrReplaceCodec(codec);
2065
Steve Antone831b8c2018-02-01 12:22:16 -08002066 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002067
2068 std::string expected_sdp = kSdpString;
2069 expected_sdp.append(kSdpSctpDataChannelString);
2070
2071 char default_portstr[16];
2072 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002073 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002074 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002075 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002076 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2077 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002078
2079 EXPECT_EQ(expected_sdp, message);
2080}
2081
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002082TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002083 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002084 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002085 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002086 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002087 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002088
2089 std::string expected_sdp = kSdpString;
2090 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002091 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002092 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002093 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002094 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002095}
2096
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002098 bool encrypted = false;
2099 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002100 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002101 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002102 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
2104 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002105 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2106 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
2108 EXPECT_EQ(sdp_with_extmap, message);
2109}
2110
jbauch5869f502017-06-29 12:31:36 -07002111TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2112 bool encrypted = true;
2113 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002114 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002115 ASSERT_TRUE(
2116 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002117 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002118}
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120TEST_F(WebRtcSdpTest, SerializeCandidates) {
2121 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002122 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002123
2124 Candidate candidate_with_ufrag(candidates_.front());
2125 candidate_with_ufrag.set_username("ABC");
2126 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2127 candidate_with_ufrag));
2128 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2129 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002130
2131 Candidate candidate_with_network_info(candidates_.front());
2132 candidate_with_network_info.set_network_id(1);
2133 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2134 candidate_with_network_info));
2135 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2136 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2137 candidate_with_network_info.set_network_cost(999);
2138 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2139 candidate_with_network_info));
2140 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2141 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2142 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143}
2144
Zach Steinb336c272018-08-09 01:16:13 -07002145TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2146 rtc::SocketAddress address("a.test", 1234);
2147 cricket::Candidate candidate(
2148 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2149 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2150 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2151 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2152 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2153}
2154
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002155// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2156// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002157TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002158 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002159 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2160 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2161 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002162 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002163 std::unique_ptr<IceCandidateInterface> jcandidate(
2164 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002165
2166 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2167 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2168}
2169
htaa6b99442016-04-12 10:29:17 -07002170TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002171 cricket::VideoCodec h264_codec("H264");
2172 h264_codec.SetParam("profile-level-id", "42e01f");
2173 h264_codec.SetParam("level-asymmetry-allowed", "1");
2174 h264_codec.SetParam("packetization-mode", "1");
2175 video_desc_->AddCodec(h264_codec);
2176
htaa6b99442016-04-12 10:29:17 -07002177 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2178
Steve Antone831b8c2018-02-01 12:22:16 -08002179 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002180 size_t after_pt = message.find(" H264/90000");
2181 ASSERT_NE(after_pt, std::string::npos);
2182 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2183 ASSERT_NE(before_pt, std::string::npos);
2184 before_pt += strlen("a=rtpmap:");
2185 std::string pt = message.substr(before_pt, after_pt - before_pt);
2186 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2187 std::string to_find = "a=fmtp:" + pt + " ";
2188 size_t fmtp_pos = message.find(to_find);
2189 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2190 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2191 ASSERT_NE(std::string::npos, fmtp_endpos);
2192 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2193 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2194 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2195 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002196 // Check that there are no spaces after semicolons.
2197 // https://bugs.webrtc.org/5793
2198 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002199}
2200
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002202 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 // Deserialize
2204 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2205 // Verify
2206 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2207}
2208
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002209TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002210 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002211 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002212 "v=0\r\n"
2213 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2214 "s=-\r\n"
2215 "t=0 0\r\n"
2216 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002217 // Deserialize
2218 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2219 EXPECT_EQ(0u, jdesc.description()->contents().size());
2220}
2221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002223 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 std::string sdp_without_carriage_return = kSdpFullString;
2225 Replace("\r\n", "\n", &sdp_without_carriage_return);
2226 // Deserialize
2227 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2228 // Verify
2229 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2230}
2231
2232TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2233 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002234 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002235 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2236 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002237 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2239 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2240}
2241
2242TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2243 static const char kSdpNoRtpmapString[] =
2244 "v=0\r\n"
2245 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2246 "s=-\r\n"
2247 "t=0 0\r\n"
2248 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2249 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002250 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 // The rtpmap line for static payload codec is optional.
2252 "a=rtpmap:18 G729/16000\r\n"
2253 "a=rtpmap:103 ISAC/16000\r\n";
2254
Steve Antona3a92c22017-12-07 10:27:41 -08002255 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2257 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002258 jdesc.description()
2259 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2260 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002262 // The codecs in the AudioContentDescription should be in the same order as
2263 // the payload types (<fmt>s) on the m= line.
2264 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2265 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002266 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 EXPECT_EQ(ref_codecs, audio->codecs());
2268}
2269
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002270TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2271 static const char kSdpNoRtpmapString[] =
2272 "v=0\r\n"
2273 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2274 "s=-\r\n"
2275 "t=0 0\r\n"
2276 "m=audio 49232 RTP/AVP 18 103\r\n"
2277 "a=fmtp:18 annexb=yes\r\n"
2278 "a=rtpmap:103 ISAC/16000\r\n";
2279
Steve Antona3a92c22017-12-07 10:27:41 -08002280 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002281 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2282 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002283 jdesc.description()
2284 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2285 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002286
2287 cricket::AudioCodec g729 = audio->codecs()[0];
2288 EXPECT_EQ("G729", g729.name);
2289 EXPECT_EQ(8000, g729.clockrate);
2290 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002291 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002292 ASSERT_TRUE(found != g729.params.end());
2293 EXPECT_EQ(found->second, "yes");
2294
2295 cricket::AudioCodec isac = audio->codecs()[1];
2296 EXPECT_EQ("ISAC", isac.name);
2297 EXPECT_EQ(103, isac.id);
2298 EXPECT_EQ(16000, isac.clockrate);
2299}
2300
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301// Ensure that we can deserialize SDP with a=fingerprint properly.
2302TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2303 // Add a DTLS a=fingerprint attribute to our session description.
2304 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002305 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002306 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 jdesc_.session_version()));
2308
Steve Antona3a92c22017-12-07 10:27:41 -08002309 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 std::string sdp_with_fingerprint = kSdpString;
2311 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2312 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2313 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2314 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2315}
2316
2317TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002318 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 std::string sdp_with_bundle = kSdpFullString;
2320 InjectAfter(kSessionTime,
2321 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2322 &sdp_with_bundle);
2323 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2324 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2325 group.AddContentName(kAudioContentName);
2326 group.AddContentName(kVideoContentName);
2327 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002328 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 jdesc_.session_version()));
2330 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2331}
2332
2333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002334 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002336 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002338 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002340 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002341 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002343 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002345 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 jdesc_.session_version()));
2347 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2348}
2349
2350TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002351 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002353 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002355 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002357 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 &sdp_with_ice_options);
2359 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2360 std::vector<std::string> transport_options;
2361 transport_options.push_back(kIceOption3);
2362 transport_options.push_back(kIceOption1);
2363 AddIceOptions(kAudioContentName, transport_options);
2364 transport_options.clear();
2365 transport_options.push_back(kIceOption3);
2366 transport_options.push_back(kIceOption2);
2367 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002368 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 jdesc_.session_version()));
2370 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2371}
2372
2373TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2374 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002375 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 std::string sdp_with_ufrag_pwd = kSdpFullString;
2377 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2378 // Add session level ufrag and pwd
2379 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002380 "a=ice-pwd:session+level+icepwd\r\n"
2381 "a=ice-ufrag:session+level+iceufrag\r\n",
2382 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002384 InjectAfter(
2385 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2387 &sdp_with_ufrag_pwd);
2388 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002389 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2390 "media+level+icepwd"));
2391 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2392 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2394 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2395}
2396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002398 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399}
2400
2401TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002402 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403}
2404
2405TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002406 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407}
2408
2409TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2410 EXPECT_TRUE(TestDeserializeRejected(true, false));
2411}
2412
2413TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2414 EXPECT_TRUE(TestDeserializeRejected(false, true));
2415}
2416
2417TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2418 EXPECT_TRUE(TestDeserializeRejected(true, true));
2419}
2420
2421// Tests that we can still handle the sdp uses mslabel and label instead of
2422// msid for backward compatibility.
2423TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002424 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002425 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 std::string sdp_without_msid = kSdpFullString;
2427 Replace("msid", "xmsid", &sdp_without_msid);
2428 // Deserialize
2429 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2430 // Verify
2431 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2432}
2433
2434TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2435 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2436
2437 std::string sdp = kSdpOneCandidate;
2438 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2439 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2440 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2441 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002442 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443
2444 // Candidate line without generation extension.
2445 sdp = kSdpOneCandidate;
2446 Replace(" generation 2", "", &sdp);
2447 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2448 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2449 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2450 Candidate expected = jcandidate_->candidate();
2451 expected.set_generation(0);
2452 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2453
honghaiza0c44ea2016-03-23 16:07:48 -07002454 // Candidate with network id and/or cost.
2455 sdp = kSdpOneCandidate;
2456 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2457 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2458 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2459 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2460 expected = jcandidate_->candidate();
2461 expected.set_network_id(2);
2462 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2463 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2464 // Add network cost
2465 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2466 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2467 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2468 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2469
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002470 sdp = kSdpTcpActiveCandidate;
2471 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2472 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002473 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002474 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2475 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2476 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002477 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2478 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002479 EXPECT_TRUE(
2480 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002481 sdp = kSdpTcpPassiveCandidate;
2482 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2483 sdp = kSdpTcpSOCandidate;
2484 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485}
2486
2487// This test verifies the deserialization of candidate-attribute
2488// as per RFC 5245. Candiate-attribute will be of the format
2489// candidate:<blah>. This format will be used when candidates
2490// are trickled.
2491TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2492 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2493
2494 std::string candidate_attribute = kRawCandidate;
2495 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2496 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2497 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2498 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2499 EXPECT_EQ(2u, jcandidate.candidate().generation());
2500
2501 // Candidate line without generation extension.
2502 candidate_attribute = kRawCandidate;
2503 Replace(" generation 2", "", &candidate_attribute);
2504 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2505 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2506 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2507 Candidate expected = jcandidate_->candidate();
2508 expected.set_generation(0);
2509 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2510
2511 // Candidate line without candidate:
2512 candidate_attribute = kRawCandidate;
2513 Replace("candidate:", "", &candidate_attribute);
2514 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2515
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002516 // Candidate line with IPV6 address.
2517 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002518
2519 // Candidate line with hostname address.
2520 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002521}
2522
2523// This test verifies that the deserialization of an invalid candidate string
2524// fails.
2525TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002526 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002527
2528 std::string candidate_attribute = kRawCandidate;
2529 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002531
2532 candidate_attribute = kSdpOneCandidate;
2533 candidate_attribute.replace(0, 1, "x");
2534 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2535
2536 candidate_attribute = kRawCandidate;
2537 candidate_attribute.append("\r\n");
2538 candidate_attribute.append(kRawCandidate);
2539 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2540
2541 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542}
2543
2544TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2545 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002546 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2548
2549 std::string sdp_with_data = kSdpString;
2550 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002551 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552
2553 // Deserialize
2554 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2555 // Verify
2556 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2557}
2558
2559TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002560 bool use_sctpmap = true;
2561 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002562 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2564
2565 std::string sdp_with_data = kSdpString;
2566 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002567 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568
lally@webrtc.org36300852015-02-24 20:19:35 +00002569 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2570 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2571 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2572
2573 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002574 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2575 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002576 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2577 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2578
2579 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002580 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2581 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2583 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2584}
2585
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002586TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002587 bool use_sctpmap = false;
2588 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002589 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002590 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2591
2592 std::string sdp_with_data = kSdpString;
2593 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002594 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002595
lally@webrtc.org36300852015-02-24 20:19:35 +00002596 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002597 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2598 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002599
lally@webrtc.org36300852015-02-24 20:19:35 +00002600 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002601 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2602 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002603 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2604 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002605
lally@webrtc.org36300852015-02-24 20:19:35 +00002606 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002607 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2608 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002609 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2610 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2611}
2612
lally69f57602015-10-08 10:15:04 -07002613TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002614 bool use_sctpmap = false;
2615 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002616 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002617 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2618
2619 std::string sdp_with_data = kSdpString;
2620 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002621 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002622
2623 // Verify with DTLS/SCTP.
2624 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2625 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2626
2627 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002628 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2629 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002630 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2631 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2632
2633 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002634 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2635 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002636 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2637 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2638}
2639
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002640// Test to check the behaviour if sctp-port is specified
2641// on the m= line and in a=sctp-port.
2642TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002643 bool use_sctpmap = true;
2644 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002645 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002646 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2647
2648 std::string sdp_with_data = kSdpString;
2649 // Append m= attributes
2650 sdp_with_data.append(kSdpSctpDataChannelString);
2651 // Append a=sctp-port attribute
2652 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002653 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002654
2655 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2656}
2657
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002658// For crbug/344475.
2659TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2660 std::string sdp_with_data = kSdpString;
2661 sdp_with_data.append(kSdpSctpDataChannelString);
2662 // Remove the "\n" at the end.
2663 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002664 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002665
2666 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2667 // No crash is a pass.
2668}
2669
Steve Anton36b29d12017-10-30 09:57:42 -07002670void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002671 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002672 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002673 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002674 DataContentDescription* dcdesc =
2675 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002676 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002677 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002678 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002679 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002680 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002681
2682 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002683 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002684 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002685}
2686
2687TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2688 bool use_sctpmap = true;
2689 AddSctpDataChannel(use_sctpmap);
2690
2691 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002692 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002693 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002694
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002695 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002696 std::string sdp_with_data = kSdpString;
2697 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002698 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2699 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2700 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002701 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002702
2703 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2704 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002705}
2706
2707TEST_F(WebRtcSdpTest,
2708 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2709 bool use_sctpmap = false;
2710 AddSctpDataChannel(use_sctpmap);
2711
Steve Antona3a92c22017-12-07 10:27:41 -08002712 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002713 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002714
2715 // We need to test the deserialized JsepSessionDescription from
2716 // kSdpSctpDataChannelStringWithSctpPort for
2717 // draft-ietf-mmusic-sctp-sdp-07
2718 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002719 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002720 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002721 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2722 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2723 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002724 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002725
2726 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2727 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002728}
2729
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002730TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002731 // We want to test that deserializing data content limits bandwidth
2732 // settings (it should never be greater than the default).
2733 // This should prevent someone from using unlimited data bandwidth through
2734 // JS and "breaking the Internet".
2735 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002736 std::string sdp_with_bandwidth = kSdpString;
2737 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002738 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002739 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002740 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002741
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002742 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2743}
2744
2745TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002746 bool use_sctpmap = true;
2747 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002748 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002749 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002750 dcd->set_bandwidth(100 * 1000);
2751 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2752
2753 std::string sdp_with_bandwidth = kSdpString;
2754 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002755 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002756 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002757 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002758
2759 // SCTP has congestion control, so we shouldn't limit the bandwidth
2760 // as we do for RTP.
2761 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002762 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2763}
2764
Yves Gerey665174f2018-06-19 15:03:05 +02002765class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2766 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002767
2768TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002769 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002770 bool encrypted = GetParam();
2771 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772}
2773
Yves Gerey665174f2018-06-19 15:03:05 +02002774TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002775 bool encrypted = GetParam();
2776 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777}
2778
Yves Gerey665174f2018-06-19 15:03:05 +02002779TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002780 bool encrypted = GetParam();
2781 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782}
2783
jbauch5869f502017-06-29 12:31:36 -07002784INSTANTIATE_TEST_CASE_P(Encrypted,
2785 WebRtcSdpExtmapTest,
2786 ::testing::Values(false, true));
2787
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002788TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002789 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002790 std::string sdp = kSdpFullString;
2791 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2792 // Deserialize
2793 SdpParseError error;
2794 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002795 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002796 EXPECT_EQ(lastline, error.line);
2797 EXPECT_EQ("Invalid SDP line.", error.description);
2798}
2799
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2801 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2802 std::string new_sdp = kSdpOneCandidate;
2803 Replace("udp", "unsupported_transport", &new_sdp);
2804 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2805 new_sdp = kSdpOneCandidate;
2806 Replace("udp", "uDP", &new_sdp);
2807 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2808 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2809 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2810 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2811}
2812
honghaiza54a0802015-12-16 18:37:23 -08002813TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002815 EXPECT_TRUE(
2816 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2818 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2819 Candidate ref_candidate = jcandidate_->candidate();
2820 ref_candidate.set_username("user_rtp");
2821 ref_candidate.set_password("password_rtp");
2822 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2823}
2824
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002825TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002826 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002827
2828 // Deserialize
2829 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2830
2831 // Verify
2832 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002833 jdesc.description()
2834 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2835 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002836 EXPECT_TRUE(audio->conference_mode());
2837
2838 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002839 jdesc.description()
2840 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2841 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002842 EXPECT_TRUE(video->conference_mode());
2843}
2844
deadbeefd45aea82017-09-16 01:24:29 -07002845TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002846 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002847
2848 // We tested deserialization already above, so just test that if we serialize
2849 // and deserialize the flag doesn't disappear.
2850 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002851 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002852 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2853
2854 // Verify.
2855 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002856 jdesc.description()
2857 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2858 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002859 EXPECT_TRUE(audio->conference_mode());
2860
2861 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002862 jdesc.description()
2863 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2864 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002865 EXPECT_TRUE(video->conference_mode());
2866}
2867
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2869 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002870 const char kSdpEmptyType[] = " =candidate";
2871 const char kSdpEqualAsPlus[] = "a+candidate";
2872 const char kSdpSpaceAfterEqual[] = "a= candidate";
2873 const char kSdpUpperType[] = "A=candidate";
2874 const char kSdpEmptyLine[] = "";
2875 const char kSdpMissingValue[] = "a=";
2876
Yves Gerey665174f2018-06-19 15:03:05 +02002877 const char kSdpBrokenFingerprint[] =
2878 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879 "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 +02002880 const char kSdpExtraField[] =
2881 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 "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 +02002883 const char kSdpMissingSpace[] =
2884 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885 "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 +00002886 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002887 const char kSdpMd5[] =
2888 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002889 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890
2891 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002892 ExpectParseFailure("v=", kSdpDestroyer);
2893 ExpectParseFailure("o=", kSdpDestroyer);
2894 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002896 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897
2898 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002899 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2900 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901
2902 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002903 ExpectParseFailure("a=candidate", kSdpEmptyType);
2904 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2905 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2906 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907
2908 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2909 // because it's orthogonal to what we are replacing and hence
2910 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002911 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2912 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2913 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2914 ExpectParseFailure("a=sendrecv", kSdpMd5);
2915
2916 // Empty Line
2917 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2918 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002919}
2920
2921TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2922 // ssrc
2923 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002924 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002925 // crypto
2926 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2927 // rtpmap
2928 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2929 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2930 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2931 // candidate
2932 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2933 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2934 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2935 ExpectParseFailure("rport 2346", "rport badvalue");
2936 ExpectParseFailure("rport 2346 generation 2",
2937 "rport 2346 generation badvalue");
2938 // m line
2939 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2940 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2941
2942 // bandwidth
2943 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002944 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002945 // rtcp-fb
2946 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2947 "a=rtcp-fb:badvalue nack\r\n",
2948 "a=rtcp-fb:badvalue nack");
2949 // extmap
2950 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2951 "a=extmap:badvalue http://example.com\r\n",
2952 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953}
2954
2955TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002956 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957
2958 const char kSdpWithReorderedPlTypesString[] =
2959 "v=0\r\n"
2960 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2961 "s=-\r\n"
2962 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002963 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02002964 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2965 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002967 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968
2969 // Deserialize
2970 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2971
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002973 GetFirstAudioContentDescription(jdesc_output.description());
2974 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002976 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2977 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 EXPECT_EQ(104, acd->codecs()[0].id);
2979}
2980
2981TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08002982 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 CodecParams params;
2984 params.max_ptime = 40;
2985 params.ptime = 30;
2986 params.min_ptime = 10;
2987 params.sprop_stereo = 1;
2988 params.stereo = 1;
2989 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002990 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08002992 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993}
2994
2995TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2996 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08002997 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08002999 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000}
3001
3002TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3003 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003004 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003006 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003007}
3008
3009TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003010 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011
3012 const char kSdpWithFmtpString[] =
3013 "v=0\r\n"
3014 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3015 "s=-\r\n"
3016 "t=0 0\r\n"
3017 "m=video 3457 RTP/SAVPF 120\r\n"
3018 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003019 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3020
3021 // Deserialize
3022 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003023 EXPECT_TRUE(
3024 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003025
Donald Curtis0e07f922015-05-15 09:21:23 -07003026 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003027 GetFirstVideoContentDescription(jdesc_output.description());
3028 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003029 ASSERT_FALSE(vcd->codecs().empty());
3030 cricket::VideoCodec vp8 = vcd->codecs()[0];
3031 EXPECT_EQ("VP8", vp8.name);
3032 EXPECT_EQ(120, vp8.id);
3033 cricket::CodecParameterMap::iterator found =
3034 vp8.params.find("x-google-min-bitrate");
3035 ASSERT_TRUE(found != vp8.params.end());
3036 EXPECT_EQ(found->second, "10");
3037 found = vp8.params.find("x-google-max-quantization");
3038 ASSERT_TRUE(found != vp8.params.end());
3039 EXPECT_EQ(found->second, "40");
3040}
3041
johan2d8d23e2016-06-03 01:22:42 -07003042TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003043 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003044
3045 const char kSdpWithFmtpString[] =
3046 "v=0\r\n"
3047 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3048 "s=-\r\n"
3049 "t=0 0\r\n"
3050 "m=video 49170 RTP/AVP 98\r\n"
3051 "a=rtpmap:98 H264/90000\r\n"
3052 "a=fmtp:98 profile-level-id=42A01E; "
3053 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3054
3055 // Deserialize.
3056 SdpParseError error;
3057 EXPECT_TRUE(
3058 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3059
johan2d8d23e2016-06-03 01:22:42 -07003060 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003061 GetFirstVideoContentDescription(jdesc_output.description());
3062 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003063 ASSERT_FALSE(vcd->codecs().empty());
3064 cricket::VideoCodec h264 = vcd->codecs()[0];
3065 EXPECT_EQ("H264", h264.name);
3066 EXPECT_EQ(98, h264.id);
3067 cricket::CodecParameterMap::const_iterator found =
3068 h264.params.find("profile-level-id");
3069 ASSERT_TRUE(found != h264.params.end());
3070 EXPECT_EQ(found->second, "42A01E");
3071 found = h264.params.find("sprop-parameter-sets");
3072 ASSERT_TRUE(found != h264.params.end());
3073 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3074}
3075
Donald Curtis0e07f922015-05-15 09:21:23 -07003076TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003077 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003078
3079 const char kSdpWithFmtpString[] =
3080 "v=0\r\n"
3081 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3082 "s=-\r\n"
3083 "t=0 0\r\n"
3084 "m=video 3457 RTP/SAVPF 120\r\n"
3085 "a=rtpmap:120 VP8/90000\r\n"
3086 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003087
3088 // Deserialize
3089 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003090 EXPECT_TRUE(
3091 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003094 GetFirstVideoContentDescription(jdesc_output.description());
3095 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 ASSERT_FALSE(vcd->codecs().empty());
3097 cricket::VideoCodec vp8 = vcd->codecs()[0];
3098 EXPECT_EQ("VP8", vp8.name);
3099 EXPECT_EQ(120, vp8.id);
3100 cricket::CodecParameterMap::iterator found =
3101 vp8.params.find("x-google-min-bitrate");
3102 ASSERT_TRUE(found != vp8.params.end());
3103 EXPECT_EQ(found->second, "10");
3104 found = vp8.params.find("x-google-max-quantization");
3105 ASSERT_TRUE(found != vp8.params.end());
3106 EXPECT_EQ(found->second, "40");
3107}
3108
ossuaa4b0772017-01-30 07:41:18 -08003109TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003110 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003111
3112 cricket::AudioCodecs codecs = acd->codecs();
3113 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3114 acd->set_codecs(codecs);
3115
Yves Gerey665174f2018-06-19 15:03:05 +02003116 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003117 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003118 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003119 std::string sdp_with_fmtp = kSdpFullString;
3120 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3121 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3122 &sdp_with_fmtp);
3123 EXPECT_EQ(sdp_with_fmtp, message);
3124}
3125
3126TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003127 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003128
3129 cricket::AudioCodecs codecs = acd->codecs();
3130 codecs[0].params["stereo"] = "1";
3131 acd->set_codecs(codecs);
3132
Yves Gerey665174f2018-06-19 15:03:05 +02003133 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003134 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003135 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003136 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003137 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003138 &sdp_with_fmtp);
3139 EXPECT_EQ(sdp_with_fmtp, message);
3140}
3141
3142TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003143 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003144
3145 cricket::AudioCodecs codecs = acd->codecs();
3146 codecs[0].params["ptime"] = "20";
3147 codecs[0].params["maxptime"] = "120";
3148 acd->set_codecs(codecs);
3149
Yves Gerey665174f2018-06-19 15:03:05 +02003150 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003151 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003152 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003153 std::string sdp_with_fmtp = kSdpFullString;
3154 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3155 "a=maxptime:120\r\n" // No comma here. String merging!
3156 "a=ptime:20\r\n",
3157 &sdp_with_fmtp);
3158 EXPECT_EQ(sdp_with_fmtp, message);
3159}
3160
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003162 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003163
3164 cricket::VideoCodecs codecs = vcd->codecs();
3165 codecs[0].params["x-google-min-bitrate"] = "10";
3166 vcd->set_codecs(codecs);
3167
Yves Gerey665174f2018-06-19 15:03:05 +02003168 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003170 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003171 std::string sdp_with_fmtp = kSdpFullString;
3172 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003173 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174 EXPECT_EQ(sdp_with_fmtp, message);
3175}
3176
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003177TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3178 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003179 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003180 std::string sdp_with_icelite = kSdpFullString;
3181 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3182 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3183 const cricket::TransportInfo* tinfo1 =
3184 desc->GetTransportInfoByName("audio_content_name");
3185 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3186 const cricket::TransportInfo* tinfo2 =
3187 desc->GetTransportInfoByName("video_content_name");
3188 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003189
3190 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003191 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3193 desc = jdesc_with_icelite.description();
3194 const cricket::TransportInfo* atinfo =
3195 desc->GetTransportInfoByName("audio_content_name");
3196 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3197 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003198 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003200
3201 // Now that we know deserialization works, we can use TestSerialize to test
3202 // serialization.
3203 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003204}
3205
3206// Verifies that the candidates in the input SDP are parsed and serialized
3207// correctly in the output SDP.
3208TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3209 std::string sdp_with_data = kSdpString;
3210 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003211 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003212
3213 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003214 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003215}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003216
3217TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3218 AddFingerprint();
3219 TransportInfo audio_transport_info =
3220 *(desc_.GetTransportInfoByName(kAudioContentName));
3221 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3222 audio_transport_info.description.connection_role);
3223 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003224 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003225
3226 TransportInfo video_transport_info =
3227 *(desc_.GetTransportInfoByName(kVideoContentName));
3228 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3229 video_transport_info.description.connection_role);
3230 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003231 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003232
3233 desc_.RemoveTransportInfoByName(kAudioContentName);
3234 desc_.RemoveTransportInfoByName(kVideoContentName);
3235
3236 desc_.AddTransportInfo(audio_transport_info);
3237 desc_.AddTransportInfo(video_transport_info);
3238
Yves Gerey665174f2018-06-19 15:03:05 +02003239 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003240 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003241 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003242 std::string sdp_with_dtlssetup = kSdpFullString;
3243
3244 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003245 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3246 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003247 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003248 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003249 EXPECT_EQ(sdp_with_dtlssetup, message);
3250}
3251
3252TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003253 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003254 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003255 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003256 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3257 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3258 const cricket::TransportInfo* atinfo =
3259 desc->GetTransportInfoByName("audio_content_name");
3260 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3261 atinfo->description.connection_role);
3262 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003263 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003264 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3265 vtinfo->description.connection_role);
3266}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003267
3268// Verifies that the order of the serialized m-lines follows the order of the
3269// ContentInfo in SessionDescription, and vise versa for deserialization.
3270TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003271 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003272 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3273 kSdpSctpDataChannelString};
3274 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3275 cricket::MEDIA_TYPE_VIDEO,
3276 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003277
3278 // Verifies all 6 permutations.
3279 for (size_t i = 0; i < 6; ++i) {
3280 size_t media_content_in_sdp[3];
3281 // The index of the first media content.
3282 media_content_in_sdp[0] = i / 2;
3283 // The index of the second media content.
3284 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3285 // The index of the third media content.
3286 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3287
3288 std::string sdp_string = kSdpSessionString;
3289 for (size_t i = 0; i < 3; ++i)
3290 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3291
3292 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3293 cricket::SessionDescription* desc = jdesc.description();
3294 EXPECT_EQ(3u, desc->contents().size());
3295
3296 for (size_t i = 0; i < 3; ++i) {
3297 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003298 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003299 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3300 }
3301
Steve Antone831b8c2018-02-01 12:22:16 -08003302 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003303 EXPECT_EQ(sdp_string, serialized_sdp);
3304 }
3305}
deadbeef9d3584c2016-02-16 17:54:10 -08003306
deadbeef25ed4352016-12-12 18:37:36 -08003307TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3308 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003309 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003310 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003311 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3312 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3313}
3314
deadbeef12771a12017-01-03 13:53:47 -08003315// The semantics of "a=bundle-only" are only defined when it's used in
3316// combination with a 0 port on the m= line. We should ignore it if used with a
3317// nonzero port.
3318TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3319 // Make the base bundle-only description but unset the bundle-only flag.
3320 MakeBundleOnlyDescription();
3321 jdesc_.description()->contents()[1].bundle_only = false;
3322
3323 std::string modified_sdp = kBundleOnlySdpFullString;
3324 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003325 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003326 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3327 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003328}
3329
3330TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3331 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003332 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003333}
3334
deadbeef9d3584c2016-02-16 17:54:10 -08003335TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3336 MakePlanBDescription();
3337
Steve Antona3a92c22017-12-07 10:27:41 -08003338 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003339 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3340
3341 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3342}
3343
3344TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3345 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003346 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003347}
3348
3349TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3350 MakeUnifiedPlanDescription();
3351
Steve Antona3a92c22017-12-07 10:27:41 -08003352 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003353 EXPECT_TRUE(
3354 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3355
3356 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3357}
3358
3359TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3360 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003361 TestSerialize(jdesc_);
3362}
3363
Seth Hampson5b4f0752018-04-02 16:31:36 -07003364// This tests deserializing a Unified Plan SDP that is compatible with both
3365// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3366// with no stream ids and multiple stream ids. For parsing this, the Unified
3367// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3368// lines do not support multiple stream ids and no stream ids.
3369TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3370 MakeUnifiedPlanDescriptionMultipleStreamIds();
3371
3372 JsepSessionDescription deserialized_description(kDummyType);
3373 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3374 &deserialized_description));
3375
3376 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3377}
3378
3379TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3380 MakeUnifiedPlanDescriptionMultipleStreamIds();
3381 TestSerialize(jdesc_);
3382}
3383
Seth Hampson5897a6e2018-04-03 11:16:33 -07003384// This tests that a Unified Plan SDP with no a=ssrc lines is
3385// serialized/deserialized appropriately. In this case the
3386// MediaContentDescription will contain a StreamParams object that doesn't have
3387// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3388// SSRC lines.
3389TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3390 MakeUnifiedPlanDescription();
3391 RemoveSsrcSignalingFromStreamParams();
3392 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3393 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3394
3395 JsepSessionDescription deserialized_description(kDummyType);
3396 EXPECT_TRUE(
3397 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3398 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3399}
3400
3401TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3402 MakeUnifiedPlanDescription();
3403 RemoveSsrcSignalingFromStreamParams();
3404
3405 TestSerialize(jdesc_);
3406}
3407
Steve Antone831b8c2018-02-01 12:22:16 -08003408TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3409 JsepSessionDescription jsep_desc(kDummyType);
3410 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3411 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3412}
3413
3414TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3415 JsepSessionDescription jsep_desc(kDummyType);
3416 std::string sdp = kSdpSessionString;
3417 sdp += kSdpSctpDataChannelString;
3418 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3419 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3420}
3421
3422TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3423 JsepSessionDescription jsep_desc(kDummyType);
3424 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3425 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3426 jsep_desc.description()->msid_signaling());
3427}
3428
3429TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3430 JsepSessionDescription jsep_desc(kDummyType);
3431 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3432 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3433 jsep_desc.description()->msid_signaling());
3434}
3435
3436const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3437const char kSsrcAttributeMsidLine[] =
3438 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3439
3440TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3441 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3442 std::string sdp = webrtc::SdpSerialize(jdesc_);
3443
3444 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3445 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3446}
3447
3448TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3449 jdesc_.description()->set_msid_signaling(
3450 cricket::kMsidSignalingSsrcAttribute);
3451 std::string sdp = webrtc::SdpSerialize(jdesc_);
3452
3453 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3454 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3455}
3456
3457TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3458 jdesc_.description()->set_msid_signaling(
3459 cricket::kMsidSignalingMediaSection |
3460 cricket::kMsidSignalingSsrcAttribute);
3461 std::string sdp = webrtc::SdpSerialize(jdesc_);
3462
3463 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3464 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003465}
deadbeef7e146cb2016-09-28 10:04:34 -07003466
3467// Regression test for heap overflow bug:
3468// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3469TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003470 // The issue occurs when the sctp-port attribute is found in a video
3471 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003472 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003473 "v=0\r\n"
3474 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3475 "s=-\r\n"
3476 "t=0 0\r\n"
3477 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3478 "a=sctp-port 5000\r\n"
3479 "a=fmtp:108 foo=10\r\n";
3480
3481 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3482 "sctp-port");
3483}
deadbeefb2362572016-12-13 16:37:06 -08003484
3485// Regression test for integer overflow bug:
3486// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3487TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003488 // Bandwidth attribute is the max signed 32-bit int, which will get
3489 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003490 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003491 "v=0\r\n"
3492 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3493 "s=-\r\n"
3494 "t=0 0\r\n"
3495 "m=video 3457 RTP/SAVPF 120\r\n"
3496 "b=AS:2147483647\r\n"
3497 "foo=fail\r\n";
3498
3499 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3500}
deadbeef7bcdb692017-01-20 12:43:58 -08003501
deadbeefbc88c6b2017-08-02 11:26:34 -07003502// Similar to the above, except that negative values are illegal, not just
3503// error-prone as large values are.
3504// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3505TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3506 static const char kSdpWithNegativeBandwidth[] =
3507 "v=0\r\n"
3508 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3509 "s=-\r\n"
3510 "t=0 0\r\n"
3511 "m=video 3457 RTP/SAVPF 120\r\n"
3512 "b=AS:-1000\r\n";
3513
3514 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3515}
3516
deadbeef3e8016e2017-08-03 17:49:30 -07003517// An exception to the above rule: a value of -1 for b=AS should just be
3518// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3519// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3520// limit", but this is now what ommitting the attribute entirely will do, so
3521// ignoring it will have the intended effect.
3522TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3523 static const char kSdpWithBandwidthOfNegativeOne[] =
3524 "v=0\r\n"
3525 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3526 "s=-\r\n"
3527 "t=0 0\r\n"
3528 "m=video 3457 RTP/SAVPF 120\r\n"
3529 "b=AS:-1\r\n";
3530
Steve Antona3a92c22017-12-07 10:27:41 -08003531 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003532 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003533 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003534 GetFirstVideoContentDescription(jdesc_output.description());
3535 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003536 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3537}
3538
deadbeef7bcdb692017-01-20 12:43:58 -08003539// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3540// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3541// Regression test for:
3542// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3543TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3544 // Important piece is "ufrag foo pwd bar".
3545 static const char kSdpWithIceCredentialsInCandidateString[] =
3546 "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=audio 9 RTP/SAVPF 111\r\n"
3551 "c=IN IP4 0.0.0.0\r\n"
3552 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3553 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3554 "a=rtpmap:111 opus/48000/2\r\n"
3555 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3556 "generation 2 ufrag foo pwd bar\r\n";
3557
Steve Antona3a92c22017-12-07 10:27:41 -08003558 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003559 EXPECT_TRUE(
3560 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3561 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3562 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003563 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003564 cricket::Candidate c = candidates->at(0)->candidate();
3565 EXPECT_EQ("ufrag_voice", c.username());
3566 EXPECT_EQ("pwd_voice", c.password());
3567}
deadbeef90f1e1e2017-02-10 12:35:05 -08003568
Johannes Kron211856b2018-09-06 12:12:28 +02003569// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3570// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3571// Regression test for:
3572// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3573TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3574 static const char kSdpWithFooIceCredentials[] =
3575 "v=0\r\n"
3576 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3577 "s=-\r\n"
3578 "t=0 0\r\n"
3579 "m=audio 9 RTP/SAVPF 111\r\n"
3580 "c=IN IP4 0.0.0.0\r\n"
3581 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3582 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3583 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3584 "a=rtpmap:111 opus/48000/2\r\n"
3585 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3586 "generation 2\r\n";
3587
3588 JsepSessionDescription jdesc_output(kDummyType);
3589 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3590 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3591 ASSERT_NE(nullptr, candidates);
3592 ASSERT_EQ(1U, candidates->count());
3593 cricket::Candidate c = candidates->at(0)->candidate();
3594 EXPECT_EQ("ufrag_voice", c.username());
3595 EXPECT_EQ("pwd_voice", c.password());
3596}
3597
deadbeef90f1e1e2017-02-10 12:35:05 -08003598// Test that SDP with an invalid port number in "a=candidate" lines is
3599// rejected, without crashing.
3600// Regression test for:
3601// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3602TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3603 static const char kSdpWithInvalidCandidatePort[] =
3604 "v=0\r\n"
3605 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3606 "s=-\r\n"
3607 "t=0 0\r\n"
3608 "m=audio 9 RTP/SAVPF 111\r\n"
3609 "c=IN IP4 0.0.0.0\r\n"
3610 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3611 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3612 "a=rtpmap:111 opus/48000/2\r\n"
3613 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3614 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3615
Steve Antona3a92c22017-12-07 10:27:41 -08003616 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003617 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3618}
deadbeefa4549d62017-02-10 17:26:22 -08003619
3620// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3621// Regression test for:
3622// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3623TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3624 static const char kSdpWithMissingTrackId[] =
3625 "v=0\r\n"
3626 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3627 "s=-\r\n"
3628 "t=0 0\r\n"
3629 "m=audio 9 RTP/SAVPF 111\r\n"
3630 "c=IN IP4 0.0.0.0\r\n"
3631 "a=rtpmap:111 opus/48000/2\r\n"
3632 "a=msid:stream_id \r\n";
3633
Steve Antona3a92c22017-12-07 10:27:41 -08003634 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003635 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3636}
3637
3638TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3639 static const char kSdpWithMissingStreamId[] =
3640 "v=0\r\n"
3641 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3642 "s=-\r\n"
3643 "t=0 0\r\n"
3644 "m=audio 9 RTP/SAVPF 111\r\n"
3645 "c=IN IP4 0.0.0.0\r\n"
3646 "a=rtpmap:111 opus/48000/2\r\n"
3647 "a=msid: track_id\r\n";
3648
Steve Antona3a92c22017-12-07 10:27:41 -08003649 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003650 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3651}
zhihuang38989e52017-03-21 11:04:53 -07003652
3653// Tests that if both session-level address and media-level address exist, use
3654// the media-level address.
3655TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003656 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003657
3658 // Sesssion-level address.
3659 std::string sdp = kSdpFullString;
3660 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3661 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3662
3663 const auto& content1 = jsep_desc.description()->contents()[0];
3664 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003665 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003666 const auto& content2 = jsep_desc.description()->contents()[1];
3667 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003668 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003669}
3670
3671// Tests that the session-level connection address will be used if the media
3672// level-addresses are not specified.
3673TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003674 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003675
3676 // Sesssion-level address.
3677 std::string sdp = kSdpString;
3678 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3679 // Remove the media level addresses.
3680 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3681 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3682 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3683
3684 const auto& content1 = jsep_desc.description()->contents()[0];
3685 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003686 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003687 const auto& content2 = jsep_desc.description()->contents()[1];
3688 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003689 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003690}
3691
3692TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003693 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003694
3695 std::string sdp = kSdpString;
3696 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3697 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3698 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3699 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3700 &sdp);
3701 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3702 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3703 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3704 &sdp);
3705 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3706 const auto& content1 = jsep_desc.description()->contents()[0];
3707 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003708 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003709 const auto& content2 = jsep_desc.description()->contents()[1];
3710 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003711 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003712}
3713
3714// Test that the invalid or unsupprted connection data cannot be parsed.
3715TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003716 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003717 std::string sdp = kSdpString;
3718 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3719
3720 // Unsupported multicast IPv4 address.
3721 sdp = kSdpFullString;
3722 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3723 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3724
3725 // Unsupported multicast IPv6 address.
3726 sdp = kSdpFullString;
3727 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3728 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3729
3730 // Mismatched address type.
3731 sdp = kSdpFullString;
3732 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3733 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3734
3735 sdp = kSdpFullString;
3736 Replace("c=IN IP4 74.125.224.39\r\n",
3737 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3738 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3739}
3740
3741TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003742 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003743 MakeDescriptionWithoutCandidates(&expected_jsep);
3744 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003745 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003746 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003747 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003748 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003749 auto audio_desc = jdesc.description()
3750 ->GetContentByName(kAudioContentName)
3751 ->media_description();
3752 auto video_desc = jdesc.description()
3753 ->GetContentByName(kVideoContentName)
3754 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003755 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3756 audio_desc->connection_address().ToString());
3757 EXPECT_EQ(video_desc_->connection_address().ToString(),
3758 video_desc->connection_address().ToString());
3759}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003760
3761// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3762// used (i.e., a single space as the session name)." So we should accept that.
3763TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3764 JsepSessionDescription jsep_desc(kDummyType);
3765 std::string sdp = kSdpString;
3766 Replace("s=-\r\n", "s= \r\n", &sdp);
3767 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3768}