blob: 6800553eb148cadd9c82bcf59c350fd746fa86a3 [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
711// Session id and version
712static const char kSessionId[] = "18446744069414584320";
713static const char kSessionVersion[] = "18446462598732840960";
714
deadbeef9d3584c2016-02-16 17:54:10 -0800715// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716static const char kIceOption1[] = "iceoption1";
717static const char kIceOption2[] = "iceoption2";
718static const char kIceOption3[] = "iceoption3";
719
deadbeef9d3584c2016-02-16 17:54:10 -0800720// ICE ufrags/passwords.
721static const char kUfragVoice[] = "ufrag_voice";
722static const char kPwdVoice[] = "pwd_voice";
723static const char kUfragVideo[] = "ufrag_video";
724static const char kPwdVideo[] = "pwd_video";
725static const char kUfragData[] = "ufrag_data";
726static const char kPwdData[] = "pwd_data";
727
728// Extra ufrags/passwords for extra unified plan m= sections.
729static const char kUfragVoice2[] = "ufrag_voice_2";
730static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700731static const char kUfragVoice3[] = "ufrag_voice_3";
732static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800733static const char kUfragVideo2[] = "ufrag_video_2";
734static const char kPwdVideo2[] = "pwd_video_2";
735static const char kUfragVideo3[] = "ufrag_video_3";
736static const char kPwdVideo3[] = "pwd_video_3";
737
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738// Content name
739static const char kAudioContentName[] = "audio_content_name";
740static const char kVideoContentName[] = "video_content_name";
741static const char kDataContentName[] = "data_content_name";
742
deadbeef9d3584c2016-02-16 17:54:10 -0800743// Extra content names for extra unified plan m= sections.
744static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700745static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800746static const char kVideoContentName2[] = "video_content_name_2";
747static const char kVideoContentName3[] = "video_content_name_3";
748
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800750static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751static const char kStream1Cname[] = "stream_1_cname";
752static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200753static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800755static const uint32_t kVideoTrack1Ssrc1 = 2;
756static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757
758// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800759static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760static const char kStream2Cname[] = "stream_2_cname";
761static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200762static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800763static const char kVideoTrackId2[] = "video_track_id_2";
764static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800766static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700767static const char kAudioTrackId3[] = "audio_track_id_3";
768static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769
770// DataChannel
771static const char kDataChannelLabel[] = "data_channel";
772static const char kDataChannelMsid[] = "data_channeld0";
773static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200774static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775
776// Candidate
777static const char kDummyMid[] = "dummy_mid";
778static const int kDummyIndex = 123;
779
780// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800781static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782
783// Helper functions
784
785static bool SdpDeserialize(const std::string& message,
786 JsepSessionDescription* jdesc) {
787 return webrtc::SdpDeserialize(message, jdesc, NULL);
788}
789
790static bool SdpDeserializeCandidate(const std::string& message,
791 JsepIceCandidate* candidate) {
792 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
793}
794
795// Add some extra |newlines| to the |message| after |line|.
796static void InjectAfter(const std::string& line,
797 const std::string& newlines,
798 std::string* message) {
799 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200800 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
801 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802}
803
804static void Replace(const std::string& line,
805 const std::string& newlines,
806 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200807 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
808 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809}
810
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000811// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
812// message.
813static void ExpectParseFailure(const std::string& bad_sdp,
814 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800815 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000817 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000819 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
820}
821
822// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
823static void ExpectParseFailure(const char* good_part, const char* bad_part) {
824 std::string bad_sdp = kSdpFullString;
825 Replace(good_part, bad_part, &bad_sdp);
826 ExpectParseFailure(bad_sdp, bad_part);
827}
828
829// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
830static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
831 const std::string& newlines,
832 const std::string& bad_part) {
833 std::string bad_sdp = kSdpFullString;
834 InjectAfter(injectpoint, newlines, &bad_sdp);
835 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836}
837
Steve Anton4e70a722017-11-28 14:57:10 -0800838static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 std::string* message) {
840 std::string new_direction;
841 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800842 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 new_direction = "a=inactive";
844 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800845 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 new_direction = "a=sendonly";
847 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800848 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 new_direction = "a=recvonly";
850 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800851 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 default:
853 new_direction = "a=sendrecv";
854 break;
855 }
856 Replace("a=sendrecv", new_direction, message);
857}
858
Yves Gerey665174f2018-06-19 15:03:05 +0200859static void ReplaceRejected(bool audio_rejected,
860 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 std::string* message) {
862 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800863 Replace("m=audio 9", "m=audio 0", message);
864 Replace(kAttributeIceUfragVoice, "", message);
865 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 }
867 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800868 Replace("m=video 9", "m=video 0", message);
869 Replace(kAttributeIceUfragVideo, "", message);
870 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 }
872}
873
874// WebRtcSdpTest
875
876class WebRtcSdpTest : public testing::Test {
877 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800878 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800879#ifdef WEBRTC_ANDROID
880 webrtc::InitializeAndroidObjects();
881#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 // AudioContentDescription
883 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800884 StreamParams audio_stream;
885 audio_stream.id = kAudioTrackId1;
886 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800887 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800888 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
889 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700890 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
891 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800892 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893
894 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800895 video_desc_ = CreateVideoContentDescription();
896 StreamParams video_stream;
897 video_stream.id = kVideoTrackId1;
898 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800899 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800900 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
901 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
902 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
903 video_stream.ssrc_groups.push_back(ssrc_group);
904 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700905 rtc::SocketAddress video_addr("74.125.224.39", 3457);
906 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800907 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
909 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800910 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
911 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
912 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
913 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914
915 // v4 host
916 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000918 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000919 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
920 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000922 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000923 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
924 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000927 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000930 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000931 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
932 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933
934 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000935 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000936 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
937 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000938 cricket::LOCAL_PORT_TYPE,
939 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000941 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000946 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
947 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000948 cricket::LOCAL_PORT_TYPE,
949 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
952 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 cricket::LOCAL_PORT_TYPE,
954 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955
956 // stun
957 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000958 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
959 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000960 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
961 address_stun, kCandidatePriority, "", "",
962 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000963 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 candidate9.set_related_address(rel_address_stun);
965
966 address_stun.SetPort(port_stun++);
967 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
969 address_stun, kCandidatePriority, "", "",
970 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000971 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 candidate10.set_related_address(rel_address_stun);
973
974 // relay
975 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000976 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000977 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
978 address_relay, kCandidatePriority, "", "",
979 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000980 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000982 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
983 address_relay, kCandidatePriority, "", "",
984 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000985 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986
987 // voice
988 candidates_.push_back(candidate1);
989 candidates_.push_back(candidate2);
990 candidates_.push_back(candidate5);
991 candidates_.push_back(candidate6);
992 candidates_.push_back(candidate9);
993 candidates_.push_back(candidate10);
994
995 // video
996 candidates_.push_back(candidate3);
997 candidates_.push_back(candidate4);
998 candidates_.push_back(candidate7);
999 candidates_.push_back(candidate8);
1000 candidates_.push_back(candidate11);
1001 candidates_.push_back(candidate12);
1002
Yves Gerey665174f2018-06-19 15:03:05 +02001003 jcandidate_.reset(
1004 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005
1006 // Set up JsepSessionDescription.
1007 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1008 std::string mline_id;
1009 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001010 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 // In this test, the audio m line index will be 0, and the video m line
1012 // will be 1.
1013 bool is_video = (i > 5);
1014 mline_id = is_video ? "video_content_name" : "audio_content_name";
1015 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001016 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 jdesc_.AddCandidate(&jice);
1018 }
1019 }
1020
Seth Hampson5b4f0752018-04-02 16:31:36 -07001021 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001022 const IceCandidateCollection* video_candidates_collection =
1023 jdesc_.candidates(1);
1024 ASSERT_NE(nullptr, video_candidates_collection);
1025 std::vector<cricket::Candidate> video_candidates;
1026 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1027 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1028 c.set_transport_name("video_content_name");
1029 video_candidates.push_back(c);
1030 }
1031 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001032 }
1033
1034 // Turns the existing reference description into a description using
1035 // a=bundle-only. This means no transport attributes and a 0 port value on
1036 // the m= sections not associated with the BUNDLE-tag.
1037 void MakeBundleOnlyDescription() {
1038 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001039
1040 // And the rest of the transport attributes.
1041 desc_.transport_infos()[1].description.ice_ufrag.clear();
1042 desc_.transport_infos()[1].description.ice_pwd.clear();
1043 desc_.transport_infos()[1].description.connection_role =
1044 cricket::CONNECTIONROLE_NONE;
1045
1046 // Set bundle-only flag.
1047 desc_.contents()[1].bundle_only = true;
1048
1049 // Add BUNDLE group.
1050 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1051 group.AddContentName(kAudioContentName);
1052 group.AddContentName(kVideoContentName);
1053 desc_.AddGroup(group);
1054
1055 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1056 jdesc_.session_version()));
1057 }
1058
deadbeef9d3584c2016-02-16 17:54:10 -08001059 // Turns the existing reference description into a plan B description,
1060 // with 2 audio tracks and 3 video tracks.
1061 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001062 audio_desc_ = audio_desc_->Copy();
1063 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001064
1065 StreamParams audio_track_2;
1066 audio_track_2.id = kAudioTrackId2;
1067 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001068 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001069 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1070 audio_desc_->AddStream(audio_track_2);
1071
1072 StreamParams video_track_2;
1073 video_track_2.id = kVideoTrackId2;
1074 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001075 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001076 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1077 video_desc_->AddStream(video_track_2);
1078
1079 StreamParams video_track_3;
1080 video_track_3.id = kVideoTrackId3;
1081 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001082 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001083 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1084 video_desc_->AddStream(video_track_3);
1085
1086 desc_.RemoveContentByName(kAudioContentName);
1087 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001088 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1089 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001090
1091 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1092 jdesc_.session_version()));
1093 }
1094
1095 // Turns the existing reference description into a unified plan description,
1096 // with 2 audio tracks and 3 video tracks.
1097 void MakeUnifiedPlanDescription() {
1098 // Audio track 2.
1099 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1100 StreamParams audio_track_2;
1101 audio_track_2.id = kAudioTrackId2;
1102 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001103 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001104 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1105 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001106 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001107 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1108 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001109 // Video track 2, in stream 2.
1110 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1111 StreamParams video_track_2;
1112 video_track_2.id = kVideoTrackId2;
1113 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001114 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001115 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1116 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001117 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001118 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1119 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1120
1121 // Video track 3, in stream 2.
1122 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1123 StreamParams video_track_3;
1124 video_track_3.id = kVideoTrackId3;
1125 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001126 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001127 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1128 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001129 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001130 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1131 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001132 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001133
1134 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1135 jdesc_.session_version()));
1136 }
1137
1138 // Creates an audio content description with no streams, and some default
1139 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 AudioContentDescription* CreateAudioContentDescription() {
1141 AudioContentDescription* audio = new AudioContentDescription();
1142 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001143 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001144 audio->AddCrypto(CryptoParams(
1145 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1147 "dummy_session_params"));
1148 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001149 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001150 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001151 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1152 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 return audio;
1154 }
1155
Seth Hampson5b4f0752018-04-02 16:31:36 -07001156 // Turns the existing reference description into a unified plan description,
1157 // with 3 audio MediaContentDescriptions with special StreamParams that
1158 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1159 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1160 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1161 desc_.RemoveContentByName(kVideoContentName);
1162 desc_.RemoveTransportInfoByName(kVideoContentName);
1163 RemoveVideoCandidates();
1164
1165 // Audio track 2 has 2 media stream ids.
1166 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1167 StreamParams audio_track_2;
1168 audio_track_2.id = kAudioTrackId2;
1169 audio_track_2.cname = kStream1Cname;
1170 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1171 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1172 audio_desc_2->AddStream(audio_track_2);
1173 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1174 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1175 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1176
1177 // Audio track 3 has no stream ids.
1178 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1179 StreamParams audio_track_3;
1180 audio_track_3.id = kAudioTrackId3;
1181 audio_track_3.cname = kStream2Cname;
1182 audio_track_3.set_stream_ids({});
1183 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1184 audio_desc_3->AddStream(audio_track_3);
1185 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1186 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1187 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1188 // Make sure to create both a=msid lines.
1189 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1190 cricket::kMsidSignalingSsrcAttribute);
1191 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1192 jdesc_.session_version()));
1193 }
1194
Seth Hampson5897a6e2018-04-03 11:16:33 -07001195 // Turns the existing reference description into a unified plan description
1196 // with one audio MediaContentDescription that contains one StreamParams with
1197 // 0 ssrcs.
1198 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1199 desc_.RemoveContentByName(kVideoContentName);
1200 desc_.RemoveContentByName(kAudioContentName);
1201 desc_.RemoveTransportInfoByName(kVideoContentName);
1202 RemoveVideoCandidates();
1203
1204 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1205 StreamParams audio_track;
1206 audio_track.id = kAudioTrackId1;
1207 audio_track.set_stream_ids({kStreamId1});
1208 audio_desc->AddStream(audio_track);
1209 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1210
1211 // Enable signaling a=msid lines.
1212 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1213 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1214 jdesc_.session_version()));
1215 }
1216
deadbeef9d3584c2016-02-16 17:54:10 -08001217 // Creates a video content description with no streams, and some default
1218 // configuration.
1219 VideoContentDescription* CreateVideoContentDescription() {
1220 VideoContentDescription* video = new VideoContentDescription();
1221 video->AddCrypto(CryptoParams(
1222 1, "AES_CM_128_HMAC_SHA1_80",
1223 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1224 video->set_protocol(cricket::kMediaProtocolSavpf);
1225 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001226 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001227 return video;
1228 }
1229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001231 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // type
1233 EXPECT_EQ(cd1->type(), cd1->type());
1234
1235 // content direction
1236 EXPECT_EQ(cd1->direction(), cd2->direction());
1237
1238 // rtcp_mux
1239 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1240
deadbeef13871492015-12-09 12:37:51 -08001241 // rtcp_reduced_size
1242 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1243
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244 // cryptos
1245 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1246 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1247 ADD_FAILURE();
1248 return;
1249 }
Yves Gerey665174f2018-06-19 15:03:05 +02001250 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 const CryptoParams c1 = cd1->cryptos().at(i);
1252 const CryptoParams c2 = cd2->cryptos().at(i);
1253 EXPECT_TRUE(c1.Matches(c2));
1254 EXPECT_EQ(c1.key_params, c2.key_params);
1255 EXPECT_EQ(c1.session_params, c2.session_params);
1256 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001257
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001259 // Use an equivalence class here, for old and new versions of the
1260 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001261 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1262 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1263 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001264 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001265 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1266 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1267 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001268 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001269 } else {
1270 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1271 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272
1273 // codecs
1274 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1275
1276 // bandwidth
1277 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1278
1279 // streams
1280 EXPECT_EQ(cd1->streams(), cd2->streams());
1281
1282 // extmap
1283 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1284 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001285 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001286 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1287 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_EQ(ext1.uri, ext2.uri);
1289 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001290 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 }
1293
zstein4b2e0822017-02-17 19:48:38 -08001294 void CompareDataContentDescription(const DataContentDescription* dcd1,
1295 const DataContentDescription* dcd2) {
1296 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1297 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1298 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299
1300 void CompareSessionDescription(const SessionDescription& desc1,
1301 const SessionDescription& desc2) {
1302 // Compare content descriptions.
1303 if (desc1.contents().size() != desc2.contents().size()) {
1304 ADD_FAILURE();
1305 return;
1306 }
Yves Gerey665174f2018-06-19 15:03:05 +02001307 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1309 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001310 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001312 EXPECT_EQ(c1.type, c2.type);
1313 EXPECT_EQ(c1.rejected, c2.rejected);
1314 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315
1316 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1317 if (IsAudioContent(&c1)) {
1318 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001319 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001321 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1323 }
1324
1325 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1326 if (IsVideoContent(&c1)) {
1327 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001328 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001330 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1332 }
1333
1334 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1335 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001336 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1337 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001338 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 }
1340 }
1341
1342 // group
1343 const cricket::ContentGroups groups1 = desc1.groups();
1344 const cricket::ContentGroups groups2 = desc2.groups();
1345 EXPECT_EQ(groups1.size(), groups1.size());
1346 if (groups1.size() != groups2.size()) {
1347 ADD_FAILURE();
1348 return;
1349 }
1350 for (size_t i = 0; i < groups1.size(); ++i) {
1351 const cricket::ContentGroup group1 = groups1.at(i);
1352 const cricket::ContentGroup group2 = groups2.at(i);
1353 EXPECT_EQ(group1.semantics(), group2.semantics());
1354 const cricket::ContentNames names1 = group1.content_names();
1355 const cricket::ContentNames names2 = group2.content_names();
1356 EXPECT_EQ(names1.size(), names2.size());
1357 if (names1.size() != names2.size()) {
1358 ADD_FAILURE();
1359 return;
1360 }
1361 cricket::ContentNames::const_iterator iter1 = names1.begin();
1362 cricket::ContentNames::const_iterator iter2 = names2.begin();
1363 while (iter1 != names1.end()) {
1364 EXPECT_EQ(*iter1++, *iter2++);
1365 }
1366 }
1367
1368 // transport info
1369 const cricket::TransportInfos transports1 = desc1.transport_infos();
1370 const cricket::TransportInfos transports2 = desc2.transport_infos();
1371 EXPECT_EQ(transports1.size(), transports2.size());
1372 if (transports1.size() != transports2.size()) {
1373 ADD_FAILURE();
1374 return;
1375 }
1376 for (size_t i = 0; i < transports1.size(); ++i) {
1377 const cricket::TransportInfo transport1 = transports1.at(i);
1378 const cricket::TransportInfo transport2 = transports2.at(i);
1379 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 EXPECT_EQ(transport1.description.ice_ufrag,
1381 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001382 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001383 EXPECT_EQ(transport1.description.ice_mode,
1384 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 if (transport1.description.identity_fingerprint) {
1386 EXPECT_EQ(*transport1.description.identity_fingerprint,
1387 *transport2.description.identity_fingerprint);
1388 } else {
1389 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1390 transport2.description.identity_fingerprint.get());
1391 }
1392 EXPECT_EQ(transport1.description.transport_options,
1393 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 }
deadbeefc80741f2015-10-22 13:14:45 -07001395
1396 // global attributes
1397 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 }
1399
Yves Gerey665174f2018-06-19 15:03:05 +02001400 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1401 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1403 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1404 CompareSessionDescription(*desc1.description(), *desc2.description());
1405 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1406 return false;
1407 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1408 const IceCandidateCollection* cc1 = desc1.candidates(i);
1409 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001410 if (cc1->count() != cc2->count()) {
1411 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 for (size_t j = 0; j < cc1->count(); ++j) {
1415 const IceCandidateInterface* c1 = cc1->at(j);
1416 const IceCandidateInterface* c2 = cc2->at(j);
1417 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1418 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1419 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1420 }
1421 }
1422 return true;
1423 }
1424
1425 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1426 // them with invalid keywords so that the parser will just ignore them.
1427 bool RemoveCandidateUfragPwd(std::string* sdp) {
1428 const char ice_ufrag[] = "a=ice-ufrag";
1429 const char ice_ufragx[] = "a=xice-ufrag";
1430 const char ice_pwd[] = "a=ice-pwd";
1431 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001432 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1433 strlen(ice_ufragx), sdp);
1434 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1435 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 return true;
1437 }
1438
1439 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001440 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1441 int mline_index,
1442 const std::string& ufrag,
1443 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 std::string content_name;
1445 if (mline_index == 0) {
1446 content_name = kAudioContentName;
1447 } else if (mline_index == 1) {
1448 content_name = kVideoContentName;
1449 } else {
nissec80e7412017-01-11 05:56:46 -08001450 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 }
Yves Gerey665174f2018-06-19 15:03:05 +02001452 TransportInfo transport_info(content_name,
1453 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 SessionDescription* desc =
1455 const_cast<SessionDescription*>(jdesc->description());
1456 desc->RemoveTransportInfoByName(content_name);
1457 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1458 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1459 const IceCandidateCollection* cc = jdesc_.candidates(i);
1460 for (size_t j = 0; j < cc->count(); ++j) {
1461 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001462 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1463 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 }
1465 }
1466 }
1467 return true;
1468 }
1469
1470 void AddIceOptions(const std::string& content_name,
1471 const std::vector<std::string>& transport_options) {
1472 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1473 cricket::TransportInfo transport_info =
1474 *(desc_.GetTransportInfoByName(content_name));
1475 desc_.RemoveTransportInfoByName(content_name);
1476 transport_info.description.transport_options = transport_options;
1477 desc_.AddTransportInfo(transport_info);
1478 }
1479
deadbeef3f7219b2015-12-28 15:17:14 -08001480 void SetIceUfragPwd(const std::string& content_name,
1481 const std::string& ice_ufrag,
1482 const std::string& ice_pwd) {
1483 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1484 cricket::TransportInfo transport_info =
1485 *(desc_.GetTransportInfoByName(content_name));
1486 desc_.RemoveTransportInfoByName(content_name);
1487 transport_info.description.ice_ufrag = ice_ufrag;
1488 transport_info.description.ice_pwd = ice_pwd;
1489 desc_.AddTransportInfo(transport_info);
1490 }
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 void AddFingerprint() {
1493 desc_.RemoveTransportInfoByName(kAudioContentName);
1494 desc_.RemoveTransportInfoByName(kVideoContentName);
Yves Gerey665174f2018-06-19 15:03:05 +02001495 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1496 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001497 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1498 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001499 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1500 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001501 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1502 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1503 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001504 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1505 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001506 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 }
1508
jbauch5869f502017-06-29 12:31:36 -07001509 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001510 audio_desc_ = audio_desc_->Copy();
1511 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001512 audio_desc_->AddRtpHeaderExtension(
1513 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1514 video_desc_->AddRtpHeaderExtension(
1515 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 desc_.RemoveContentByName(kAudioContentName);
1517 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001518 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1519 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 }
1521
1522 void RemoveCryptos() {
1523 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1524 video_desc_->set_cryptos(std::vector<CryptoParams>());
1525 }
1526
Seth Hampson5897a6e2018-04-03 11:16:33 -07001527 // Removes everything in StreamParams from the session description that is
1528 // used for a=ssrc lines.
1529 void RemoveSsrcSignalingFromStreamParams() {
1530 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1531 // With Unified Plan there should be one StreamParams per m= section.
1532 StreamParams& stream =
1533 content_info.media_description()->mutable_streams()[0];
1534 stream.ssrcs.clear();
1535 stream.ssrc_groups.clear();
1536 stream.cname.clear();
1537 }
1538 }
1539
1540 // Removes all a=ssrc lines from the SDP string.
1541 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1542 const char kAttributeSsrc[] = "a=ssrc";
1543 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1544 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1545 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1546 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1547 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1548 }
1549 }
1550
Steve Anton4e70a722017-11-28 14:57:10 -08001551 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 audio_desc_->set_direction(direction);
1553 video_desc_->set_direction(direction);
1554 std::string new_sdp = kSdpFullString;
1555 ReplaceDirection(direction, &new_sdp);
1556
Yves Gerey665174f2018-06-19 15:03:05 +02001557 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 jdesc_.session_version())) {
1559 return false;
1560 }
Steve Antone831b8c2018-02-01 12:22:16 -08001561 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 EXPECT_EQ(new_sdp, message);
1563 return true;
1564 }
1565
1566 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001567 audio_desc_ = audio_desc_->Copy();
1568 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001569
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 desc_.RemoveContentByName(kAudioContentName);
1571 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001572 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001574 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001576 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1577 audio_rejected ? "" : kPwdVoice);
1578 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1579 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001580
1581 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1583
Steve Antona3a92c22017-12-07 10:27:41 -08001584 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001585 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001586 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 EXPECT_EQ(new_sdp, message);
1588 return true;
1589 }
1590
zstein4b2e0822017-02-17 19:48:38 -08001591 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001592 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001594 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001596 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001597 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001598 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1599 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001600 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1601 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001602 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1603 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 }
1605
1606 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001607 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 data_desc_ = data.get();
1609
deadbeef67cf2c12016-04-13 10:07:16 -07001610 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 StreamParams data_stream;
1612 data_stream.id = kDataChannelMsid;
1613 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001614 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 data_stream.ssrcs.push_back(kDataChannelSsrc);
1616 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001617 data_desc_->AddCrypto(
1618 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1619 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001621 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001622 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1623 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 }
1625
Steve Anton4e70a722017-11-28 14:57:10 -08001626 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 std::string new_sdp = kSdpFullString;
1628 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001629 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630
1631 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1632
1633 audio_desc_->set_direction(direction);
1634 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001635 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 jdesc_.session_version())) {
1637 return false;
1638 }
1639 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1640 return true;
1641 }
1642
1643 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001644 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001646 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001648
Steve Antonb1c1de12017-12-21 15:14:30 -08001649 audio_desc_ = audio_desc_->Copy();
1650 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 desc_.RemoveContentByName(kAudioContentName);
1652 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001653 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001655 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001657 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1658 audio_rejected ? "" : kPwdVoice);
1659 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1660 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001661 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001662 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1663 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 return false;
1665 }
deadbeef3f7219b2015-12-28 15:17:14 -08001666 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 return true;
1668 }
1669
Yves Gerey665174f2018-06-19 15:03:05 +02001670 void TestDeserializeExtmap(bool session_level,
1671 bool media_level,
1672 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001673 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001674 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001675 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001677 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 std::string sdp_with_extmap = kSdpString;
1679 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001680 InjectAfter(kSessionTime,
1681 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1682 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 &sdp_with_extmap);
1684 }
1685 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001686 InjectAfter(kAttributeIcePwdVoice,
1687 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1688 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001690 InjectAfter(kAttributeIcePwdVideo,
1691 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1692 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 &sdp_with_extmap);
1694 }
1695 // The extmap can't be present at the same time in both session level and
1696 // media level.
1697 if (session_level && media_level) {
1698 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001699 EXPECT_FALSE(
1700 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1702 } else {
1703 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1704 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1705 }
1706 }
1707
1708 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001709 const std::string& name,
1710 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 cricket::CodecParameterMap::const_iterator found = params.find(name);
1712 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001713 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 }
1715
1716 void TestDeserializeCodecParams(const CodecParams& params,
1717 JsepSessionDescription* jdesc_output) {
1718 std::string sdp =
1719 "v=0\r\n"
1720 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1721 "s=-\r\n"
1722 "t=0 0\r\n"
1723 // Include semantics for WebRTC Media Streams since it is supported by
1724 // this parser, and will be added to the SDP when serializing a session
1725 // description.
1726 "a=msid-semantic: WMS\r\n"
1727 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001728 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 // Pltype 111 listed before 103 and 104 in the map.
1730 "a=rtpmap:111 opus/48000/2\r\n"
1731 // Pltype 103 listed before 104.
1732 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001733 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001734 "a=fmtp:111 0-15,66,70\r\n"
1735 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001737 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001738 << "; sprop-stereo=" << params.sprop_stereo
1739 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001740 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 << "a=ptime:" << params.ptime << "\r\n"
1742 << "a=maxptime:" << params.max_ptime << "\r\n";
1743 sdp += os.str();
1744
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001745 os.clear();
1746 os.str("");
1747 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001748 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001749 << "a=rtpmap:99 VP8/90000\r\n"
1750 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001751 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001752 sdp += os.str();
1753
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 // Deserialize
1755 SdpParseError error;
1756 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001759 GetFirstAudioContentDescription(jdesc_output->description());
1760 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 ASSERT_FALSE(acd->codecs().empty());
1762 cricket::AudioCodec opus = acd->codecs()[0];
1763 EXPECT_EQ("opus", opus.name);
1764 EXPECT_EQ(111, opus.id);
1765 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1766 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1767 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1768 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001769 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1770 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1772 cricket::AudioCodec codec = acd->codecs()[i];
1773 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1774 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001776
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001777 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001778 GetFirstVideoContentDescription(jdesc_output->description());
1779 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001780 ASSERT_FALSE(vcd->codecs().empty());
1781 cricket::VideoCodec vp8 = vcd->codecs()[0];
1782 EXPECT_EQ("VP8", vp8.name);
1783 EXPECT_EQ(99, vp8.id);
1784 cricket::VideoCodec rtx = vcd->codecs()[1];
1785 EXPECT_EQ("RTX", rtx.name);
1786 EXPECT_EQ(95, rtx.id);
1787 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 }
1789
1790 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1791 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001792 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 "v=0\r\n"
1794 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1795 "s=-\r\n"
1796 "t=0 0\r\n"
1797 // Include semantics for WebRTC Media Streams since it is supported by
1798 // this parser, and will be added to the SDP when serializing a session
1799 // description.
1800 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001801 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001802 "a=rtpmap:111 opus/48000/2\r\n";
1803 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 "m=video 3457 RTP/SAVPF 101\r\n"
1805 "a=rtpmap:101 VP8/90000\r\n"
1806 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001807 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001808 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001810 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001811 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001813 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001814 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 // Deserialize
1816 SdpParseError error;
1817 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001819 GetFirstAudioContentDescription(jdesc_output->description());
1820 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 ASSERT_FALSE(acd->codecs().empty());
1822 cricket::AudioCodec opus = acd->codecs()[0];
1823 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001824 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1825 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001828 GetFirstVideoContentDescription(jdesc_output->description());
1829 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 ASSERT_FALSE(vcd->codecs().empty());
1831 cricket::VideoCodec vp8 = vcd->codecs()[0];
1832 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1833 vp8.name.c_str());
1834 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001835 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1836 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1837 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1838 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1839 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1840 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1841 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1842 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 }
1844
1845 // Two SDP messages can mean the same thing but be different strings, e.g.
1846 // some of the lines can be serialized in different order.
1847 // However, a deserialized description can be compared field by field and has
1848 // no order. If deserializer has already been tested, serializing then
1849 // deserializing and comparing JsepSessionDescription will test
1850 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001851 void TestSerialize(const JsepSessionDescription& jdesc) {
1852 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001853 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 SdpParseError error;
1855 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1856 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1857 }
1858
zhihuang38989e52017-03-21 11:04:53 -07001859 // Calling 'Initialize' with a copy of the inner SessionDescription will
1860 // create a copy of the JsepSessionDescription without candidates. The
1861 // 'connection address' field, previously set from the candidates, must also
1862 // be reset.
1863 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1864 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1865 rtc::SocketAddress video_addr("0.0.0.0", 9);
1866 audio_desc_->set_connection_address(audio_addr);
1867 video_desc_->set_connection_address(video_addr);
1868 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1869 }
1870
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 protected:
1872 SessionDescription desc_;
1873 AudioContentDescription* audio_desc_;
1874 VideoContentDescription* video_desc_;
1875 DataContentDescription* data_desc_;
1876 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001877 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 JsepSessionDescription jdesc_;
1879};
1880
1881void TestMismatch(const std::string& string1, const std::string& string2) {
1882 int position = 0;
1883 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1884 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001885 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 break;
1887 }
1888 }
1889 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1890 << " character\n"
1891 << " 1: " << string1.substr(position, 20) << "\n"
1892 << " 2: " << string2.substr(position, 20) << "\n";
1893}
1894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1896 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001897 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 TestMismatch(std::string(kSdpFullString), message);
1899}
1900
1901TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001902 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001903 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904}
1905
1906// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1907// the case in a DTLS offer.
1908TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1909 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001910 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001911 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001912 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913
1914 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001915 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1916 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917
1918 EXPECT_EQ(sdp_with_fingerprint, message);
1919}
1920
1921// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1922// be the case in a DTLS answer.
1923TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1924 AddFingerprint();
1925 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001926 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001927 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001928 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929
1930 std::string sdp_with_fingerprint = kSdpString;
1931 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1932 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001933 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1934 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935
1936 EXPECT_EQ(sdp_with_fingerprint, message);
1937}
1938
1939TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1940 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001941 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001942 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001943 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 EXPECT_EQ(std::string(kSdpString), message);
1945}
1946
1947TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1948 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1949 group.AddContentName(kAudioContentName);
1950 group.AddContentName(kVideoContentName);
1951 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001952 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001954 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 std::string sdp_with_bundle = kSdpFullString;
1956 InjectAfter(kSessionTime,
1957 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1958 &sdp_with_bundle);
1959 EXPECT_EQ(sdp_with_bundle, message);
1960}
1961
1962TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001963 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001965 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001967 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001969 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001971 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001973 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 &sdp_with_bandwidth);
1975 EXPECT_EQ(sdp_with_bandwidth, message);
1976}
1977
1978TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1979 std::vector<std::string> transport_options;
1980 transport_options.push_back(kIceOption1);
1981 transport_options.push_back(kIceOption3);
1982 AddIceOptions(kAudioContentName, transport_options);
1983 transport_options.clear();
1984 transport_options.push_back(kIceOption2);
1985 transport_options.push_back(kIceOption3);
1986 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001987 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001989 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001991 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001993 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 &sdp_with_ice_options);
1995 EXPECT_EQ(sdp_with_ice_options, message);
1996}
1997
1998TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001999 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000}
2001
2002TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002003 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004}
2005
2006TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002007 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008}
2009
2010TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2011 EXPECT_TRUE(TestSerializeRejected(true, false));
2012}
2013
2014TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2015 EXPECT_TRUE(TestSerializeRejected(false, true));
2016}
2017
2018TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2019 EXPECT_TRUE(TestSerializeRejected(true, true));
2020}
2021
2022TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2023 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002024 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025
zhihuang38989e52017-03-21 11:04:53 -07002026 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002027 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028
2029 std::string expected_sdp = kSdpString;
2030 expected_sdp.append(kSdpRtpDataChannelString);
2031 EXPECT_EQ(expected_sdp, message);
2032}
2033
2034TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002035 bool use_sctpmap = true;
2036 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002037 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038
zhihuang38989e52017-03-21 11:04:53 -07002039 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002040 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
2042 std::string expected_sdp = kSdpString;
2043 expected_sdp.append(kSdpSctpDataChannelString);
2044 EXPECT_EQ(message, expected_sdp);
2045}
2046
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002047TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002048 bool use_sctpmap = true;
2049 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002050 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002051 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002052 DataContentDescription* dcdesc =
2053 jsep_desc.description()
2054 ->GetContentDescriptionByName(kDataContentName)
2055 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002056
2057 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002058 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002059 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002060 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2061 dcdesc->AddOrReplaceCodec(codec);
2062
Steve Antone831b8c2018-02-01 12:22:16 -08002063 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002064
2065 std::string expected_sdp = kSdpString;
2066 expected_sdp.append(kSdpSctpDataChannelString);
2067
2068 char default_portstr[16];
2069 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002070 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002071 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002072 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002073 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2074 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002075
2076 EXPECT_EQ(expected_sdp, message);
2077}
2078
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002079TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002080 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002081 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002082 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002083 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002084 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002085
2086 std::string expected_sdp = kSdpString;
2087 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002088 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002089 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002090 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002091 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002092}
2093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002095 bool encrypted = false;
2096 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002097 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002098 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002099 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
2101 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002102 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2103 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
2105 EXPECT_EQ(sdp_with_extmap, message);
2106}
2107
jbauch5869f502017-06-29 12:31:36 -07002108TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2109 bool encrypted = true;
2110 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002111 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002112 ASSERT_TRUE(
2113 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002114 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002115}
2116
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117TEST_F(WebRtcSdpTest, SerializeCandidates) {
2118 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002119 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002120
2121 Candidate candidate_with_ufrag(candidates_.front());
2122 candidate_with_ufrag.set_username("ABC");
2123 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2124 candidate_with_ufrag));
2125 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2126 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002127
2128 Candidate candidate_with_network_info(candidates_.front());
2129 candidate_with_network_info.set_network_id(1);
2130 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2131 candidate_with_network_info));
2132 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2133 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2134 candidate_with_network_info.set_network_cost(999);
2135 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2136 candidate_with_network_info));
2137 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2138 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2139 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140}
2141
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002142// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2143// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002144TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002145 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002146 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2147 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2148 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002149 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002150 std::unique_ptr<IceCandidateInterface> jcandidate(
2151 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002152
2153 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2154 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2155}
2156
htaa6b99442016-04-12 10:29:17 -07002157TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002158 cricket::VideoCodec h264_codec("H264");
2159 h264_codec.SetParam("profile-level-id", "42e01f");
2160 h264_codec.SetParam("level-asymmetry-allowed", "1");
2161 h264_codec.SetParam("packetization-mode", "1");
2162 video_desc_->AddCodec(h264_codec);
2163
htaa6b99442016-04-12 10:29:17 -07002164 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2165
Steve Antone831b8c2018-02-01 12:22:16 -08002166 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002167 size_t after_pt = message.find(" H264/90000");
2168 ASSERT_NE(after_pt, std::string::npos);
2169 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2170 ASSERT_NE(before_pt, std::string::npos);
2171 before_pt += strlen("a=rtpmap:");
2172 std::string pt = message.substr(before_pt, after_pt - before_pt);
2173 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2174 std::string to_find = "a=fmtp:" + pt + " ";
2175 size_t fmtp_pos = message.find(to_find);
2176 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2177 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2178 ASSERT_NE(std::string::npos, fmtp_endpos);
2179 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2180 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2181 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2182 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002183 // Check that there are no spaces after semicolons.
2184 // https://bugs.webrtc.org/5793
2185 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002186}
2187
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002189 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 // Deserialize
2191 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2192 // Verify
2193 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2194}
2195
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002196TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002197 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002198 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002199 "v=0\r\n"
2200 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2201 "s=-\r\n"
2202 "t=0 0\r\n"
2203 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002204 // Deserialize
2205 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2206 EXPECT_EQ(0u, jdesc.description()->contents().size());
2207}
2208
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002210 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 std::string sdp_without_carriage_return = kSdpFullString;
2212 Replace("\r\n", "\n", &sdp_without_carriage_return);
2213 // Deserialize
2214 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2215 // Verify
2216 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2217}
2218
2219TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2220 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002221 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002222 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2223 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002224 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2226 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2227}
2228
2229TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2230 static const char kSdpNoRtpmapString[] =
2231 "v=0\r\n"
2232 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2233 "s=-\r\n"
2234 "t=0 0\r\n"
2235 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2236 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002237 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 // The rtpmap line for static payload codec is optional.
2239 "a=rtpmap:18 G729/16000\r\n"
2240 "a=rtpmap:103 ISAC/16000\r\n";
2241
Steve Antona3a92c22017-12-07 10:27:41 -08002242 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2244 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002245 jdesc.description()
2246 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2247 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002249 // The codecs in the AudioContentDescription should be in the same order as
2250 // the payload types (<fmt>s) on the m= line.
2251 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2252 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002253 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 EXPECT_EQ(ref_codecs, audio->codecs());
2255}
2256
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002257TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2258 static const char kSdpNoRtpmapString[] =
2259 "v=0\r\n"
2260 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2261 "s=-\r\n"
2262 "t=0 0\r\n"
2263 "m=audio 49232 RTP/AVP 18 103\r\n"
2264 "a=fmtp:18 annexb=yes\r\n"
2265 "a=rtpmap:103 ISAC/16000\r\n";
2266
Steve Antona3a92c22017-12-07 10:27:41 -08002267 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002268 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2269 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002270 jdesc.description()
2271 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2272 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002273
2274 cricket::AudioCodec g729 = audio->codecs()[0];
2275 EXPECT_EQ("G729", g729.name);
2276 EXPECT_EQ(8000, g729.clockrate);
2277 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002278 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002279 ASSERT_TRUE(found != g729.params.end());
2280 EXPECT_EQ(found->second, "yes");
2281
2282 cricket::AudioCodec isac = audio->codecs()[1];
2283 EXPECT_EQ("ISAC", isac.name);
2284 EXPECT_EQ(103, isac.id);
2285 EXPECT_EQ(16000, isac.clockrate);
2286}
2287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288// Ensure that we can deserialize SDP with a=fingerprint properly.
2289TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2290 // Add a DTLS a=fingerprint attribute to our session description.
2291 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002292 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002293 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 jdesc_.session_version()));
2295
Steve Antona3a92c22017-12-07 10:27:41 -08002296 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 std::string sdp_with_fingerprint = kSdpString;
2298 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2299 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2300 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2301 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2302}
2303
2304TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002305 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 std::string sdp_with_bundle = kSdpFullString;
2307 InjectAfter(kSessionTime,
2308 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2309 &sdp_with_bundle);
2310 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2311 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2312 group.AddContentName(kAudioContentName);
2313 group.AddContentName(kVideoContentName);
2314 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002315 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 jdesc_.session_version()));
2317 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2318}
2319
2320TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002321 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002323 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002325 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002327 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002328 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002330 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002332 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 jdesc_.session_version()));
2334 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002338 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002340 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002342 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002344 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 &sdp_with_ice_options);
2346 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2347 std::vector<std::string> transport_options;
2348 transport_options.push_back(kIceOption3);
2349 transport_options.push_back(kIceOption1);
2350 AddIceOptions(kAudioContentName, transport_options);
2351 transport_options.clear();
2352 transport_options.push_back(kIceOption3);
2353 transport_options.push_back(kIceOption2);
2354 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002355 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 jdesc_.session_version()));
2357 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2358}
2359
2360TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2361 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002362 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 std::string sdp_with_ufrag_pwd = kSdpFullString;
2364 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2365 // Add session level ufrag and pwd
2366 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002367 "a=ice-pwd:session+level+icepwd\r\n"
2368 "a=ice-ufrag:session+level+iceufrag\r\n",
2369 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002371 InjectAfter(
2372 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2374 &sdp_with_ufrag_pwd);
2375 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002376 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2377 "media+level+icepwd"));
2378 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2379 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2381 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2382}
2383
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002385 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386}
2387
2388TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002389 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390}
2391
2392TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002393 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394}
2395
2396TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2397 EXPECT_TRUE(TestDeserializeRejected(true, false));
2398}
2399
2400TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2401 EXPECT_TRUE(TestDeserializeRejected(false, true));
2402}
2403
2404TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2405 EXPECT_TRUE(TestDeserializeRejected(true, true));
2406}
2407
2408// Tests that we can still handle the sdp uses mslabel and label instead of
2409// msid for backward compatibility.
2410TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002411 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002412 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 std::string sdp_without_msid = kSdpFullString;
2414 Replace("msid", "xmsid", &sdp_without_msid);
2415 // Deserialize
2416 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2417 // Verify
2418 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2419}
2420
2421TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2422 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2423
2424 std::string sdp = kSdpOneCandidate;
2425 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2426 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2427 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2428 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002429 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
2431 // Candidate line without generation extension.
2432 sdp = kSdpOneCandidate;
2433 Replace(" generation 2", "", &sdp);
2434 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2435 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2436 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2437 Candidate expected = jcandidate_->candidate();
2438 expected.set_generation(0);
2439 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2440
honghaiza0c44ea2016-03-23 16:07:48 -07002441 // Candidate with network id and/or cost.
2442 sdp = kSdpOneCandidate;
2443 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2444 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2445 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2446 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2447 expected = jcandidate_->candidate();
2448 expected.set_network_id(2);
2449 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2450 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2451 // Add network cost
2452 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2453 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2454 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2455 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2456
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002457 sdp = kSdpTcpActiveCandidate;
2458 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2459 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002460 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002461 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2462 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2463 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002464 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2465 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002466 EXPECT_TRUE(
2467 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002468 sdp = kSdpTcpPassiveCandidate;
2469 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2470 sdp = kSdpTcpSOCandidate;
2471 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472}
2473
2474// This test verifies the deserialization of candidate-attribute
2475// as per RFC 5245. Candiate-attribute will be of the format
2476// candidate:<blah>. This format will be used when candidates
2477// are trickled.
2478TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2479 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2480
2481 std::string candidate_attribute = kRawCandidate;
2482 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2483 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2484 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2485 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2486 EXPECT_EQ(2u, jcandidate.candidate().generation());
2487
2488 // Candidate line without generation extension.
2489 candidate_attribute = kRawCandidate;
2490 Replace(" generation 2", "", &candidate_attribute);
2491 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2492 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2493 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2494 Candidate expected = jcandidate_->candidate();
2495 expected.set_generation(0);
2496 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2497
2498 // Candidate line without candidate:
2499 candidate_attribute = kRawCandidate;
2500 Replace("candidate:", "", &candidate_attribute);
2501 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2502
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002503 // Candidate line with IPV6 address.
2504 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2505}
2506
2507// This test verifies that the deserialization of an invalid candidate string
2508// fails.
2509TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002510 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002511
2512 std::string candidate_attribute = kRawCandidate;
2513 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002515
2516 candidate_attribute = kSdpOneCandidate;
2517 candidate_attribute.replace(0, 1, "x");
2518 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2519
2520 candidate_attribute = kRawCandidate;
2521 candidate_attribute.append("\r\n");
2522 candidate_attribute.append(kRawCandidate);
2523 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2524
2525 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526}
2527
2528TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2529 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002530 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2532
2533 std::string sdp_with_data = kSdpString;
2534 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002535 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536
2537 // Deserialize
2538 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2539 // Verify
2540 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2541}
2542
2543TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002544 bool use_sctpmap = true;
2545 AddSctpDataChannel(use_sctpmap);
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(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002551 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552
lally@webrtc.org36300852015-02-24 20:19:35 +00002553 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2554 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2555 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2556
2557 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002558 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2559 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002560 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2561 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2562
2563 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002564 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2565 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2567 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2568}
2569
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002570TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002571 bool use_sctpmap = false;
2572 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002573 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002574 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2575
2576 std::string sdp_with_data = kSdpString;
2577 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002578 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002579
lally@webrtc.org36300852015-02-24 20:19:35 +00002580 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002581 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2582 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002583
lally@webrtc.org36300852015-02-24 20:19:35 +00002584 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002585 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2586 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002587 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2588 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002589
lally@webrtc.org36300852015-02-24 20:19:35 +00002590 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002591 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2592 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002593 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2594 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2595}
2596
lally69f57602015-10-08 10:15:04 -07002597TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002598 bool use_sctpmap = false;
2599 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002600 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002601 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2602
2603 std::string sdp_with_data = kSdpString;
2604 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002605 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002606
2607 // Verify with DTLS/SCTP.
2608 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2609 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2610
2611 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002612 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2613 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002614 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2615 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2616
2617 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002618 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2619 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002620 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2621 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2622}
2623
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002624// Test to check the behaviour if sctp-port is specified
2625// on the m= line and in a=sctp-port.
2626TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002627 bool use_sctpmap = true;
2628 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002629 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002630 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2631
2632 std::string sdp_with_data = kSdpString;
2633 // Append m= attributes
2634 sdp_with_data.append(kSdpSctpDataChannelString);
2635 // Append a=sctp-port attribute
2636 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002637 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002638
2639 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2640}
2641
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002642// For crbug/344475.
2643TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2644 std::string sdp_with_data = kSdpString;
2645 sdp_with_data.append(kSdpSctpDataChannelString);
2646 // Remove the "\n" at the end.
2647 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002648 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002649
2650 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2651 // No crash is a pass.
2652}
2653
Steve Anton36b29d12017-10-30 09:57:42 -07002654void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002655 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002656 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002657 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002658 DataContentDescription* dcdesc =
2659 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002660 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002661 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002662 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002663 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002664 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002665
2666 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002667 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002668 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002669}
2670
2671TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2672 bool use_sctpmap = true;
2673 AddSctpDataChannel(use_sctpmap);
2674
2675 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002676 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002677 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002678
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002679 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002680 std::string sdp_with_data = kSdpString;
2681 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002682 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2683 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2684 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002685 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002686
2687 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2688 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002689}
2690
2691TEST_F(WebRtcSdpTest,
2692 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2693 bool use_sctpmap = false;
2694 AddSctpDataChannel(use_sctpmap);
2695
Steve Antona3a92c22017-12-07 10:27:41 -08002696 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002697 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002698
2699 // We need to test the deserialized JsepSessionDescription from
2700 // kSdpSctpDataChannelStringWithSctpPort for
2701 // draft-ietf-mmusic-sctp-sdp-07
2702 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002703 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002704 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002705 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2706 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2707 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002708 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002709
2710 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2711 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002712}
2713
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002714TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002715 // We want to test that deserializing data content limits bandwidth
2716 // settings (it should never be greater than the default).
2717 // This should prevent someone from using unlimited data bandwidth through
2718 // JS and "breaking the Internet".
2719 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002720 std::string sdp_with_bandwidth = kSdpString;
2721 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002722 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002723 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002724 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002725
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002726 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2727}
2728
2729TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002730 bool use_sctpmap = true;
2731 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002732 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002733 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002734 dcd->set_bandwidth(100 * 1000);
2735 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2736
2737 std::string sdp_with_bandwidth = kSdpString;
2738 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002739 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002740 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002741 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002742
2743 // SCTP has congestion control, so we shouldn't limit the bandwidth
2744 // as we do for RTP.
2745 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002746 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2747}
2748
Yves Gerey665174f2018-06-19 15:03:05 +02002749class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2750 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002751
2752TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002753 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002754 bool encrypted = GetParam();
2755 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756}
2757
Yves Gerey665174f2018-06-19 15:03:05 +02002758TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002759 bool encrypted = GetParam();
2760 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761}
2762
Yves Gerey665174f2018-06-19 15:03:05 +02002763TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002764 bool encrypted = GetParam();
2765 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766}
2767
jbauch5869f502017-06-29 12:31:36 -07002768INSTANTIATE_TEST_CASE_P(Encrypted,
2769 WebRtcSdpExtmapTest,
2770 ::testing::Values(false, true));
2771
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002772TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002773 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002774 std::string sdp = kSdpFullString;
2775 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2776 // Deserialize
2777 SdpParseError error;
2778 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002779 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002780 EXPECT_EQ(lastline, error.line);
2781 EXPECT_EQ("Invalid SDP line.", error.description);
2782}
2783
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002784TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2785 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2786 std::string new_sdp = kSdpOneCandidate;
2787 Replace("udp", "unsupported_transport", &new_sdp);
2788 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2789 new_sdp = kSdpOneCandidate;
2790 Replace("udp", "uDP", &new_sdp);
2791 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2792 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2793 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2794 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2795}
2796
honghaiza54a0802015-12-16 18:37:23 -08002797TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002798 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002799 EXPECT_TRUE(
2800 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002801 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2802 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2803 Candidate ref_candidate = jcandidate_->candidate();
2804 ref_candidate.set_username("user_rtp");
2805 ref_candidate.set_password("password_rtp");
2806 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2807}
2808
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002809TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002810 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002811
2812 // Deserialize
2813 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2814
2815 // Verify
2816 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002817 jdesc.description()
2818 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2819 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002820 EXPECT_TRUE(audio->conference_mode());
2821
2822 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002823 jdesc.description()
2824 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2825 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002826 EXPECT_TRUE(video->conference_mode());
2827}
2828
deadbeefd45aea82017-09-16 01:24:29 -07002829TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002830 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002831
2832 // We tested deserialization already above, so just test that if we serialize
2833 // and deserialize the flag doesn't disappear.
2834 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002835 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002836 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2837
2838 // Verify.
2839 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002840 jdesc.description()
2841 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2842 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002843 EXPECT_TRUE(audio->conference_mode());
2844
2845 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002846 jdesc.description()
2847 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2848 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002849 EXPECT_TRUE(video->conference_mode());
2850}
2851
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2853 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002854 const char kSdpEmptyType[] = " =candidate";
2855 const char kSdpEqualAsPlus[] = "a+candidate";
2856 const char kSdpSpaceAfterEqual[] = "a= candidate";
2857 const char kSdpUpperType[] = "A=candidate";
2858 const char kSdpEmptyLine[] = "";
2859 const char kSdpMissingValue[] = "a=";
2860
Yves Gerey665174f2018-06-19 15:03:05 +02002861 const char kSdpBrokenFingerprint[] =
2862 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 "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 +02002864 const char kSdpExtraField[] =
2865 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 "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 +02002867 const char kSdpMissingSpace[] =
2868 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 "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 +00002870 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002871 const char kSdpMd5[] =
2872 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002873 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874
2875 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002876 ExpectParseFailure("v=", kSdpDestroyer);
2877 ExpectParseFailure("o=", kSdpDestroyer);
2878 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002880 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881
2882 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002883 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2884 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885
2886 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002887 ExpectParseFailure("a=candidate", kSdpEmptyType);
2888 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2889 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2890 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891
2892 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2893 // because it's orthogonal to what we are replacing and hence
2894 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002895 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2896 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2897 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2898 ExpectParseFailure("a=sendrecv", kSdpMd5);
2899
2900 // Empty Line
2901 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2902 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002903}
2904
2905TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2906 // ssrc
2907 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002908 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002909 // crypto
2910 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2911 // rtpmap
2912 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2913 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2914 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2915 // candidate
2916 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2917 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2918 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2919 ExpectParseFailure("rport 2346", "rport badvalue");
2920 ExpectParseFailure("rport 2346 generation 2",
2921 "rport 2346 generation badvalue");
2922 // m line
2923 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2924 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2925
2926 // bandwidth
2927 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002928 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002929 // rtcp-fb
2930 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2931 "a=rtcp-fb:badvalue nack\r\n",
2932 "a=rtcp-fb:badvalue nack");
2933 // extmap
2934 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2935 "a=extmap:badvalue http://example.com\r\n",
2936 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002937}
2938
2939TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002940 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941
2942 const char kSdpWithReorderedPlTypesString[] =
2943 "v=0\r\n"
2944 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2945 "s=-\r\n"
2946 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002947 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02002948 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2949 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002951 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952
2953 // Deserialize
2954 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2955
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002957 GetFirstAudioContentDescription(jdesc_output.description());
2958 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002960 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2961 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962 EXPECT_EQ(104, acd->codecs()[0].id);
2963}
2964
2965TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08002966 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 CodecParams params;
2968 params.max_ptime = 40;
2969 params.ptime = 30;
2970 params.min_ptime = 10;
2971 params.sprop_stereo = 1;
2972 params.stereo = 1;
2973 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002974 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08002976 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002977}
2978
2979TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2980 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08002981 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08002983 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984}
2985
2986TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2987 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08002988 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08002990 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991}
2992
2993TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08002994 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995
2996 const char kSdpWithFmtpString[] =
2997 "v=0\r\n"
2998 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2999 "s=-\r\n"
3000 "t=0 0\r\n"
3001 "m=video 3457 RTP/SAVPF 120\r\n"
3002 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003003 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3004
3005 // Deserialize
3006 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003007 EXPECT_TRUE(
3008 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003009
Donald Curtis0e07f922015-05-15 09:21:23 -07003010 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003011 GetFirstVideoContentDescription(jdesc_output.description());
3012 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003013 ASSERT_FALSE(vcd->codecs().empty());
3014 cricket::VideoCodec vp8 = vcd->codecs()[0];
3015 EXPECT_EQ("VP8", vp8.name);
3016 EXPECT_EQ(120, vp8.id);
3017 cricket::CodecParameterMap::iterator found =
3018 vp8.params.find("x-google-min-bitrate");
3019 ASSERT_TRUE(found != vp8.params.end());
3020 EXPECT_EQ(found->second, "10");
3021 found = vp8.params.find("x-google-max-quantization");
3022 ASSERT_TRUE(found != vp8.params.end());
3023 EXPECT_EQ(found->second, "40");
3024}
3025
johan2d8d23e2016-06-03 01:22:42 -07003026TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003027 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003028
3029 const char kSdpWithFmtpString[] =
3030 "v=0\r\n"
3031 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3032 "s=-\r\n"
3033 "t=0 0\r\n"
3034 "m=video 49170 RTP/AVP 98\r\n"
3035 "a=rtpmap:98 H264/90000\r\n"
3036 "a=fmtp:98 profile-level-id=42A01E; "
3037 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3038
3039 // Deserialize.
3040 SdpParseError error;
3041 EXPECT_TRUE(
3042 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3043
johan2d8d23e2016-06-03 01:22:42 -07003044 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003045 GetFirstVideoContentDescription(jdesc_output.description());
3046 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003047 ASSERT_FALSE(vcd->codecs().empty());
3048 cricket::VideoCodec h264 = vcd->codecs()[0];
3049 EXPECT_EQ("H264", h264.name);
3050 EXPECT_EQ(98, h264.id);
3051 cricket::CodecParameterMap::const_iterator found =
3052 h264.params.find("profile-level-id");
3053 ASSERT_TRUE(found != h264.params.end());
3054 EXPECT_EQ(found->second, "42A01E");
3055 found = h264.params.find("sprop-parameter-sets");
3056 ASSERT_TRUE(found != h264.params.end());
3057 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3058}
3059
Donald Curtis0e07f922015-05-15 09:21:23 -07003060TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003061 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003062
3063 const char kSdpWithFmtpString[] =
3064 "v=0\r\n"
3065 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3066 "s=-\r\n"
3067 "t=0 0\r\n"
3068 "m=video 3457 RTP/SAVPF 120\r\n"
3069 "a=rtpmap:120 VP8/90000\r\n"
3070 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071
3072 // Deserialize
3073 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003074 EXPECT_TRUE(
3075 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003078 GetFirstVideoContentDescription(jdesc_output.description());
3079 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080 ASSERT_FALSE(vcd->codecs().empty());
3081 cricket::VideoCodec vp8 = vcd->codecs()[0];
3082 EXPECT_EQ("VP8", vp8.name);
3083 EXPECT_EQ(120, vp8.id);
3084 cricket::CodecParameterMap::iterator found =
3085 vp8.params.find("x-google-min-bitrate");
3086 ASSERT_TRUE(found != vp8.params.end());
3087 EXPECT_EQ(found->second, "10");
3088 found = vp8.params.find("x-google-max-quantization");
3089 ASSERT_TRUE(found != vp8.params.end());
3090 EXPECT_EQ(found->second, "40");
3091}
3092
ossuaa4b0772017-01-30 07:41:18 -08003093TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003094 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003095
3096 cricket::AudioCodecs codecs = acd->codecs();
3097 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3098 acd->set_codecs(codecs);
3099
Yves Gerey665174f2018-06-19 15:03:05 +02003100 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003101 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003102 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003103 std::string sdp_with_fmtp = kSdpFullString;
3104 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3105 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3106 &sdp_with_fmtp);
3107 EXPECT_EQ(sdp_with_fmtp, message);
3108}
3109
3110TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003111 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003112
3113 cricket::AudioCodecs codecs = acd->codecs();
3114 codecs[0].params["stereo"] = "1";
3115 acd->set_codecs(codecs);
3116
Yves Gerey665174f2018-06-19 15:03:05 +02003117 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003118 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003119 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003120 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003121 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003122 &sdp_with_fmtp);
3123 EXPECT_EQ(sdp_with_fmtp, message);
3124}
3125
3126TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
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["ptime"] = "20";
3131 codecs[0].params["maxptime"] = "120";
3132 acd->set_codecs(codecs);
3133
Yves Gerey665174f2018-06-19 15:03:05 +02003134 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003135 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003136 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003137 std::string sdp_with_fmtp = kSdpFullString;
3138 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3139 "a=maxptime:120\r\n" // No comma here. String merging!
3140 "a=ptime:20\r\n",
3141 &sdp_with_fmtp);
3142 EXPECT_EQ(sdp_with_fmtp, message);
3143}
3144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003146 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147
3148 cricket::VideoCodecs codecs = vcd->codecs();
3149 codecs[0].params["x-google-min-bitrate"] = "10";
3150 vcd->set_codecs(codecs);
3151
Yves Gerey665174f2018-06-19 15:03:05 +02003152 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003154 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003155 std::string sdp_with_fmtp = kSdpFullString;
3156 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003157 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003158 EXPECT_EQ(sdp_with_fmtp, message);
3159}
3160
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003161TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3162 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003163 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164 std::string sdp_with_icelite = kSdpFullString;
3165 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3166 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3167 const cricket::TransportInfo* tinfo1 =
3168 desc->GetTransportInfoByName("audio_content_name");
3169 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3170 const cricket::TransportInfo* tinfo2 =
3171 desc->GetTransportInfoByName("video_content_name");
3172 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003173
3174 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003175 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3177 desc = jdesc_with_icelite.description();
3178 const cricket::TransportInfo* atinfo =
3179 desc->GetTransportInfoByName("audio_content_name");
3180 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3181 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003182 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003184
3185 // Now that we know deserialization works, we can use TestSerialize to test
3186 // serialization.
3187 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188}
3189
3190// Verifies that the candidates in the input SDP are parsed and serialized
3191// correctly in the output SDP.
3192TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3193 std::string sdp_with_data = kSdpString;
3194 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003195 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196
3197 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003198 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003200
3201TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3202 AddFingerprint();
3203 TransportInfo audio_transport_info =
3204 *(desc_.GetTransportInfoByName(kAudioContentName));
3205 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3206 audio_transport_info.description.connection_role);
3207 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003208 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003209
3210 TransportInfo video_transport_info =
3211 *(desc_.GetTransportInfoByName(kVideoContentName));
3212 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3213 video_transport_info.description.connection_role);
3214 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003215 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003216
3217 desc_.RemoveTransportInfoByName(kAudioContentName);
3218 desc_.RemoveTransportInfoByName(kVideoContentName);
3219
3220 desc_.AddTransportInfo(audio_transport_info);
3221 desc_.AddTransportInfo(video_transport_info);
3222
Yves Gerey665174f2018-06-19 15:03:05 +02003223 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003224 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003225 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003226 std::string sdp_with_dtlssetup = kSdpFullString;
3227
3228 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003229 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3230 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003231 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003232 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003233 EXPECT_EQ(sdp_with_dtlssetup, message);
3234}
3235
3236TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003237 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003238 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003239 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003240 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3241 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3242 const cricket::TransportInfo* atinfo =
3243 desc->GetTransportInfoByName("audio_content_name");
3244 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3245 atinfo->description.connection_role);
3246 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003247 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003248 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3249 vtinfo->description.connection_role);
3250}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003251
3252// Verifies that the order of the serialized m-lines follows the order of the
3253// ContentInfo in SessionDescription, and vise versa for deserialization.
3254TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003255 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003256 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3257 kSdpSctpDataChannelString};
3258 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3259 cricket::MEDIA_TYPE_VIDEO,
3260 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003261
3262 // Verifies all 6 permutations.
3263 for (size_t i = 0; i < 6; ++i) {
3264 size_t media_content_in_sdp[3];
3265 // The index of the first media content.
3266 media_content_in_sdp[0] = i / 2;
3267 // The index of the second media content.
3268 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3269 // The index of the third media content.
3270 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3271
3272 std::string sdp_string = kSdpSessionString;
3273 for (size_t i = 0; i < 3; ++i)
3274 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3275
3276 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3277 cricket::SessionDescription* desc = jdesc.description();
3278 EXPECT_EQ(3u, desc->contents().size());
3279
3280 for (size_t i = 0; i < 3; ++i) {
3281 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003282 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003283 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3284 }
3285
Steve Antone831b8c2018-02-01 12:22:16 -08003286 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003287 EXPECT_EQ(sdp_string, serialized_sdp);
3288 }
3289}
deadbeef9d3584c2016-02-16 17:54:10 -08003290
deadbeef25ed4352016-12-12 18:37:36 -08003291TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3292 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003293 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003294 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003295 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3296 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3297}
3298
deadbeef12771a12017-01-03 13:53:47 -08003299// The semantics of "a=bundle-only" are only defined when it's used in
3300// combination with a 0 port on the m= line. We should ignore it if used with a
3301// nonzero port.
3302TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3303 // Make the base bundle-only description but unset the bundle-only flag.
3304 MakeBundleOnlyDescription();
3305 jdesc_.description()->contents()[1].bundle_only = false;
3306
3307 std::string modified_sdp = kBundleOnlySdpFullString;
3308 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003309 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003310 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3311 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003312}
3313
3314TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3315 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003316 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003317}
3318
deadbeef9d3584c2016-02-16 17:54:10 -08003319TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3320 MakePlanBDescription();
3321
Steve Antona3a92c22017-12-07 10:27:41 -08003322 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003323 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3324
3325 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3326}
3327
3328TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3329 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003330 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003331}
3332
3333TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3334 MakeUnifiedPlanDescription();
3335
Steve Antona3a92c22017-12-07 10:27:41 -08003336 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003337 EXPECT_TRUE(
3338 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3339
3340 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3341}
3342
3343TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3344 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003345 TestSerialize(jdesc_);
3346}
3347
Seth Hampson5b4f0752018-04-02 16:31:36 -07003348// This tests deserializing a Unified Plan SDP that is compatible with both
3349// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3350// with no stream ids and multiple stream ids. For parsing this, the Unified
3351// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3352// lines do not support multiple stream ids and no stream ids.
3353TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3354 MakeUnifiedPlanDescriptionMultipleStreamIds();
3355
3356 JsepSessionDescription deserialized_description(kDummyType);
3357 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3358 &deserialized_description));
3359
3360 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3361}
3362
3363TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3364 MakeUnifiedPlanDescriptionMultipleStreamIds();
3365 TestSerialize(jdesc_);
3366}
3367
Seth Hampson5897a6e2018-04-03 11:16:33 -07003368// This tests that a Unified Plan SDP with no a=ssrc lines is
3369// serialized/deserialized appropriately. In this case the
3370// MediaContentDescription will contain a StreamParams object that doesn't have
3371// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3372// SSRC lines.
3373TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3374 MakeUnifiedPlanDescription();
3375 RemoveSsrcSignalingFromStreamParams();
3376 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3377 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3378
3379 JsepSessionDescription deserialized_description(kDummyType);
3380 EXPECT_TRUE(
3381 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3382 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3383}
3384
3385TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3386 MakeUnifiedPlanDescription();
3387 RemoveSsrcSignalingFromStreamParams();
3388
3389 TestSerialize(jdesc_);
3390}
3391
Steve Antone831b8c2018-02-01 12:22:16 -08003392TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3393 JsepSessionDescription jsep_desc(kDummyType);
3394 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3395 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3396}
3397
3398TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3399 JsepSessionDescription jsep_desc(kDummyType);
3400 std::string sdp = kSdpSessionString;
3401 sdp += kSdpSctpDataChannelString;
3402 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3403 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3404}
3405
3406TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3407 JsepSessionDescription jsep_desc(kDummyType);
3408 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3409 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3410 jsep_desc.description()->msid_signaling());
3411}
3412
3413TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3414 JsepSessionDescription jsep_desc(kDummyType);
3415 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3416 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3417 jsep_desc.description()->msid_signaling());
3418}
3419
3420const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3421const char kSsrcAttributeMsidLine[] =
3422 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3423
3424TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3425 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3426 std::string sdp = webrtc::SdpSerialize(jdesc_);
3427
3428 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3429 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3430}
3431
3432TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3433 jdesc_.description()->set_msid_signaling(
3434 cricket::kMsidSignalingSsrcAttribute);
3435 std::string sdp = webrtc::SdpSerialize(jdesc_);
3436
3437 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3438 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3439}
3440
3441TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3442 jdesc_.description()->set_msid_signaling(
3443 cricket::kMsidSignalingMediaSection |
3444 cricket::kMsidSignalingSsrcAttribute);
3445 std::string sdp = webrtc::SdpSerialize(jdesc_);
3446
3447 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3448 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003449}
deadbeef7e146cb2016-09-28 10:04:34 -07003450
3451// Regression test for heap overflow bug:
3452// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3453TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003454 // The issue occurs when the sctp-port attribute is found in a video
3455 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003456 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003457 "v=0\r\n"
3458 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3459 "s=-\r\n"
3460 "t=0 0\r\n"
3461 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3462 "a=sctp-port 5000\r\n"
3463 "a=fmtp:108 foo=10\r\n";
3464
3465 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3466 "sctp-port");
3467}
deadbeefb2362572016-12-13 16:37:06 -08003468
3469// Regression test for integer overflow bug:
3470// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3471TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003472 // Bandwidth attribute is the max signed 32-bit int, which will get
3473 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003474 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003475 "v=0\r\n"
3476 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3477 "s=-\r\n"
3478 "t=0 0\r\n"
3479 "m=video 3457 RTP/SAVPF 120\r\n"
3480 "b=AS:2147483647\r\n"
3481 "foo=fail\r\n";
3482
3483 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3484}
deadbeef7bcdb692017-01-20 12:43:58 -08003485
deadbeefbc88c6b2017-08-02 11:26:34 -07003486// Similar to the above, except that negative values are illegal, not just
3487// error-prone as large values are.
3488// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3489TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3490 static const char kSdpWithNegativeBandwidth[] =
3491 "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:-1000\r\n";
3497
3498 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3499}
3500
deadbeef3e8016e2017-08-03 17:49:30 -07003501// An exception to the above rule: a value of -1 for b=AS should just be
3502// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3503// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3504// limit", but this is now what ommitting the attribute entirely will do, so
3505// ignoring it will have the intended effect.
3506TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3507 static const char kSdpWithBandwidthOfNegativeOne[] =
3508 "v=0\r\n"
3509 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3510 "s=-\r\n"
3511 "t=0 0\r\n"
3512 "m=video 3457 RTP/SAVPF 120\r\n"
3513 "b=AS:-1\r\n";
3514
Steve Antona3a92c22017-12-07 10:27:41 -08003515 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003516 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003517 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003518 GetFirstVideoContentDescription(jdesc_output.description());
3519 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003520 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3521}
3522
deadbeef7bcdb692017-01-20 12:43:58 -08003523// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3524// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3525// Regression test for:
3526// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3527TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3528 // Important piece is "ufrag foo pwd bar".
3529 static const char kSdpWithIceCredentialsInCandidateString[] =
3530 "v=0\r\n"
3531 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3532 "s=-\r\n"
3533 "t=0 0\r\n"
3534 "m=audio 9 RTP/SAVPF 111\r\n"
3535 "c=IN IP4 0.0.0.0\r\n"
3536 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3537 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3538 "a=rtpmap:111 opus/48000/2\r\n"
3539 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3540 "generation 2 ufrag foo pwd bar\r\n";
3541
Steve Antona3a92c22017-12-07 10:27:41 -08003542 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003543 EXPECT_TRUE(
3544 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3545 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3546 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003547 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003548 cricket::Candidate c = candidates->at(0)->candidate();
3549 EXPECT_EQ("ufrag_voice", c.username());
3550 EXPECT_EQ("pwd_voice", c.password());
3551}
deadbeef90f1e1e2017-02-10 12:35:05 -08003552
3553// Test that SDP with an invalid port number in "a=candidate" lines is
3554// rejected, without crashing.
3555// Regression test for:
3556// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3557TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3558 static const char kSdpWithInvalidCandidatePort[] =
3559 "v=0\r\n"
3560 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3561 "s=-\r\n"
3562 "t=0 0\r\n"
3563 "m=audio 9 RTP/SAVPF 111\r\n"
3564 "c=IN IP4 0.0.0.0\r\n"
3565 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3566 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3567 "a=rtpmap:111 opus/48000/2\r\n"
3568 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3569 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3570
Steve Antona3a92c22017-12-07 10:27:41 -08003571 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003572 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3573}
deadbeefa4549d62017-02-10 17:26:22 -08003574
3575// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3576// Regression test for:
3577// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3578TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3579 static const char kSdpWithMissingTrackId[] =
3580 "v=0\r\n"
3581 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3582 "s=-\r\n"
3583 "t=0 0\r\n"
3584 "m=audio 9 RTP/SAVPF 111\r\n"
3585 "c=IN IP4 0.0.0.0\r\n"
3586 "a=rtpmap:111 opus/48000/2\r\n"
3587 "a=msid:stream_id \r\n";
3588
Steve Antona3a92c22017-12-07 10:27:41 -08003589 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003590 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3591}
3592
3593TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3594 static const char kSdpWithMissingStreamId[] =
3595 "v=0\r\n"
3596 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3597 "s=-\r\n"
3598 "t=0 0\r\n"
3599 "m=audio 9 RTP/SAVPF 111\r\n"
3600 "c=IN IP4 0.0.0.0\r\n"
3601 "a=rtpmap:111 opus/48000/2\r\n"
3602 "a=msid: track_id\r\n";
3603
Steve Antona3a92c22017-12-07 10:27:41 -08003604 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003605 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3606}
zhihuang38989e52017-03-21 11:04:53 -07003607
3608// Tests that if both session-level address and media-level address exist, use
3609// the media-level address.
3610TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003611 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003612
3613 // Sesssion-level address.
3614 std::string sdp = kSdpFullString;
3615 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3616 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3617
3618 const auto& content1 = jsep_desc.description()->contents()[0];
3619 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003620 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003621 const auto& content2 = jsep_desc.description()->contents()[1];
3622 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003623 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003624}
3625
3626// Tests that the session-level connection address will be used if the media
3627// level-addresses are not specified.
3628TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003629 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003630
3631 // Sesssion-level address.
3632 std::string sdp = kSdpString;
3633 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3634 // Remove the media level addresses.
3635 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3636 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3637 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3638
3639 const auto& content1 = jsep_desc.description()->contents()[0];
3640 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003641 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003642 const auto& content2 = jsep_desc.description()->contents()[1];
3643 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003644 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003645}
3646
3647TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003648 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003649
3650 std::string sdp = kSdpString;
3651 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3652 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3653 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3654 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3655 &sdp);
3656 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3657 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3658 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3659 &sdp);
3660 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3661 const auto& content1 = jsep_desc.description()->contents()[0];
3662 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003663 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003664 const auto& content2 = jsep_desc.description()->contents()[1];
3665 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003666 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003667}
3668
3669// Test that the invalid or unsupprted connection data cannot be parsed.
3670TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003671 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003672 std::string sdp = kSdpString;
3673 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3674
3675 // Unsupported multicast IPv4 address.
3676 sdp = kSdpFullString;
3677 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3678 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3679
3680 // Unsupported multicast IPv6 address.
3681 sdp = kSdpFullString;
3682 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3683 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3684
3685 // Mismatched address type.
3686 sdp = kSdpFullString;
3687 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3688 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3689
3690 sdp = kSdpFullString;
3691 Replace("c=IN IP4 74.125.224.39\r\n",
3692 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3693 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3694}
3695
3696TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003697 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003698 MakeDescriptionWithoutCandidates(&expected_jsep);
3699 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003700 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003701 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003702 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003703 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003704 auto audio_desc = jdesc.description()
3705 ->GetContentByName(kAudioContentName)
3706 ->media_description();
3707 auto video_desc = jdesc.description()
3708 ->GetContentByName(kVideoContentName)
3709 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003710 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3711 audio_desc->connection_address().ToString());
3712 EXPECT_EQ(video_desc_->connection_address().ToString(),
3713 video_desc->connection_address().ToString());
3714}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003715
3716// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3717// used (i.e., a single space as the session name)." So we should accept that.
3718TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3719 JsepSessionDescription jsep_desc(kDummyType);
3720 std::string sdp = kSdpString;
3721 Replace("s=-\r\n", "s= \r\n", &sdp);
3722 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3723}