blob: c268b04ae1c8d156d15219d40c2826bfd20c6ba5 [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"
Patrik Höglundaba85d12017-11-28 15:46:08 +010019#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "p2p/base/p2pconstants.h"
21#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";
89static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91static const int kExtmapId = 1;
92static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -070097static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
Peter Boström0c4e06b2015-10-07 12:23:21 +0200101static const uint8_t kIdentityDigest[] = {
102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
lally@webrtc.org34807282015-02-24 20:19:39 +0000105static const char kDtlsSctp[] = "DTLS/SCTP";
106static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
107static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000108
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109struct CodecParams {
110 int max_ptime;
111 int ptime;
112 int min_ptime;
113 int sprop_stereo;
114 int stereo;
115 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000116 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117};
118
deadbeef9d3584c2016-02-16 17:54:10 -0800119// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
120// instead of "a=crypto", and have an explicit test for adding "a=crypto".
121// Currently it's the other way around.
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123// Reference sdp string
124static const char kSdpFullString[] =
125 "v=0\r\n"
126 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800129 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
131 "c=IN IP4 74.125.127.126\r\n"
132 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
133 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
142 "raddr 192.168.1.5 rport 2346 "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
145 "raddr 192.168.1.5 rport 2348 "
146 "generation 2\r\n"
147 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
148 "a=mid:audio_content_name\r\n"
149 "a=sendrecv\r\n"
150 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800151 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
153 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
154 "dummy_session_params\r\n"
155 "a=rtpmap:111 opus/48000/2\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000157 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 "a=ssrc:1 cname:stream_1_cname\r\n"
159 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
160 "a=ssrc:1 mslabel:local_stream_1\r\n"
161 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 "m=video 3457 RTP/SAVPF 120\r\n"
163 "c=IN IP4 74.125.224.39\r\n"
164 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
165 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
172 "generation 2\r\n"
173 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
174 "generation 2\r\n"
175 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
176 "generation 2\r\n"
177 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
178 "a=mid:video_content_name\r\n"
179 "a=sendrecv\r\n"
180 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
181 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
182 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800183 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 "a=ssrc:2 cname:stream_1_cname\r\n"
185 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
186 "a=ssrc:2 mslabel:local_stream_1\r\n"
187 "a=ssrc:2 label:video_track_id_1\r\n"
188 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800189 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800191 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192
193// SDP reference string without the candidates.
194static const char kSdpString[] =
195 "v=0\r\n"
196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
197 "s=-\r\n"
198 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800199 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000200 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000201 "c=IN IP4 0.0.0.0\r\n"
202 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
204 "a=mid:audio_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800207 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
209 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
210 "dummy_session_params\r\n"
211 "a=rtpmap:111 opus/48000/2\r\n"
212 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000213 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:1 cname:stream_1_cname\r\n"
215 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
216 "a=ssrc:1 mslabel:local_stream_1\r\n"
217 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000218 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000219 "c=IN IP4 0.0.0.0\r\n"
220 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
222 "a=mid:video_content_name\r\n"
223 "a=sendrecv\r\n"
224 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
225 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
226 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800227 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 "a=ssrc:2 cname:stream_1_cname\r\n"
229 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
230 "a=ssrc:2 mslabel:local_stream_1\r\n"
231 "a=ssrc:2 label:video_track_id_1\r\n"
232 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800233 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800235 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
237static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000238 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000239 "c=IN IP4 0.0.0.0\r\n"
240 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 "a=ice-ufrag:ufrag_data\r\n"
242 "a=ice-pwd:pwd_data\r\n"
243 "a=mid:data_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
247 "a=rtpmap:101 google-data/90000\r\n"
248 "a=ssrc:10 cname:data_channel_cname\r\n"
249 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
250 "a=ssrc:10 mslabel:data_channel\r\n"
251 "a=ssrc:10 label:data_channeld0\r\n";
252
253static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000254 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000255 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 "a=ice-ufrag:ufrag_data\r\n"
257 "a=ice-pwd:pwd_data\r\n"
258 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000259 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000261// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000262static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port 5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
lally69f57602015-10-08 10:15:04 -0700271static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
272 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
273 "a=max-message-size=100000\r\n"
274 "a=sctp-port:5000\r\n"
275 "c=IN IP4 0.0.0.0\r\n"
276 "a=ice-ufrag:ufrag_data\r\n"
277 "a=ice-pwd:pwd_data\r\n"
278 "a=mid:data_content_name\r\n";
279
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280static const char kSdpSctpDataChannelWithCandidatesString[] =
281 "m=application 2345 DTLS/SCTP 5000\r\n"
282 "c=IN IP4 74.125.127.126\r\n"
283 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
284 "generation 2\r\n"
285 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
286 "generation 2\r\n"
287 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
288 "raddr 192.168.1.5 rport 2346 "
289 "generation 2\r\n"
290 "a=ice-ufrag:ufrag_data\r\n"
291 "a=ice-pwd:pwd_data\r\n"
292 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000293 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000295static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000296 "v=0\r\n"
297 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
298 "s=-\r\n"
299 "t=0 0\r\n"
300 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000301 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000302 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000303 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000304 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000306 "a=x-google-flag:conference\r\n";
307
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000308static const char kSdpSessionString[] =
309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS local_stream\r\n";
314
315static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000316 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000317 "c=IN IP4 0.0.0.0\r\n"
318 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000319 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
320 "a=mid:audio_content_name\r\n"
321 "a=sendrecv\r\n"
322 "a=rtpmap:111 opus/48000/2\r\n"
323 "a=ssrc:1 cname:stream_1_cname\r\n"
324 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
325 "a=ssrc:1 mslabel:local_stream\r\n"
326 "a=ssrc:1 label:audio_track_id_1\r\n";
327
328static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000329 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000332 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
333 "a=mid:video_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:120 VP8/90000\r\n"
336 "a=ssrc:2 cname:stream_1_cname\r\n"
337 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
338 "a=ssrc:2 mslabel:local_stream\r\n"
339 "a=ssrc:2 label:video_track_id_1\r\n";
340
deadbeef25ed4352016-12-12 18:37:36 -0800341// Reference sdp string using bundle-only.
342static const char kBundleOnlySdpFullString[] =
343 "v=0\r\n"
344 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
347 "a=group:BUNDLE audio_content_name video_content_name\r\n"
348 "a=msid-semantic: WMS local_stream_1\r\n"
349 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
350 "c=IN IP4 74.125.127.126\r\n"
351 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
352 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
361 "raddr 192.168.1.5 rport 2346 "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
364 "raddr 192.168.1.5 rport 2348 "
365 "generation 2\r\n"
366 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
367 "a=mid:audio_content_name\r\n"
368 "a=sendrecv\r\n"
369 "a=rtcp-mux\r\n"
370 "a=rtcp-rsize\r\n"
371 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
372 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
373 "dummy_session_params\r\n"
374 "a=rtpmap:111 opus/48000/2\r\n"
375 "a=rtpmap:103 ISAC/16000\r\n"
376 "a=rtpmap:104 ISAC/32000\r\n"
377 "a=ssrc:1 cname:stream_1_cname\r\n"
378 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
379 "a=ssrc:1 mslabel:local_stream_1\r\n"
380 "a=ssrc:1 label:audio_track_id_1\r\n"
381 "m=video 0 RTP/SAVPF 120\r\n"
382 "c=IN IP4 0.0.0.0\r\n"
383 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
384 "a=bundle-only\r\n"
385 "a=mid:video_content_name\r\n"
386 "a=sendrecv\r\n"
387 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
388 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
389 "a=rtpmap:120 VP8/90000\r\n"
390 "a=ssrc-group:FEC 2 3\r\n"
391 "a=ssrc:2 cname:stream_1_cname\r\n"
392 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
393 "a=ssrc:2 mslabel:local_stream_1\r\n"
394 "a=ssrc:2 label:video_track_id_1\r\n"
395 "a=ssrc:3 cname:stream_1_cname\r\n"
396 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
397 "a=ssrc:3 mslabel:local_stream_1\r\n"
398 "a=ssrc:3 label:video_track_id_1\r\n";
399
deadbeef9d3584c2016-02-16 17:54:10 -0800400// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
401// tracks.
402static const char kPlanBSdpFullString[] =
403 "v=0\r\n"
404 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
405 "s=-\r\n"
406 "t=0 0\r\n"
407 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
408 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
409 "c=IN IP4 74.125.127.126\r\n"
410 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
411 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
420 "raddr 192.168.1.5 rport 2346 "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
423 "raddr 192.168.1.5 rport 2348 "
424 "generation 2\r\n"
425 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
426 "a=mid:audio_content_name\r\n"
427 "a=sendrecv\r\n"
428 "a=rtcp-mux\r\n"
429 "a=rtcp-rsize\r\n"
430 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
431 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
432 "dummy_session_params\r\n"
433 "a=rtpmap:111 opus/48000/2\r\n"
434 "a=rtpmap:103 ISAC/16000\r\n"
435 "a=rtpmap:104 ISAC/32000\r\n"
436 "a=ssrc:1 cname:stream_1_cname\r\n"
437 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
438 "a=ssrc:1 mslabel:local_stream_1\r\n"
439 "a=ssrc:1 label:audio_track_id_1\r\n"
440 "a=ssrc:4 cname:stream_2_cname\r\n"
441 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
442 "a=ssrc:4 mslabel:local_stream_2\r\n"
443 "a=ssrc:4 label:audio_track_id_2\r\n"
444 "m=video 3457 RTP/SAVPF 120\r\n"
445 "c=IN IP4 74.125.224.39\r\n"
446 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
447 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
454 "generation 2\r\n"
455 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
456 "generation 2\r\n"
457 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
458 "generation 2\r\n"
459 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
460 "a=mid:video_content_name\r\n"
461 "a=sendrecv\r\n"
462 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
463 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
464 "a=rtpmap:120 VP8/90000\r\n"
465 "a=ssrc-group:FEC 2 3\r\n"
466 "a=ssrc:2 cname:stream_1_cname\r\n"
467 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
468 "a=ssrc:2 mslabel:local_stream_1\r\n"
469 "a=ssrc:2 label:video_track_id_1\r\n"
470 "a=ssrc:3 cname:stream_1_cname\r\n"
471 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
472 "a=ssrc:3 mslabel:local_stream_1\r\n"
473 "a=ssrc:3 label:video_track_id_1\r\n"
474 "a=ssrc:5 cname:stream_2_cname\r\n"
475 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
476 "a=ssrc:5 mslabel:local_stream_2\r\n"
477 "a=ssrc:5 label:video_track_id_2\r\n"
478 "a=ssrc:6 cname:stream_2_cname\r\n"
479 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
480 "a=ssrc:6 mslabel:local_stream_2\r\n"
481 "a=ssrc:6 label:video_track_id_3\r\n";
482
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800483// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
484// tracks, but with the unified plan "a=msid" attribute.
485static const char kPlanBSdpFullStringWithMsid[] =
486 "v=0\r\n"
487 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
488 "s=-\r\n"
489 "t=0 0\r\n"
490 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
491 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
492 "c=IN IP4 74.125.127.126\r\n"
493 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
494 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
497 "generation 2\r\n"
498 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
503 "raddr 192.168.1.5 rport 2346 "
504 "generation 2\r\n"
505 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
506 "raddr 192.168.1.5 rport 2348 "
507 "generation 2\r\n"
508 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
509 "a=mid:audio_content_name\r\n"
510 "a=msid:local_stream_1 audio_track_id_1\r\n"
511 "a=sendrecv\r\n"
512 "a=rtcp-mux\r\n"
513 "a=rtcp-rsize\r\n"
514 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
515 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
516 "dummy_session_params\r\n"
517 "a=rtpmap:111 opus/48000/2\r\n"
518 "a=rtpmap:103 ISAC/16000\r\n"
519 "a=rtpmap:104 ISAC/32000\r\n"
520 "a=ssrc:1 cname:stream_1_cname\r\n"
521 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
522 "a=ssrc:1 mslabel:local_stream_1\r\n"
523 "a=ssrc:1 label:audio_track_id_1\r\n"
524 "a=ssrc:4 cname:stream_2_cname\r\n"
525 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
526 "a=ssrc:4 mslabel:local_stream_2\r\n"
527 "a=ssrc:4 label:audio_track_id_2\r\n"
528 "m=video 3457 RTP/SAVPF 120\r\n"
529 "c=IN IP4 74.125.224.39\r\n"
530 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
531 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
540 "generation 2\r\n"
541 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
542 "generation 2\r\n"
543 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
544 "a=mid:video_content_name\r\n"
545 "a=msid:local_stream_1 video_track_id_1\r\n"
546 "a=sendrecv\r\n"
547 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
548 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
549 "a=rtpmap:120 VP8/90000\r\n"
550 "a=ssrc-group:FEC 2 3\r\n"
551 "a=ssrc:2 cname:stream_1_cname\r\n"
552 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
553 "a=ssrc:2 mslabel:local_stream_1\r\n"
554 "a=ssrc:2 label:video_track_id_1\r\n"
555 "a=ssrc:3 cname:stream_1_cname\r\n"
556 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
557 "a=ssrc:3 mslabel:local_stream_1\r\n"
558 "a=ssrc:3 label:video_track_id_1\r\n"
559 "a=ssrc:5 cname:stream_2_cname\r\n"
560 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
561 "a=ssrc:5 mslabel:local_stream_2\r\n"
562 "a=ssrc:5 label:video_track_id_2\r\n"
563 "a=ssrc:6 cname:stream_2_cname\r\n"
564 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
565 "a=ssrc:6 mslabel:local_stream_2\r\n"
566 "a=ssrc:6 label:video_track_id_3\r\n";
567
deadbeef9d3584c2016-02-16 17:54:10 -0800568// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
569// tracks.
570static const char kUnifiedPlanSdpFullString[] =
571 "v=0\r\n"
572 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
573 "s=-\r\n"
574 "t=0 0\r\n"
575 "a=msid-semantic: WMS local_stream_1\r\n"
576 // Audio track 1, stream 1 (with candidates).
577 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
578 "c=IN IP4 74.125.127.126\r\n"
579 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
580 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
581 "generation 2\r\n"
582 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
583 "generation 2\r\n"
584 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
585 "generation 2\r\n"
586 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
587 "generation 2\r\n"
588 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
589 "raddr 192.168.1.5 rport 2346 "
590 "generation 2\r\n"
591 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
592 "raddr 192.168.1.5 rport 2348 "
593 "generation 2\r\n"
594 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
595 "a=mid:audio_content_name\r\n"
596 "a=msid:local_stream_1 audio_track_id_1\r\n"
597 "a=sendrecv\r\n"
598 "a=rtcp-mux\r\n"
599 "a=rtcp-rsize\r\n"
600 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
601 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
602 "dummy_session_params\r\n"
603 "a=rtpmap:111 opus/48000/2\r\n"
604 "a=rtpmap:103 ISAC/16000\r\n"
605 "a=rtpmap:104 ISAC/32000\r\n"
606 "a=ssrc:1 cname:stream_1_cname\r\n"
607 // Video track 1, stream 1 (with candidates).
608 "m=video 3457 RTP/SAVPF 120\r\n"
609 "c=IN IP4 74.125.224.39\r\n"
610 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
611 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
616 "generation 2\r\n"
617 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
618 "generation 2\r\n"
619 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
620 "generation 2\r\n"
621 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
622 "generation 2\r\n"
623 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
624 "a=mid:video_content_name\r\n"
625 "a=msid:local_stream_1 video_track_id_1\r\n"
626 "a=sendrecv\r\n"
627 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
628 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
629 "a=rtpmap:120 VP8/90000\r\n"
630 "a=ssrc-group:FEC 2 3\r\n"
631 "a=ssrc:2 cname:stream_1_cname\r\n"
632 "a=ssrc:3 cname:stream_1_cname\r\n"
633 // Audio track 2, stream 2.
634 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
635 "c=IN IP4 0.0.0.0\r\n"
636 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
637 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
638 "a=mid:audio_content_name_2\r\n"
639 "a=msid:local_stream_2 audio_track_id_2\r\n"
640 "a=sendrecv\r\n"
641 "a=rtcp-mux\r\n"
642 "a=rtcp-rsize\r\n"
643 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
644 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
645 "dummy_session_params\r\n"
646 "a=rtpmap:111 opus/48000/2\r\n"
647 "a=rtpmap:103 ISAC/16000\r\n"
648 "a=rtpmap:104 ISAC/32000\r\n"
649 "a=ssrc:4 cname:stream_2_cname\r\n"
650 // Video track 2, stream 2.
651 "m=video 9 RTP/SAVPF 120\r\n"
652 "c=IN IP4 0.0.0.0\r\n"
653 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
654 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
655 "a=mid:video_content_name_2\r\n"
656 "a=msid:local_stream_2 video_track_id_2\r\n"
657 "a=sendrecv\r\n"
658 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
659 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
660 "a=rtpmap:120 VP8/90000\r\n"
661 "a=ssrc:5 cname:stream_2_cname\r\n"
662 // Video track 3, stream 2.
663 "m=video 9 RTP/SAVPF 120\r\n"
664 "c=IN IP4 0.0.0.0\r\n"
665 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
666 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
667 "a=mid:video_content_name_3\r\n"
668 "a=msid:local_stream_2 video_track_id_3\r\n"
669 "a=sendrecv\r\n"
670 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
671 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
672 "a=rtpmap:120 VP8/90000\r\n"
673 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674
675// One candidate reference string as per W3c spec.
676// candidate:<blah> not a=candidate:<blah>CRLF
677static const char kRawCandidate[] =
678 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
679// One candidate reference string.
680static const char kSdpOneCandidate[] =
681 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
682 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000683
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000684static const char kSdpTcpActiveCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype active generation 2";
687static const char kSdpTcpPassiveCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype passive generation 2";
690static const char kSdpTcpSOCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype so generation 2";
693static const char kSdpTcpInvalidCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype invalid generation 2";
696
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000697// One candidate reference string with IPV6 address.
698static const char kRawIPV6Candidate[] =
699 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700700 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701
702// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800703static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800705 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706
707// Session id and version
708static const char kSessionId[] = "18446744069414584320";
709static const char kSessionVersion[] = "18446462598732840960";
710
deadbeef9d3584c2016-02-16 17:54:10 -0800711// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712static const char kIceOption1[] = "iceoption1";
713static const char kIceOption2[] = "iceoption2";
714static const char kIceOption3[] = "iceoption3";
715
deadbeef9d3584c2016-02-16 17:54:10 -0800716// ICE ufrags/passwords.
717static const char kUfragVoice[] = "ufrag_voice";
718static const char kPwdVoice[] = "pwd_voice";
719static const char kUfragVideo[] = "ufrag_video";
720static const char kPwdVideo[] = "pwd_video";
721static const char kUfragData[] = "ufrag_data";
722static const char kPwdData[] = "pwd_data";
723
724// Extra ufrags/passwords for extra unified plan m= sections.
725static const char kUfragVoice2[] = "ufrag_voice_2";
726static const char kPwdVoice2[] = "pwd_voice_2";
727static const char kUfragVideo2[] = "ufrag_video_2";
728static const char kPwdVideo2[] = "pwd_video_2";
729static const char kUfragVideo3[] = "ufrag_video_3";
730static const char kPwdVideo3[] = "pwd_video_3";
731
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732// Content name
733static const char kAudioContentName[] = "audio_content_name";
734static const char kVideoContentName[] = "video_content_name";
735static const char kDataContentName[] = "data_content_name";
736
deadbeef9d3584c2016-02-16 17:54:10 -0800737// Extra content names for extra unified plan m= sections.
738static const char kAudioContentName2[] = "audio_content_name_2";
739static const char kVideoContentName2[] = "video_content_name_2";
740static const char kVideoContentName3[] = "video_content_name_3";
741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742// MediaStream 1
743static const char kStreamLabel1[] = "local_stream_1";
744static const char kStream1Cname[] = "stream_1_cname";
745static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200746static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800748static const uint32_t kVideoTrack1Ssrc1 = 2;
749static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750
751// MediaStream 2
752static const char kStreamLabel2[] = "local_stream_2";
753static const char kStream2Cname[] = "stream_2_cname";
754static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200755static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800756static const char kVideoTrackId2[] = "video_track_id_2";
757static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800759static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760
761// DataChannel
762static const char kDataChannelLabel[] = "data_channel";
763static const char kDataChannelMsid[] = "data_channeld0";
764static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200765static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766
767// Candidate
768static const char kDummyMid[] = "dummy_mid";
769static const int kDummyIndex = 123;
770
771// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800772static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773
774// Helper functions
775
776static bool SdpDeserialize(const std::string& message,
777 JsepSessionDescription* jdesc) {
778 return webrtc::SdpDeserialize(message, jdesc, NULL);
779}
780
781static bool SdpDeserializeCandidate(const std::string& message,
782 JsepIceCandidate* candidate) {
783 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
784}
785
786// Add some extra |newlines| to the |message| after |line|.
787static void InjectAfter(const std::string& line,
788 const std::string& newlines,
789 std::string* message) {
790 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000791 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 tmp.c_str(), tmp.length(), message);
793}
794
795static void Replace(const std::string& line,
796 const std::string& newlines,
797 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 newlines.c_str(), newlines.length(), message);
800}
801
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000802// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
803// message.
804static void ExpectParseFailure(const std::string& bad_sdp,
805 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800806 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000808 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000810 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
811}
812
813// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
814static void ExpectParseFailure(const char* good_part, const char* bad_part) {
815 std::string bad_sdp = kSdpFullString;
816 Replace(good_part, bad_part, &bad_sdp);
817 ExpectParseFailure(bad_sdp, bad_part);
818}
819
820// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
821static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
822 const std::string& newlines,
823 const std::string& bad_part) {
824 std::string bad_sdp = kSdpFullString;
825 InjectAfter(injectpoint, newlines, &bad_sdp);
826 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827}
828
Steve Anton4e70a722017-11-28 14:57:10 -0800829static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 std::string* message) {
831 std::string new_direction;
832 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800833 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 new_direction = "a=inactive";
835 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800836 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 new_direction = "a=sendonly";
838 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800839 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 new_direction = "a=recvonly";
841 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800842 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 default:
844 new_direction = "a=sendrecv";
845 break;
846 }
847 Replace("a=sendrecv", new_direction, message);
848}
849
850static void ReplaceRejected(bool audio_rejected, bool video_rejected,
851 std::string* message) {
852 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800853 Replace("m=audio 9", "m=audio 0", message);
854 Replace(kAttributeIceUfragVoice, "", message);
855 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800858 Replace("m=video 9", "m=video 0", message);
859 Replace(kAttributeIceUfragVideo, "", message);
860 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 }
862}
863
864// WebRtcSdpTest
865
866class WebRtcSdpTest : public testing::Test {
867 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800868 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800869#ifdef WEBRTC_ANDROID
870 webrtc::InitializeAndroidObjects();
871#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 // AudioContentDescription
873 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800874 StreamParams audio_stream;
875 audio_stream.id = kAudioTrackId1;
876 audio_stream.cname = kStream1Cname;
877 audio_stream.sync_label = kStreamLabel1;
878 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
879 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700880 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
881 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800882 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883
884 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800885 video_desc_ = CreateVideoContentDescription();
886 StreamParams video_stream;
887 video_stream.id = kVideoTrackId1;
888 video_stream.cname = kStream1Cname;
889 video_stream.sync_label = kStreamLabel1;
890 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
891 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
892 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
893 video_stream.ssrc_groups.push_back(ssrc_group);
894 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700895 rtc::SocketAddress video_addr("74.125.224.39", 3457);
896 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800897 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800900 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
901 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
902 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
903 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
905 // v4 host
906 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000907 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000908 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000909 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
910 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000912 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000913 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
914 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000916 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000917 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
918 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000920 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000921 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
922 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923
924 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
927 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000928 cricket::LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000931 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
932 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000933 cricket::LOCAL_PORT_TYPE,
934 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000936 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "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 candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945
946 // stun
947 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000948 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
949 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000950 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
951 address_stun, kCandidatePriority, "", "",
952 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000953 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 candidate9.set_related_address(rel_address_stun);
955
956 address_stun.SetPort(port_stun++);
957 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000958 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
959 address_stun, kCandidatePriority, "", "",
960 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000961 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 candidate10.set_related_address(rel_address_stun);
963
964 // relay
965 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000966 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000967 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
968 address_relay, kCandidatePriority, "", "",
969 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000970 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000972 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
973 address_relay, kCandidatePriority, "", "",
974 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000975 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976
977 // voice
978 candidates_.push_back(candidate1);
979 candidates_.push_back(candidate2);
980 candidates_.push_back(candidate5);
981 candidates_.push_back(candidate6);
982 candidates_.push_back(candidate9);
983 candidates_.push_back(candidate10);
984
985 // video
986 candidates_.push_back(candidate3);
987 candidates_.push_back(candidate4);
988 candidates_.push_back(candidate7);
989 candidates_.push_back(candidate8);
990 candidates_.push_back(candidate11);
991 candidates_.push_back(candidate12);
992
993 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
994 0, candidate1));
995
996 // Set up JsepSessionDescription.
997 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
998 std::string mline_id;
999 int mline_index = 0;
1000 for (size_t i = 0; i< candidates_.size(); ++i) {
1001 // In this test, the audio m line index will be 0, and the video m line
1002 // will be 1.
1003 bool is_video = (i > 5);
1004 mline_id = is_video ? "video_content_name" : "audio_content_name";
1005 mline_index = is_video ? 1 : 0;
1006 JsepIceCandidate jice(mline_id,
1007 mline_index,
1008 candidates_.at(i));
1009 jdesc_.AddCandidate(&jice);
1010 }
1011 }
1012
deadbeef25ed4352016-12-12 18:37:36 -08001013 // Turns the existing reference description into a description using
1014 // a=bundle-only. This means no transport attributes and a 0 port value on
1015 // the m= sections not associated with the BUNDLE-tag.
1016 void MakeBundleOnlyDescription() {
1017 // Remove video candidates. JsepSessionDescription doesn't make it
1018 // simple.
1019 const IceCandidateCollection* video_candidates_collection =
1020 jdesc_.candidates(1);
1021 ASSERT_NE(nullptr, video_candidates_collection);
1022 std::vector<cricket::Candidate> video_candidates;
1023 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1024 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1025 c.set_transport_name("video_content_name");
1026 video_candidates.push_back(c);
1027 }
1028 jdesc_.RemoveCandidates(video_candidates);
1029
1030 // And the rest of the transport attributes.
1031 desc_.transport_infos()[1].description.ice_ufrag.clear();
1032 desc_.transport_infos()[1].description.ice_pwd.clear();
1033 desc_.transport_infos()[1].description.connection_role =
1034 cricket::CONNECTIONROLE_NONE;
1035
1036 // Set bundle-only flag.
1037 desc_.contents()[1].bundle_only = true;
1038
1039 // Add BUNDLE group.
1040 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1041 group.AddContentName(kAudioContentName);
1042 group.AddContentName(kVideoContentName);
1043 desc_.AddGroup(group);
1044
1045 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1046 jdesc_.session_version()));
1047 }
1048
deadbeef9d3584c2016-02-16 17:54:10 -08001049 // Turns the existing reference description into a plan B description,
1050 // with 2 audio tracks and 3 video tracks.
1051 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001052 audio_desc_ = audio_desc_->Copy();
1053 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001054
1055 StreamParams audio_track_2;
1056 audio_track_2.id = kAudioTrackId2;
1057 audio_track_2.cname = kStream2Cname;
1058 audio_track_2.sync_label = kStreamLabel2;
1059 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1060 audio_desc_->AddStream(audio_track_2);
1061
1062 StreamParams video_track_2;
1063 video_track_2.id = kVideoTrackId2;
1064 video_track_2.cname = kStream2Cname;
1065 video_track_2.sync_label = kStreamLabel2;
1066 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1067 video_desc_->AddStream(video_track_2);
1068
1069 StreamParams video_track_3;
1070 video_track_3.id = kVideoTrackId3;
1071 video_track_3.cname = kStream2Cname;
1072 video_track_3.sync_label = kStreamLabel2;
1073 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1074 video_desc_->AddStream(video_track_3);
1075
1076 desc_.RemoveContentByName(kAudioContentName);
1077 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001078 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1079 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001080
1081 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1082 jdesc_.session_version()));
1083 }
1084
1085 // Turns the existing reference description into a unified plan description,
1086 // with 2 audio tracks and 3 video tracks.
1087 void MakeUnifiedPlanDescription() {
1088 // Audio track 2.
1089 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1090 StreamParams audio_track_2;
1091 audio_track_2.id = kAudioTrackId2;
1092 audio_track_2.cname = kStream2Cname;
1093 audio_track_2.sync_label = kStreamLabel2;
1094 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1095 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001096 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001097 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1098 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001099 // Video track 2, in stream 2.
1100 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1101 StreamParams video_track_2;
1102 video_track_2.id = kVideoTrackId2;
1103 video_track_2.cname = kStream2Cname;
1104 video_track_2.sync_label = kStreamLabel2;
1105 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1106 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001107 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001108 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1109 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1110
1111 // Video track 3, in stream 2.
1112 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1113 StreamParams video_track_3;
1114 video_track_3.id = kVideoTrackId3;
1115 video_track_3.cname = kStream2Cname;
1116 video_track_3.sync_label = kStreamLabel2;
1117 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1118 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001119 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001120 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1121 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001122 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001123
1124 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1125 jdesc_.session_version()));
1126 }
1127
1128 // Creates an audio content description with no streams, and some default
1129 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 AudioContentDescription* CreateAudioContentDescription() {
1131 AudioContentDescription* audio = new AudioContentDescription();
1132 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001133 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1135 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1136 "dummy_session_params"));
1137 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001138 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001139 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001140 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1141 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 return audio;
1143 }
1144
deadbeef9d3584c2016-02-16 17:54:10 -08001145 // Creates a video content description with no streams, and some default
1146 // configuration.
1147 VideoContentDescription* CreateVideoContentDescription() {
1148 VideoContentDescription* video = new VideoContentDescription();
1149 video->AddCrypto(CryptoParams(
1150 1, "AES_CM_128_HMAC_SHA1_80",
1151 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1152 video->set_protocol(cricket::kMediaProtocolSavpf);
1153 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001154 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001155 return video;
1156 }
1157
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 template <class MCD>
1159 void CompareMediaContentDescription(const MCD* cd1,
1160 const MCD* cd2) {
1161 // type
1162 EXPECT_EQ(cd1->type(), cd1->type());
1163
1164 // content direction
1165 EXPECT_EQ(cd1->direction(), cd2->direction());
1166
1167 // rtcp_mux
1168 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1169
deadbeef13871492015-12-09 12:37:51 -08001170 // rtcp_reduced_size
1171 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 // cryptos
1174 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1175 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1176 ADD_FAILURE();
1177 return;
1178 }
1179 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1180 const CryptoParams c1 = cd1->cryptos().at(i);
1181 const CryptoParams c2 = cd2->cryptos().at(i);
1182 EXPECT_TRUE(c1.Matches(c2));
1183 EXPECT_EQ(c1.key_params, c2.key_params);
1184 EXPECT_EQ(c1.session_params, c2.session_params);
1185 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001188 // Use an equivalence class here, for old and new versions of the
1189 // protocol description.
1190 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001191 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1192 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1193 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001194 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001195 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1196 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1197 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001198 } else {
1199 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1200 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201
1202 // codecs
1203 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1204
1205 // bandwidth
1206 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1207
1208 // streams
1209 EXPECT_EQ(cd1->streams(), cd2->streams());
1210
1211 // extmap
1212 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1213 cd2->rtp_header_extensions().size());
1214 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001215 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1216 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 EXPECT_EQ(ext1.uri, ext2.uri);
1218 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001219 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 }
1222
zstein4b2e0822017-02-17 19:48:38 -08001223 void CompareDataContentDescription(const DataContentDescription* dcd1,
1224 const DataContentDescription* dcd2) {
1225 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1226 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1227 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228
1229 void CompareSessionDescription(const SessionDescription& desc1,
1230 const SessionDescription& desc2) {
1231 // Compare content descriptions.
1232 if (desc1.contents().size() != desc2.contents().size()) {
1233 ADD_FAILURE();
1234 return;
1235 }
1236 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1237 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1238 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001239 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001241 EXPECT_EQ(c1.type, c2.type);
1242 EXPECT_EQ(c1.rejected, c2.rejected);
1243 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244
1245 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1246 if (IsAudioContent(&c1)) {
1247 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001248 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001250 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1252 }
1253
1254 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1255 if (IsVideoContent(&c1)) {
1256 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001257 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001259 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1261 }
1262
1263 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1264 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001265 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1266 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001267 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268 }
1269 }
1270
1271 // group
1272 const cricket::ContentGroups groups1 = desc1.groups();
1273 const cricket::ContentGroups groups2 = desc2.groups();
1274 EXPECT_EQ(groups1.size(), groups1.size());
1275 if (groups1.size() != groups2.size()) {
1276 ADD_FAILURE();
1277 return;
1278 }
1279 for (size_t i = 0; i < groups1.size(); ++i) {
1280 const cricket::ContentGroup group1 = groups1.at(i);
1281 const cricket::ContentGroup group2 = groups2.at(i);
1282 EXPECT_EQ(group1.semantics(), group2.semantics());
1283 const cricket::ContentNames names1 = group1.content_names();
1284 const cricket::ContentNames names2 = group2.content_names();
1285 EXPECT_EQ(names1.size(), names2.size());
1286 if (names1.size() != names2.size()) {
1287 ADD_FAILURE();
1288 return;
1289 }
1290 cricket::ContentNames::const_iterator iter1 = names1.begin();
1291 cricket::ContentNames::const_iterator iter2 = names2.begin();
1292 while (iter1 != names1.end()) {
1293 EXPECT_EQ(*iter1++, *iter2++);
1294 }
1295 }
1296
1297 // transport info
1298 const cricket::TransportInfos transports1 = desc1.transport_infos();
1299 const cricket::TransportInfos transports2 = desc2.transport_infos();
1300 EXPECT_EQ(transports1.size(), transports2.size());
1301 if (transports1.size() != transports2.size()) {
1302 ADD_FAILURE();
1303 return;
1304 }
1305 for (size_t i = 0; i < transports1.size(); ++i) {
1306 const cricket::TransportInfo transport1 = transports1.at(i);
1307 const cricket::TransportInfo transport2 = transports2.at(i);
1308 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_EQ(transport1.description.ice_ufrag,
1310 transport2.description.ice_ufrag);
1311 EXPECT_EQ(transport1.description.ice_pwd,
1312 transport2.description.ice_pwd);
1313 if (transport1.description.identity_fingerprint) {
1314 EXPECT_EQ(*transport1.description.identity_fingerprint,
1315 *transport2.description.identity_fingerprint);
1316 } else {
1317 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1318 transport2.description.identity_fingerprint.get());
1319 }
1320 EXPECT_EQ(transport1.description.transport_options,
1321 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 }
deadbeefc80741f2015-10-22 13:14:45 -07001323
1324 // global attributes
1325 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 }
1327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 bool CompareSessionDescription(
1329 const JsepSessionDescription& desc1,
1330 const JsepSessionDescription& desc2) {
1331 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1332 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1333 CompareSessionDescription(*desc1.description(), *desc2.description());
1334 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1335 return false;
1336 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1337 const IceCandidateCollection* cc1 = desc1.candidates(i);
1338 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001339 if (cc1->count() != cc2->count()) {
1340 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001342 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 for (size_t j = 0; j < cc1->count(); ++j) {
1344 const IceCandidateInterface* c1 = cc1->at(j);
1345 const IceCandidateInterface* c2 = cc2->at(j);
1346 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1347 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1348 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1349 }
1350 }
1351 return true;
1352 }
1353
1354 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1355 // them with invalid keywords so that the parser will just ignore them.
1356 bool RemoveCandidateUfragPwd(std::string* sdp) {
1357 const char ice_ufrag[] = "a=ice-ufrag";
1358 const char ice_ufragx[] = "a=xice-ufrag";
1359 const char ice_pwd[] = "a=ice-pwd";
1360 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001361 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001363 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 ice_pwdx, strlen(ice_pwdx), sdp);
1365 return true;
1366 }
1367
1368 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1369 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1370 const std::string& ufrag, const std::string& pwd) {
1371 std::string content_name;
1372 if (mline_index == 0) {
1373 content_name = kAudioContentName;
1374 } else if (mline_index == 1) {
1375 content_name = kVideoContentName;
1376 } else {
nissec80e7412017-01-11 05:56:46 -08001377 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 }
1379 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001380 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 SessionDescription* desc =
1382 const_cast<SessionDescription*>(jdesc->description());
1383 desc->RemoveTransportInfoByName(content_name);
1384 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1385 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1386 const IceCandidateCollection* cc = jdesc_.candidates(i);
1387 for (size_t j = 0; j < cc->count(); ++j) {
1388 if (cc->at(j)->sdp_mline_index() == mline_index) {
1389 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1390 ufrag);
1391 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1392 pwd);
1393 }
1394 }
1395 }
1396 return true;
1397 }
1398
1399 void AddIceOptions(const std::string& content_name,
1400 const std::vector<std::string>& transport_options) {
1401 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1402 cricket::TransportInfo transport_info =
1403 *(desc_.GetTransportInfoByName(content_name));
1404 desc_.RemoveTransportInfoByName(content_name);
1405 transport_info.description.transport_options = transport_options;
1406 desc_.AddTransportInfo(transport_info);
1407 }
1408
deadbeef3f7219b2015-12-28 15:17:14 -08001409 void SetIceUfragPwd(const std::string& content_name,
1410 const std::string& ice_ufrag,
1411 const std::string& ice_pwd) {
1412 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1413 cricket::TransportInfo transport_info =
1414 *(desc_.GetTransportInfoByName(content_name));
1415 desc_.RemoveTransportInfoByName(content_name);
1416 transport_info.description.ice_ufrag = ice_ufrag;
1417 transport_info.description.ice_pwd = ice_pwd;
1418 desc_.AddTransportInfo(transport_info);
1419 }
1420
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 void AddFingerprint() {
1422 desc_.RemoveTransportInfoByName(kAudioContentName);
1423 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001424 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 kIdentityDigest,
1426 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001427 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1428 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001429 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1430 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001431 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1432 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1433 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001434 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1435 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001436 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 }
1438
jbauch5869f502017-06-29 12:31:36 -07001439 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001440 audio_desc_ = audio_desc_->Copy();
1441 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001442 audio_desc_->AddRtpHeaderExtension(
1443 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1444 video_desc_->AddRtpHeaderExtension(
1445 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 desc_.RemoveContentByName(kAudioContentName);
1447 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001448 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1449 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 }
1451
1452 void RemoveCryptos() {
1453 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1454 video_desc_->set_cryptos(std::vector<CryptoParams>());
1455 }
1456
Steve Anton4e70a722017-11-28 14:57:10 -08001457 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 audio_desc_->set_direction(direction);
1459 video_desc_->set_direction(direction);
1460 std::string new_sdp = kSdpFullString;
1461 ReplaceDirection(direction, &new_sdp);
1462
1463 if (!jdesc_.Initialize(desc_.Copy(),
1464 jdesc_.session_id(),
1465 jdesc_.session_version())) {
1466 return false;
1467 }
Steve Antone831b8c2018-02-01 12:22:16 -08001468 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 EXPECT_EQ(new_sdp, message);
1470 return true;
1471 }
1472
1473 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001474 audio_desc_ = audio_desc_->Copy();
1475 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 desc_.RemoveContentByName(kAudioContentName);
1478 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001479 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001481 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001483 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1484 audio_rejected ? "" : kPwdVoice);
1485 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1486 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001487
1488 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1490
Steve Antona3a92c22017-12-07 10:27:41 -08001491 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001492 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001493 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_EQ(new_sdp, message);
1495 return true;
1496 }
1497
zstein4b2e0822017-02-17 19:48:38 -08001498 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001499 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001501 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001503 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001504 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001505 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1506 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001507 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1508 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001509 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1510 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 }
1512
1513 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001514 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 data_desc_ = data.get();
1516
deadbeef67cf2c12016-04-13 10:07:16 -07001517 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 StreamParams data_stream;
1519 data_stream.id = kDataChannelMsid;
1520 data_stream.cname = kDataChannelCname;
1521 data_stream.sync_label = kDataChannelLabel;
1522 data_stream.ssrcs.push_back(kDataChannelSsrc);
1523 data_desc_->AddStream(data_stream);
1524 data_desc_->AddCrypto(CryptoParams(
1525 1, "AES_CM_128_HMAC_SHA1_80",
1526 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1527 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001528 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001529 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1530 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 }
1532
Steve Anton4e70a722017-11-28 14:57:10 -08001533 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 std::string new_sdp = kSdpFullString;
1535 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001536 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537
1538 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1539
1540 audio_desc_->set_direction(direction);
1541 video_desc_->set_direction(direction);
1542 if (!jdesc_.Initialize(desc_.Copy(),
1543 jdesc_.session_id(),
1544 jdesc_.session_version())) {
1545 return false;
1546 }
1547 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1548 return true;
1549 }
1550
1551 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001552 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001554 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001556
Steve Antonb1c1de12017-12-21 15:14:30 -08001557 audio_desc_ = audio_desc_->Copy();
1558 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 desc_.RemoveContentByName(kAudioContentName);
1560 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001561 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001563 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001565 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1566 audio_rejected ? "" : kPwdVoice);
1567 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1568 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001569 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001570 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1571 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 return false;
1573 }
deadbeef3f7219b2015-12-28 15:17:14 -08001574 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 return true;
1576 }
1577
jbauch5869f502017-06-29 12:31:36 -07001578 void TestDeserializeExtmap(bool session_level, bool media_level,
1579 bool encrypted) {
1580 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001581 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1583 jdesc_.session_id(),
1584 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001585 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 std::string sdp_with_extmap = kSdpString;
1587 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001588 InjectAfter(kSessionTime,
1589 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1590 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 &sdp_with_extmap);
1592 }
1593 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001594 InjectAfter(kAttributeIcePwdVoice,
1595 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1596 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001598 InjectAfter(kAttributeIcePwdVideo,
1599 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1600 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 &sdp_with_extmap);
1602 }
1603 // The extmap can't be present at the same time in both session level and
1604 // media level.
1605 if (session_level && media_level) {
1606 SdpParseError error;
1607 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1608 &jdesc_with_extmap, &error));
1609 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1610 } else {
1611 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1612 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1613 }
1614 }
1615
1616 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1617 const std::string& name, int expected_value) {
1618 cricket::CodecParameterMap::const_iterator found = params.find(name);
1619 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001620 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 }
1622
1623 void TestDeserializeCodecParams(const CodecParams& params,
1624 JsepSessionDescription* jdesc_output) {
1625 std::string sdp =
1626 "v=0\r\n"
1627 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1628 "s=-\r\n"
1629 "t=0 0\r\n"
1630 // Include semantics for WebRTC Media Streams since it is supported by
1631 // this parser, and will be added to the SDP when serializing a session
1632 // description.
1633 "a=msid-semantic: WMS\r\n"
1634 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001635 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 // Pltype 111 listed before 103 and 104 in the map.
1637 "a=rtpmap:111 opus/48000/2\r\n"
1638 // Pltype 103 listed before 104.
1639 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001640 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001641 "a=fmtp:111 0-15,66,70\r\n"
1642 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001644 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001645 << "; sprop-stereo=" << params.sprop_stereo
1646 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001647 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 << "a=ptime:" << params.ptime << "\r\n"
1649 << "a=maxptime:" << params.max_ptime << "\r\n";
1650 sdp += os.str();
1651
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001652 os.clear();
1653 os.str("");
1654 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001655 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001656 << "a=rtpmap:99 VP8/90000\r\n"
1657 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001658 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001659 sdp += os.str();
1660
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 // Deserialize
1662 SdpParseError error;
1663 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1664
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001666 GetFirstAudioContentDescription(jdesc_output->description());
1667 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 ASSERT_FALSE(acd->codecs().empty());
1669 cricket::AudioCodec opus = acd->codecs()[0];
1670 EXPECT_EQ("opus", opus.name);
1671 EXPECT_EQ(111, opus.id);
1672 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1673 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1674 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1675 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001676 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1677 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1679 cricket::AudioCodec codec = acd->codecs()[i];
1680 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1681 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001683
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001684 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001685 GetFirstVideoContentDescription(jdesc_output->description());
1686 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001687 ASSERT_FALSE(vcd->codecs().empty());
1688 cricket::VideoCodec vp8 = vcd->codecs()[0];
1689 EXPECT_EQ("VP8", vp8.name);
1690 EXPECT_EQ(99, vp8.id);
1691 cricket::VideoCodec rtx = vcd->codecs()[1];
1692 EXPECT_EQ("RTX", rtx.name);
1693 EXPECT_EQ(95, rtx.id);
1694 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 }
1696
1697 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1698 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001699 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 "v=0\r\n"
1701 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1702 "s=-\r\n"
1703 "t=0 0\r\n"
1704 // Include semantics for WebRTC Media Streams since it is supported by
1705 // this parser, and will be added to the SDP when serializing a session
1706 // description.
1707 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001708 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001709 "a=rtpmap:111 opus/48000/2\r\n";
1710 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 "m=video 3457 RTP/SAVPF 101\r\n"
1712 "a=rtpmap:101 VP8/90000\r\n"
1713 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001714 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001715 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001717 os << sdp_session_and_audio;
1718 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1719 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001721 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 // Deserialize
1723 SdpParseError error;
1724 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001726 GetFirstAudioContentDescription(jdesc_output->description());
1727 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 ASSERT_FALSE(acd->codecs().empty());
1729 cricket::AudioCodec opus = acd->codecs()[0];
1730 EXPECT_EQ(111, opus.id);
1731 EXPECT_TRUE(opus.HasFeedbackParam(
1732 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1733 cricket::kParamValueEmpty)));
1734
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001736 GetFirstVideoContentDescription(jdesc_output->description());
1737 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 ASSERT_FALSE(vcd->codecs().empty());
1739 cricket::VideoCodec vp8 = vcd->codecs()[0];
1740 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1741 vp8.name.c_str());
1742 EXPECT_EQ(101, vp8.id);
1743 EXPECT_TRUE(vp8.HasFeedbackParam(
1744 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1745 cricket::kParamValueEmpty)));
1746 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001747 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1748 cricket::kRtcpFbNackParamPli)));
1749 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1751 cricket::kParamValueEmpty)));
1752 EXPECT_TRUE(vp8.HasFeedbackParam(
1753 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1754 cricket::kRtcpFbCcmParamFir)));
1755 }
1756
1757 // Two SDP messages can mean the same thing but be different strings, e.g.
1758 // some of the lines can be serialized in different order.
1759 // However, a deserialized description can be compared field by field and has
1760 // no order. If deserializer has already been tested, serializing then
1761 // deserializing and comparing JsepSessionDescription will test
1762 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001763 void TestSerialize(const JsepSessionDescription& jdesc) {
1764 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001765 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 SdpParseError error;
1767 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1768 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1769 }
1770
zhihuang38989e52017-03-21 11:04:53 -07001771 // Calling 'Initialize' with a copy of the inner SessionDescription will
1772 // create a copy of the JsepSessionDescription without candidates. The
1773 // 'connection address' field, previously set from the candidates, must also
1774 // be reset.
1775 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1776 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1777 rtc::SocketAddress video_addr("0.0.0.0", 9);
1778 audio_desc_->set_connection_address(audio_addr);
1779 video_desc_->set_connection_address(video_addr);
1780 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1781 }
1782
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 protected:
1784 SessionDescription desc_;
1785 AudioContentDescription* audio_desc_;
1786 VideoContentDescription* video_desc_;
1787 DataContentDescription* data_desc_;
1788 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001789 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 JsepSessionDescription jdesc_;
1791};
1792
1793void TestMismatch(const std::string& string1, const std::string& string2) {
1794 int position = 0;
1795 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1796 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001797 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 break;
1799 }
1800 }
1801 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1802 << " character\n"
1803 << " 1: " << string1.substr(position, 20) << "\n"
1804 << " 2: " << string2.substr(position, 20) << "\n";
1805}
1806
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1808 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001809 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 TestMismatch(std::string(kSdpFullString), message);
1811}
1812
1813TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001814 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001815 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816}
1817
1818// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1819// the case in a DTLS offer.
1820TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1821 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001822 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001823 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001824 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825
1826 std::string sdp_with_fingerprint = kSdpString;
1827 InjectAfter(kAttributeIcePwdVoice,
1828 kFingerprint, &sdp_with_fingerprint);
1829 InjectAfter(kAttributeIcePwdVideo,
1830 kFingerprint, &sdp_with_fingerprint);
1831
1832 EXPECT_EQ(sdp_with_fingerprint, message);
1833}
1834
1835// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1836// be the case in a DTLS answer.
1837TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1838 AddFingerprint();
1839 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001840 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001841 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001842 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843
1844 std::string sdp_with_fingerprint = kSdpString;
1845 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1846 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1847 InjectAfter(kAttributeIcePwdVoice,
1848 kFingerprint, &sdp_with_fingerprint);
1849 InjectAfter(kAttributeIcePwdVideo,
1850 kFingerprint, &sdp_with_fingerprint);
1851
1852 EXPECT_EQ(sdp_with_fingerprint, message);
1853}
1854
1855TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1856 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001857 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001858 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001859 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 EXPECT_EQ(std::string(kSdpString), message);
1861}
1862
1863TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1864 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1865 group.AddContentName(kAudioContentName);
1866 group.AddContentName(kVideoContentName);
1867 desc_.AddGroup(group);
1868 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1869 jdesc_.session_id(),
1870 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001871 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 std::string sdp_with_bundle = kSdpFullString;
1873 InjectAfter(kSessionTime,
1874 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1875 &sdp_with_bundle);
1876 EXPECT_EQ(sdp_with_bundle, message);
1877}
1878
1879TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001880 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001882 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 acd->set_bandwidth(50 * 1000);
1884 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1885 jdesc_.session_id(),
1886 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001887 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001889 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 "b=AS:100\r\n",
1891 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001892 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 "b=AS:50\r\n",
1894 &sdp_with_bandwidth);
1895 EXPECT_EQ(sdp_with_bandwidth, message);
1896}
1897
1898TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1899 std::vector<std::string> transport_options;
1900 transport_options.push_back(kIceOption1);
1901 transport_options.push_back(kIceOption3);
1902 AddIceOptions(kAudioContentName, transport_options);
1903 transport_options.clear();
1904 transport_options.push_back(kIceOption2);
1905 transport_options.push_back(kIceOption3);
1906 AddIceOptions(kVideoContentName, transport_options);
1907 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1908 jdesc_.session_id(),
1909 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001910 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 std::string sdp_with_ice_options = kSdpFullString;
1912 InjectAfter(kAttributeIcePwdVoice,
1913 "a=ice-options:iceoption1 iceoption3\r\n",
1914 &sdp_with_ice_options);
1915 InjectAfter(kAttributeIcePwdVideo,
1916 "a=ice-options:iceoption2 iceoption3\r\n",
1917 &sdp_with_ice_options);
1918 EXPECT_EQ(sdp_with_ice_options, message);
1919}
1920
1921TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001922 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923}
1924
1925TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001926 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927}
1928
1929TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001930 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931}
1932
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1934 EXPECT_TRUE(TestSerializeRejected(true, false));
1935}
1936
1937TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1938 EXPECT_TRUE(TestSerializeRejected(false, true));
1939}
1940
1941TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1942 EXPECT_TRUE(TestSerializeRejected(true, true));
1943}
1944
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1946 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08001947 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948
zhihuang38989e52017-03-21 11:04:53 -07001949 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08001950 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951
1952 std::string expected_sdp = kSdpString;
1953 expected_sdp.append(kSdpRtpDataChannelString);
1954 EXPECT_EQ(expected_sdp, message);
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08001958 bool use_sctpmap = true;
1959 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08001960 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961
zhihuang38989e52017-03-21 11:04:53 -07001962 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08001963 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964
1965 std::string expected_sdp = kSdpString;
1966 expected_sdp.append(kSdpSctpDataChannelString);
1967 EXPECT_EQ(message, expected_sdp);
1968}
1969
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001970TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08001971 bool use_sctpmap = true;
1972 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08001973 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001974 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08001975 DataContentDescription* dcdesc =
1976 jsep_desc.description()
1977 ->GetContentDescriptionByName(kDataContentName)
1978 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001979
1980 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001981 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001982 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001983 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1984 dcdesc->AddOrReplaceCodec(codec);
1985
Steve Antone831b8c2018-02-01 12:22:16 -08001986 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001987
1988 std::string expected_sdp = kSdpString;
1989 expected_sdp.append(kSdpSctpDataChannelString);
1990
1991 char default_portstr[16];
1992 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001993 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001994 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001995 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1996 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001997 new_portstr, strlen(new_portstr),
1998 &expected_sdp);
1999
2000 EXPECT_EQ(expected_sdp, message);
2001}
2002
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002003TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002004 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002005 AddRtpDataChannel();
2006 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002007 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002008 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002009
2010 std::string expected_sdp = kSdpString;
2011 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002012 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002013 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002014 "b=AS:100\r\n",
2015 &expected_sdp);
2016 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002017}
2018
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002020 bool encrypted = false;
2021 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002022 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002023 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002024 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025
2026 std::string sdp_with_extmap = kSdpString;
2027 InjectAfter("a=mid:audio_content_name\r\n",
2028 kExtmap, &sdp_with_extmap);
2029 InjectAfter("a=mid:video_content_name\r\n",
2030 kExtmap, &sdp_with_extmap);
2031
2032 EXPECT_EQ(sdp_with_extmap, message);
2033}
2034
jbauch5869f502017-06-29 12:31:36 -07002035TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2036 bool encrypted = true;
2037 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002038 JsepSessionDescription desc_with_extmap(kDummyType);
jbauch5869f502017-06-29 12:31:36 -07002039 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2040 kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002041 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002042}
2043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044TEST_F(WebRtcSdpTest, SerializeCandidates) {
2045 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002046 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002047
2048 Candidate candidate_with_ufrag(candidates_.front());
2049 candidate_with_ufrag.set_username("ABC");
2050 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2051 candidate_with_ufrag));
2052 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2053 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002054
2055 Candidate candidate_with_network_info(candidates_.front());
2056 candidate_with_network_info.set_network_id(1);
2057 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2058 candidate_with_network_info));
2059 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2060 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2061 candidate_with_network_info.set_network_cost(999);
2062 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2063 candidate_with_network_info));
2064 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2065 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2066 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067}
2068
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002069// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2070// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002071TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002072 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002073 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2074 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2075 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002076 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002077 std::unique_ptr<IceCandidateInterface> jcandidate(
2078 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002079
2080 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2081 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2082}
2083
htaa6b99442016-04-12 10:29:17 -07002084TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002085 cricket::VideoCodec h264_codec("H264");
2086 h264_codec.SetParam("profile-level-id", "42e01f");
2087 h264_codec.SetParam("level-asymmetry-allowed", "1");
2088 h264_codec.SetParam("packetization-mode", "1");
2089 video_desc_->AddCodec(h264_codec);
2090
htaa6b99442016-04-12 10:29:17 -07002091 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2092
Steve Antone831b8c2018-02-01 12:22:16 -08002093 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002094 size_t after_pt = message.find(" H264/90000");
2095 ASSERT_NE(after_pt, std::string::npos);
2096 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2097 ASSERT_NE(before_pt, std::string::npos);
2098 before_pt += strlen("a=rtpmap:");
2099 std::string pt = message.substr(before_pt, after_pt - before_pt);
2100 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2101 std::string to_find = "a=fmtp:" + pt + " ";
2102 size_t fmtp_pos = message.find(to_find);
2103 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2104 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2105 ASSERT_NE(std::string::npos, fmtp_endpos);
2106 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2107 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2108 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2109 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002110 // Check that there are no spaces after semicolons.
2111 // https://bugs.webrtc.org/5793
2112 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002116 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 // Deserialize
2118 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2119 // Verify
2120 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2121}
2122
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002123TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002124 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002125 const char kSdpWithoutMline[] =
2126 "v=0\r\n"
2127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2128 "s=-\r\n"
2129 "t=0 0\r\n"
2130 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2131 // Deserialize
2132 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2133 EXPECT_EQ(0u, jdesc.description()->contents().size());
2134}
2135
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002137 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 std::string sdp_without_carriage_return = kSdpFullString;
2139 Replace("\r\n", "\n", &sdp_without_carriage_return);
2140 // Deserialize
2141 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2142 // Verify
2143 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2144}
2145
2146TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2147 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002148 JsepSessionDescription jdesc_no_candidates(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2150 kSessionId, kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002151 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2153 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2154}
2155
2156TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2157 static const char kSdpNoRtpmapString[] =
2158 "v=0\r\n"
2159 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2160 "s=-\r\n"
2161 "t=0 0\r\n"
2162 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2163 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002164 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 // The rtpmap line for static payload codec is optional.
2166 "a=rtpmap:18 G729/16000\r\n"
2167 "a=rtpmap:103 ISAC/16000\r\n";
2168
Steve Antona3a92c22017-12-07 10:27:41 -08002169 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2171 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002172 jdesc.description()
2173 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2174 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002176 // The codecs in the AudioContentDescription should be in the same order as
2177 // the payload types (<fmt>s) on the m= line.
2178 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2179 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002180 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 EXPECT_EQ(ref_codecs, audio->codecs());
2182}
2183
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002184TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2185 static const char kSdpNoRtpmapString[] =
2186 "v=0\r\n"
2187 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2188 "s=-\r\n"
2189 "t=0 0\r\n"
2190 "m=audio 49232 RTP/AVP 18 103\r\n"
2191 "a=fmtp:18 annexb=yes\r\n"
2192 "a=rtpmap:103 ISAC/16000\r\n";
2193
Steve Antona3a92c22017-12-07 10:27:41 -08002194 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002195 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2196 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002197 jdesc.description()
2198 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2199 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002200
2201 cricket::AudioCodec g729 = audio->codecs()[0];
2202 EXPECT_EQ("G729", g729.name);
2203 EXPECT_EQ(8000, g729.clockrate);
2204 EXPECT_EQ(18, g729.id);
2205 cricket::CodecParameterMap::iterator found =
2206 g729.params.find("annexb");
2207 ASSERT_TRUE(found != g729.params.end());
2208 EXPECT_EQ(found->second, "yes");
2209
2210 cricket::AudioCodec isac = audio->codecs()[1];
2211 EXPECT_EQ("ISAC", isac.name);
2212 EXPECT_EQ(103, isac.id);
2213 EXPECT_EQ(16000, isac.clockrate);
2214}
2215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216// Ensure that we can deserialize SDP with a=fingerprint properly.
2217TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2218 // Add a DTLS a=fingerprint attribute to our session description.
2219 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002220 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2222 jdesc_.session_id(),
2223 jdesc_.session_version()));
2224
Steve Antona3a92c22017-12-07 10:27:41 -08002225 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 std::string sdp_with_fingerprint = kSdpString;
2227 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2228 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2229 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2230 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2231}
2232
2233TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002234 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 std::string sdp_with_bundle = kSdpFullString;
2236 InjectAfter(kSessionTime,
2237 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2238 &sdp_with_bundle);
2239 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2240 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2241 group.AddContentName(kAudioContentName);
2242 group.AddContentName(kVideoContentName);
2243 desc_.AddGroup(group);
2244 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2245 jdesc_.session_id(),
2246 jdesc_.session_version()));
2247 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2248}
2249
2250TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002251 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 std::string sdp_with_bandwidth = kSdpFullString;
2253 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2254 "b=AS:100\r\n",
2255 &sdp_with_bandwidth);
2256 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2257 "b=AS:50\r\n",
2258 &sdp_with_bandwidth);
2259 EXPECT_TRUE(
2260 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002261 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002263 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 acd->set_bandwidth(50 * 1000);
2265 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2266 jdesc_.session_id(),
2267 jdesc_.session_version()));
2268 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2269}
2270
2271TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002272 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 std::string sdp_with_ice_options = kSdpFullString;
2274 InjectAfter(kSessionTime,
2275 "a=ice-options:iceoption3\r\n",
2276 &sdp_with_ice_options);
2277 InjectAfter(kAttributeIcePwdVoice,
2278 "a=ice-options:iceoption1\r\n",
2279 &sdp_with_ice_options);
2280 InjectAfter(kAttributeIcePwdVideo,
2281 "a=ice-options:iceoption2\r\n",
2282 &sdp_with_ice_options);
2283 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2284 std::vector<std::string> transport_options;
2285 transport_options.push_back(kIceOption3);
2286 transport_options.push_back(kIceOption1);
2287 AddIceOptions(kAudioContentName, transport_options);
2288 transport_options.clear();
2289 transport_options.push_back(kIceOption3);
2290 transport_options.push_back(kIceOption2);
2291 AddIceOptions(kVideoContentName, transport_options);
2292 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2293 jdesc_.session_id(),
2294 jdesc_.session_version()));
2295 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2296}
2297
2298TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2299 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002300 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 std::string sdp_with_ufrag_pwd = kSdpFullString;
2302 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2303 // Add session level ufrag and pwd
2304 InjectAfter(kSessionTime,
2305 "a=ice-pwd:session+level+icepwd\r\n"
2306 "a=ice-ufrag:session+level+iceufrag\r\n",
2307 &sdp_with_ufrag_pwd);
2308 // Add media level ufrag and pwd for audio
2309 InjectAfter("a=mid:audio_content_name\r\n",
2310 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2311 &sdp_with_ufrag_pwd);
2312 // Update the candidate ufrag and pwd to the expected ones.
2313 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2314 "media+level+iceufrag", "media+level+icepwd"));
2315 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2316 "session+level+iceufrag", "session+level+icepwd"));
2317 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2318 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2319}
2320
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002322 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323}
2324
2325TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002326 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327}
2328
2329TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002330 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331}
2332
2333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2334 EXPECT_TRUE(TestDeserializeRejected(true, false));
2335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2338 EXPECT_TRUE(TestDeserializeRejected(false, true));
2339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2342 EXPECT_TRUE(TestDeserializeRejected(true, true));
2343}
2344
2345// Tests that we can still handle the sdp uses mslabel and label instead of
2346// msid for backward compatibility.
2347TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002348 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002349 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 std::string sdp_without_msid = kSdpFullString;
2351 Replace("msid", "xmsid", &sdp_without_msid);
2352 // Deserialize
2353 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2354 // Verify
2355 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2356}
2357
2358TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2359 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2360
2361 std::string sdp = kSdpOneCandidate;
2362 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2363 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2364 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2365 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002366 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
2368 // Candidate line without generation extension.
2369 sdp = kSdpOneCandidate;
2370 Replace(" generation 2", "", &sdp);
2371 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2372 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2373 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2374 Candidate expected = jcandidate_->candidate();
2375 expected.set_generation(0);
2376 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2377
honghaiza0c44ea2016-03-23 16:07:48 -07002378 // Candidate with network id and/or cost.
2379 sdp = kSdpOneCandidate;
2380 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2381 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2382 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2383 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2384 expected = jcandidate_->candidate();
2385 expected.set_network_id(2);
2386 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2387 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2388 // Add network cost
2389 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2390 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2391 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2392 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2393
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002394 sdp = kSdpTcpActiveCandidate;
2395 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2396 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002397 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002398 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2399 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2400 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002401 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2402 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002403 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2404 jcandidate_template->candidate()));
2405 sdp = kSdpTcpPassiveCandidate;
2406 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2407 sdp = kSdpTcpSOCandidate;
2408 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409}
2410
2411// This test verifies the deserialization of candidate-attribute
2412// as per RFC 5245. Candiate-attribute will be of the format
2413// candidate:<blah>. This format will be used when candidates
2414// are trickled.
2415TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2416 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2417
2418 std::string candidate_attribute = kRawCandidate;
2419 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2420 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2421 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2422 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2423 EXPECT_EQ(2u, jcandidate.candidate().generation());
2424
2425 // Candidate line without generation extension.
2426 candidate_attribute = kRawCandidate;
2427 Replace(" generation 2", "", &candidate_attribute);
2428 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2429 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2430 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2431 Candidate expected = jcandidate_->candidate();
2432 expected.set_generation(0);
2433 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2434
2435 // Candidate line without candidate:
2436 candidate_attribute = kRawCandidate;
2437 Replace("candidate:", "", &candidate_attribute);
2438 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2439
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002440 // Candidate line with IPV6 address.
2441 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2442}
2443
2444// This test verifies that the deserialization of an invalid candidate string
2445// fails.
2446TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2447 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2448
2449 std::string candidate_attribute = kRawCandidate;
2450 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002452
2453 candidate_attribute = kSdpOneCandidate;
2454 candidate_attribute.replace(0, 1, "x");
2455 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2456
2457 candidate_attribute = kRawCandidate;
2458 candidate_attribute.append("\r\n");
2459 candidate_attribute.append(kRawCandidate);
2460 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2461
2462 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463}
2464
2465TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2466 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002467 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2469
2470 std::string sdp_with_data = kSdpString;
2471 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002472 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473
2474 // Deserialize
2475 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2476 // Verify
2477 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2478}
2479
2480TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002481 bool use_sctpmap = true;
2482 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002483 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2485
2486 std::string sdp_with_data = kSdpString;
2487 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002488 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489
lally@webrtc.org36300852015-02-24 20:19:35 +00002490 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2491 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2492 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2493
2494 // Verify with UDP/DTLS/SCTP.
2495 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2496 strlen(kDtlsSctp), kUdpDtlsSctp);
2497 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2498 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2499
2500 // Verify with TCP/DTLS/SCTP.
2501 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2502 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2505}
2506
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002507TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002508 bool use_sctpmap = false;
2509 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002510 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002511 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2512
2513 std::string sdp_with_data = kSdpString;
2514 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002515 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002516
lally@webrtc.org36300852015-02-24 20:19:35 +00002517 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002518 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2519 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002520
lally@webrtc.org36300852015-02-24 20:19:35 +00002521 // Verify with UDP/DTLS/SCTP.
2522 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2523 strlen(kDtlsSctp), kUdpDtlsSctp);
2524 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2525 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002526
lally@webrtc.org36300852015-02-24 20:19:35 +00002527 // Verify with TCP/DTLS/SCTP.
2528 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2529 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002530 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2531 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2532}
2533
lally69f57602015-10-08 10:15:04 -07002534TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002535 bool use_sctpmap = false;
2536 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002537 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002538 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2539
2540 std::string sdp_with_data = kSdpString;
2541 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002542 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002543
2544 // Verify with DTLS/SCTP.
2545 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2546 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2547
2548 // Verify with UDP/DTLS/SCTP.
2549 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2550 strlen(kDtlsSctp), kUdpDtlsSctp);
2551 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2552 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2553
2554 // Verify with TCP/DTLS/SCTP.
2555 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2556 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2557 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2558 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2559}
2560
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002561// Test to check the behaviour if sctp-port is specified
2562// on the m= line and in a=sctp-port.
2563TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002564 bool use_sctpmap = true;
2565 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002566 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002567 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2568
2569 std::string sdp_with_data = kSdpString;
2570 // Append m= attributes
2571 sdp_with_data.append(kSdpSctpDataChannelString);
2572 // Append a=sctp-port attribute
2573 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002574 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002575
2576 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2577}
2578
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002579// For crbug/344475.
2580TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2581 std::string sdp_with_data = kSdpString;
2582 sdp_with_data.append(kSdpSctpDataChannelString);
2583 // Remove the "\n" at the end.
2584 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002585 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002586
2587 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2588 // No crash is a pass.
2589}
2590
Steve Anton36b29d12017-10-30 09:57:42 -07002591void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002592 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002593 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002594 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002595 DataContentDescription* dcdesc =
2596 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002597 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002598 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002599 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002600 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002601 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002602
2603 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002604 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002605 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002606}
2607
2608TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2609 bool use_sctpmap = true;
2610 AddSctpDataChannel(use_sctpmap);
2611
2612 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002613 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002614 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002615
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002616 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002617 std::string sdp_with_data = kSdpString;
2618 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002619 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2620 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2621 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002622 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002623
2624 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2625 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002626}
2627
2628TEST_F(WebRtcSdpTest,
2629 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2630 bool use_sctpmap = false;
2631 AddSctpDataChannel(use_sctpmap);
2632
Steve Antona3a92c22017-12-07 10:27:41 -08002633 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002634 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002635
2636 // We need to test the deserialized JsepSessionDescription from
2637 // kSdpSctpDataChannelStringWithSctpPort for
2638 // draft-ietf-mmusic-sctp-sdp-07
2639 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002640 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002641 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002642 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2643 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2644 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002645 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002646
2647 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2648 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002649}
2650
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002651TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002652 // We want to test that deserializing data content limits bandwidth
2653 // settings (it should never be greater than the default).
2654 // This should prevent someone from using unlimited data bandwidth through
2655 // JS and "breaking the Internet".
2656 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002657 std::string sdp_with_bandwidth = kSdpString;
2658 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2659 InjectAfter("a=mid:data_content_name\r\n",
2660 "b=AS:100\r\n",
2661 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002662 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002663
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002664 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2665}
2666
2667TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002668 bool use_sctpmap = true;
2669 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002670 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002671 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002672 dcd->set_bandwidth(100 * 1000);
2673 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2674
2675 std::string sdp_with_bandwidth = kSdpString;
2676 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2677 InjectAfter("a=mid:data_content_name\r\n",
2678 "b=AS:100\r\n",
2679 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002680 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002681
2682 // SCTP has congestion control, so we shouldn't limit the bandwidth
2683 // as we do for RTP.
2684 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002685 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2686}
2687
jbauch5869f502017-06-29 12:31:36 -07002688class WebRtcSdpExtmapTest
2689 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2690};
2691
2692TEST_P(WebRtcSdpExtmapTest,
2693 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2694 bool encrypted = GetParam();
2695 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696}
2697
jbauch5869f502017-06-29 12:31:36 -07002698TEST_P(WebRtcSdpExtmapTest,
2699 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2700 bool encrypted = GetParam();
2701 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702}
2703
jbauch5869f502017-06-29 12:31:36 -07002704TEST_P(WebRtcSdpExtmapTest,
2705 DeserializeSessionDescriptionWithInvalidExtmap) {
2706 bool encrypted = GetParam();
2707 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708}
2709
jbauch5869f502017-06-29 12:31:36 -07002710INSTANTIATE_TEST_CASE_P(Encrypted,
2711 WebRtcSdpExtmapTest,
2712 ::testing::Values(false, true));
2713
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002714TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002715 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002716 std::string sdp = kSdpFullString;
2717 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2718 // Deserialize
2719 SdpParseError error;
2720 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002721 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002722 EXPECT_EQ(lastline, error.line);
2723 EXPECT_EQ("Invalid SDP line.", error.description);
2724}
2725
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2727 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2728 std::string new_sdp = kSdpOneCandidate;
2729 Replace("udp", "unsupported_transport", &new_sdp);
2730 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2731 new_sdp = kSdpOneCandidate;
2732 Replace("udp", "uDP", &new_sdp);
2733 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2734 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2735 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2736 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2737}
2738
honghaiza54a0802015-12-16 18:37:23 -08002739TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002741 EXPECT_TRUE(
2742 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2744 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2745 Candidate ref_candidate = jcandidate_->candidate();
2746 ref_candidate.set_username("user_rtp");
2747 ref_candidate.set_password("password_rtp");
2748 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2749}
2750
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002751TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002752 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002753
2754 // Deserialize
2755 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2756
2757 // Verify
2758 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002759 jdesc.description()
2760 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2761 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002762 EXPECT_TRUE(audio->conference_mode());
2763
2764 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002765 jdesc.description()
2766 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2767 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002768 EXPECT_TRUE(video->conference_mode());
2769}
2770
deadbeefd45aea82017-09-16 01:24:29 -07002771TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002772 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002773
2774 // We tested deserialization already above, so just test that if we serialize
2775 // and deserialize the flag doesn't disappear.
2776 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002777 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002778 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2779
2780 // Verify.
2781 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002782 jdesc.description()
2783 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2784 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002785 EXPECT_TRUE(audio->conference_mode());
2786
2787 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002788 jdesc.description()
2789 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2790 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002791 EXPECT_TRUE(video->conference_mode());
2792}
2793
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002794TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2795 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002796 const char kSdpEmptyType[] = " =candidate";
2797 const char kSdpEqualAsPlus[] = "a+candidate";
2798 const char kSdpSpaceAfterEqual[] = "a= candidate";
2799 const char kSdpUpperType[] = "A=candidate";
2800 const char kSdpEmptyLine[] = "";
2801 const char kSdpMissingValue[] = "a=";
2802
2803 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002805 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002806 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002807 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 "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 +00002809 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002810 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002811 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812
2813 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002814 ExpectParseFailure("v=", kSdpDestroyer);
2815 ExpectParseFailure("o=", kSdpDestroyer);
2816 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002818 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819
2820 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002821 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2822 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823
2824 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002825 ExpectParseFailure("a=candidate", kSdpEmptyType);
2826 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2827 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2828 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002829
2830 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2831 // because it's orthogonal to what we are replacing and hence
2832 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002833 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2834 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2835 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2836 ExpectParseFailure("a=sendrecv", kSdpMd5);
2837
2838 // Empty Line
2839 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2840 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002841}
2842
2843TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2844 // ssrc
2845 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002846 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002847 // crypto
2848 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2849 // rtpmap
2850 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2851 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2852 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2853 // candidate
2854 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2855 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2856 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2857 ExpectParseFailure("rport 2346", "rport badvalue");
2858 ExpectParseFailure("rport 2346 generation 2",
2859 "rport 2346 generation badvalue");
2860 // m line
2861 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2862 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2863
2864 // bandwidth
2865 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2866 "b=AS:badvalue\r\n",
2867 "b=AS:badvalue");
2868 // rtcp-fb
2869 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2870 "a=rtcp-fb:badvalue nack\r\n",
2871 "a=rtcp-fb:badvalue nack");
2872 // extmap
2873 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2874 "a=extmap:badvalue http://example.com\r\n",
2875 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002876}
2877
2878TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002879 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880
2881 const char kSdpWithReorderedPlTypesString[] =
2882 "v=0\r\n"
2883 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2884 "s=-\r\n"
2885 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002886 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2888 // in the map.
2889 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002890 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891
2892 // Deserialize
2893 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002896 GetFirstAudioContentDescription(jdesc_output.description());
2897 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002899 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2900 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 EXPECT_EQ(104, acd->codecs()[0].id);
2902}
2903
2904TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08002905 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002906 CodecParams params;
2907 params.max_ptime = 40;
2908 params.ptime = 30;
2909 params.min_ptime = 10;
2910 params.sprop_stereo = 1;
2911 params.stereo = 1;
2912 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002913 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08002915 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916}
2917
2918TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2919 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08002920 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08002922 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923}
2924
2925TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2926 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08002927 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08002929 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930}
2931
2932TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08002933 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934
2935 const char kSdpWithFmtpString[] =
2936 "v=0\r\n"
2937 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2938 "s=-\r\n"
2939 "t=0 0\r\n"
2940 "m=video 3457 RTP/SAVPF 120\r\n"
2941 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002942 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2943
2944 // Deserialize
2945 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002946 EXPECT_TRUE(
2947 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002948
Donald Curtis0e07f922015-05-15 09:21:23 -07002949 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002950 GetFirstVideoContentDescription(jdesc_output.description());
2951 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07002952 ASSERT_FALSE(vcd->codecs().empty());
2953 cricket::VideoCodec vp8 = vcd->codecs()[0];
2954 EXPECT_EQ("VP8", vp8.name);
2955 EXPECT_EQ(120, vp8.id);
2956 cricket::CodecParameterMap::iterator found =
2957 vp8.params.find("x-google-min-bitrate");
2958 ASSERT_TRUE(found != vp8.params.end());
2959 EXPECT_EQ(found->second, "10");
2960 found = vp8.params.find("x-google-max-quantization");
2961 ASSERT_TRUE(found != vp8.params.end());
2962 EXPECT_EQ(found->second, "40");
2963}
2964
johan2d8d23e2016-06-03 01:22:42 -07002965TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08002966 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07002967
2968 const char kSdpWithFmtpString[] =
2969 "v=0\r\n"
2970 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2971 "s=-\r\n"
2972 "t=0 0\r\n"
2973 "m=video 49170 RTP/AVP 98\r\n"
2974 "a=rtpmap:98 H264/90000\r\n"
2975 "a=fmtp:98 profile-level-id=42A01E; "
2976 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2977
2978 // Deserialize.
2979 SdpParseError error;
2980 EXPECT_TRUE(
2981 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2982
johan2d8d23e2016-06-03 01:22:42 -07002983 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002984 GetFirstVideoContentDescription(jdesc_output.description());
2985 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07002986 ASSERT_FALSE(vcd->codecs().empty());
2987 cricket::VideoCodec h264 = vcd->codecs()[0];
2988 EXPECT_EQ("H264", h264.name);
2989 EXPECT_EQ(98, h264.id);
2990 cricket::CodecParameterMap::const_iterator found =
2991 h264.params.find("profile-level-id");
2992 ASSERT_TRUE(found != h264.params.end());
2993 EXPECT_EQ(found->second, "42A01E");
2994 found = h264.params.find("sprop-parameter-sets");
2995 ASSERT_TRUE(found != h264.params.end());
2996 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
2997}
2998
Donald Curtis0e07f922015-05-15 09:21:23 -07002999TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003000 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003001
3002 const char kSdpWithFmtpString[] =
3003 "v=0\r\n"
3004 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3005 "s=-\r\n"
3006 "t=0 0\r\n"
3007 "m=video 3457 RTP/SAVPF 120\r\n"
3008 "a=rtpmap:120 VP8/90000\r\n"
3009 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010
3011 // Deserialize
3012 SdpParseError error;
3013 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3014 &error));
3015
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003017 GetFirstVideoContentDescription(jdesc_output.description());
3018 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019 ASSERT_FALSE(vcd->codecs().empty());
3020 cricket::VideoCodec vp8 = vcd->codecs()[0];
3021 EXPECT_EQ("VP8", vp8.name);
3022 EXPECT_EQ(120, vp8.id);
3023 cricket::CodecParameterMap::iterator found =
3024 vp8.params.find("x-google-min-bitrate");
3025 ASSERT_TRUE(found != vp8.params.end());
3026 EXPECT_EQ(found->second, "10");
3027 found = vp8.params.find("x-google-max-quantization");
3028 ASSERT_TRUE(found != vp8.params.end());
3029 EXPECT_EQ(found->second, "40");
3030}
3031
ossuaa4b0772017-01-30 07:41:18 -08003032TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003033 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003034
3035 cricket::AudioCodecs codecs = acd->codecs();
3036 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3037 acd->set_codecs(codecs);
3038
3039 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3040 jdesc_.session_id(),
3041 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003042 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003043 std::string sdp_with_fmtp = kSdpFullString;
3044 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3045 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3046 &sdp_with_fmtp);
3047 EXPECT_EQ(sdp_with_fmtp, message);
3048}
3049
3050TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003051 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003052
3053 cricket::AudioCodecs codecs = acd->codecs();
3054 codecs[0].params["stereo"] = "1";
3055 acd->set_codecs(codecs);
3056
3057 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3058 jdesc_.session_id(),
3059 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003060 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003061 std::string sdp_with_fmtp = kSdpFullString;
3062 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3063 "a=fmtp:111 stereo=1\r\n",
3064 &sdp_with_fmtp);
3065 EXPECT_EQ(sdp_with_fmtp, message);
3066}
3067
3068TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003069 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003070
3071 cricket::AudioCodecs codecs = acd->codecs();
3072 codecs[0].params["ptime"] = "20";
3073 codecs[0].params["maxptime"] = "120";
3074 acd->set_codecs(codecs);
3075
3076 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3077 jdesc_.session_id(),
3078 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003079 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003080 std::string sdp_with_fmtp = kSdpFullString;
3081 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3082 "a=maxptime:120\r\n" // No comma here. String merging!
3083 "a=ptime:20\r\n",
3084 &sdp_with_fmtp);
3085 EXPECT_EQ(sdp_with_fmtp, message);
3086}
3087
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003089 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003090
3091 cricket::VideoCodecs codecs = vcd->codecs();
3092 codecs[0].params["x-google-min-bitrate"] = "10";
3093 vcd->set_codecs(codecs);
3094
3095 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3096 jdesc_.session_id(),
3097 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003098 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099 std::string sdp_with_fmtp = kSdpFullString;
3100 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3101 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3102 &sdp_with_fmtp);
3103 EXPECT_EQ(sdp_with_fmtp, message);
3104}
3105
3106TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
Steve Antona3a92c22017-12-07 10:27:41 -08003107 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003108 std::string sdp_with_icelite = kSdpFullString;
3109 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3110 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3111 const cricket::TransportInfo* tinfo1 =
3112 desc->GetTransportInfoByName("audio_content_name");
3113 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3114 const cricket::TransportInfo* tinfo2 =
3115 desc->GetTransportInfoByName("video_content_name");
3116 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3117 InjectAfter(kSessionTime,
3118 "a=ice-lite\r\n",
3119 &sdp_with_icelite);
3120 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3121 desc = jdesc_with_icelite.description();
3122 const cricket::TransportInfo* atinfo =
3123 desc->GetTransportInfoByName("audio_content_name");
3124 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3125 const cricket::TransportInfo* vtinfo =
3126 desc->GetTransportInfoByName("video_content_name");
3127 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3128}
3129
3130// Verifies that the candidates in the input SDP are parsed and serialized
3131// correctly in the output SDP.
3132TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3133 std::string sdp_with_data = kSdpString;
3134 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003135 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136
3137 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003138 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003140
3141TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3142 AddFingerprint();
3143 TransportInfo audio_transport_info =
3144 *(desc_.GetTransportInfoByName(kAudioContentName));
3145 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3146 audio_transport_info.description.connection_role);
3147 audio_transport_info.description.connection_role =
3148 cricket::CONNECTIONROLE_ACTIVE;
3149
3150 TransportInfo video_transport_info =
3151 *(desc_.GetTransportInfoByName(kVideoContentName));
3152 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3153 video_transport_info.description.connection_role);
3154 video_transport_info.description.connection_role =
3155 cricket::CONNECTIONROLE_ACTIVE;
3156
3157 desc_.RemoveTransportInfoByName(kAudioContentName);
3158 desc_.RemoveTransportInfoByName(kVideoContentName);
3159
3160 desc_.AddTransportInfo(audio_transport_info);
3161 desc_.AddTransportInfo(video_transport_info);
3162
3163 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3164 jdesc_.session_id(),
3165 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003166 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003167 std::string sdp_with_dtlssetup = kSdpFullString;
3168
3169 // Fingerprint attribute is necessary to add DTLS setup attribute.
3170 InjectAfter(kAttributeIcePwdVoice,
3171 kFingerprint, &sdp_with_dtlssetup);
3172 InjectAfter(kAttributeIcePwdVideo,
3173 kFingerprint, &sdp_with_dtlssetup);
3174 // Now adding |setup| attribute.
3175 InjectAfter(kFingerprint,
3176 "a=setup:active\r\n", &sdp_with_dtlssetup);
3177 EXPECT_EQ(sdp_with_dtlssetup, message);
3178}
3179
3180TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003181 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003182 std::string sdp_with_dtlssetup = kSdpFullString;
3183 InjectAfter(kSessionTime,
3184 "a=setup:actpass\r\n",
3185 &sdp_with_dtlssetup);
3186 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3187 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3188 const cricket::TransportInfo* atinfo =
3189 desc->GetTransportInfoByName("audio_content_name");
3190 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3191 atinfo->description.connection_role);
3192 const cricket::TransportInfo* vtinfo =
3193 desc->GetTransportInfoByName("video_content_name");
3194 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3195 vtinfo->description.connection_role);
3196}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003197
3198// Verifies that the order of the serialized m-lines follows the order of the
3199// ContentInfo in SessionDescription, and vise versa for deserialization.
3200TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003201 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003202 const std::string media_content_sdps[3] = {
3203 kSdpAudioString,
3204 kSdpVideoString,
3205 kSdpSctpDataChannelString
3206 };
3207 const cricket::MediaType media_types[3] = {
3208 cricket::MEDIA_TYPE_AUDIO,
3209 cricket::MEDIA_TYPE_VIDEO,
3210 cricket::MEDIA_TYPE_DATA
3211 };
3212
3213 // Verifies all 6 permutations.
3214 for (size_t i = 0; i < 6; ++i) {
3215 size_t media_content_in_sdp[3];
3216 // The index of the first media content.
3217 media_content_in_sdp[0] = i / 2;
3218 // The index of the second media content.
3219 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3220 // The index of the third media content.
3221 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3222
3223 std::string sdp_string = kSdpSessionString;
3224 for (size_t i = 0; i < 3; ++i)
3225 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3226
3227 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3228 cricket::SessionDescription* desc = jdesc.description();
3229 EXPECT_EQ(3u, desc->contents().size());
3230
3231 for (size_t i = 0; i < 3; ++i) {
3232 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003233 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003234 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3235 }
3236
Steve Antone831b8c2018-02-01 12:22:16 -08003237 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003238 EXPECT_EQ(sdp_string, serialized_sdp);
3239 }
3240}
deadbeef9d3584c2016-02-16 17:54:10 -08003241
deadbeef25ed4352016-12-12 18:37:36 -08003242TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3243 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003244 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003245 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003246 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3247 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3248}
3249
deadbeef12771a12017-01-03 13:53:47 -08003250// The semantics of "a=bundle-only" are only defined when it's used in
3251// combination with a 0 port on the m= line. We should ignore it if used with a
3252// nonzero port.
3253TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3254 // Make the base bundle-only description but unset the bundle-only flag.
3255 MakeBundleOnlyDescription();
3256 jdesc_.description()->contents()[1].bundle_only = false;
3257
3258 std::string modified_sdp = kBundleOnlySdpFullString;
3259 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003260 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003261 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3262 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003263}
3264
3265TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3266 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003267 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003268}
3269
deadbeef9d3584c2016-02-16 17:54:10 -08003270TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3271 MakePlanBDescription();
3272
Steve Antona3a92c22017-12-07 10:27:41 -08003273 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003274 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3275
3276 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3277}
3278
3279TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3280 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003281 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003282}
3283
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003284// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3285// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3286// some extent). If we parse this, the Plan B msid attribute (which is more
3287// specific, since it's at the SSRC level) should take priority.
3288TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3289 MakePlanBDescription();
3290
Steve Antona3a92c22017-12-07 10:27:41 -08003291 JsepSessionDescription deserialized_description(kDummyType);
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003292 EXPECT_TRUE(
3293 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3294
3295 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3296}
3297
deadbeef9d3584c2016-02-16 17:54:10 -08003298TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3299 MakeUnifiedPlanDescription();
3300
Steve Antona3a92c22017-12-07 10:27:41 -08003301 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003302 EXPECT_TRUE(
3303 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3304
3305 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3306}
3307
3308TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3309 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003310 TestSerialize(jdesc_);
3311}
3312
3313TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3314 JsepSessionDescription jsep_desc(kDummyType);
3315 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3316 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3317}
3318
3319TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3320 JsepSessionDescription jsep_desc(kDummyType);
3321 std::string sdp = kSdpSessionString;
3322 sdp += kSdpSctpDataChannelString;
3323 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3324 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3325}
3326
3327TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3328 JsepSessionDescription jsep_desc(kDummyType);
3329 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3330 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3331 jsep_desc.description()->msid_signaling());
3332}
3333
3334TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3335 JsepSessionDescription jsep_desc(kDummyType);
3336 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3337 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3338 jsep_desc.description()->msid_signaling());
3339}
3340
3341const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3342const char kSsrcAttributeMsidLine[] =
3343 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3344
3345TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3346 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3347 std::string sdp = webrtc::SdpSerialize(jdesc_);
3348
3349 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3350 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3351}
3352
3353TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3354 jdesc_.description()->set_msid_signaling(
3355 cricket::kMsidSignalingSsrcAttribute);
3356 std::string sdp = webrtc::SdpSerialize(jdesc_);
3357
3358 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3359 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3360}
3361
3362TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3363 jdesc_.description()->set_msid_signaling(
3364 cricket::kMsidSignalingMediaSection |
3365 cricket::kMsidSignalingSsrcAttribute);
3366 std::string sdp = webrtc::SdpSerialize(jdesc_);
3367
3368 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3369 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003370}
deadbeef7e146cb2016-09-28 10:04:34 -07003371
3372// Regression test for heap overflow bug:
3373// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3374TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003375 // The issue occurs when the sctp-port attribute is found in a video
3376 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003377 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003378 "v=0\r\n"
3379 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3380 "s=-\r\n"
3381 "t=0 0\r\n"
3382 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3383 "a=sctp-port 5000\r\n"
3384 "a=fmtp:108 foo=10\r\n";
3385
3386 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3387 "sctp-port");
3388}
deadbeefb2362572016-12-13 16:37:06 -08003389
3390// Regression test for integer overflow bug:
3391// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3392TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003393 // Bandwidth attribute is the max signed 32-bit int, which will get
3394 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003395 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003396 "v=0\r\n"
3397 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3398 "s=-\r\n"
3399 "t=0 0\r\n"
3400 "m=video 3457 RTP/SAVPF 120\r\n"
3401 "b=AS:2147483647\r\n"
3402 "foo=fail\r\n";
3403
3404 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3405}
deadbeef7bcdb692017-01-20 12:43:58 -08003406
deadbeefbc88c6b2017-08-02 11:26:34 -07003407// Similar to the above, except that negative values are illegal, not just
3408// error-prone as large values are.
3409// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3410TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3411 static const char kSdpWithNegativeBandwidth[] =
3412 "v=0\r\n"
3413 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3414 "s=-\r\n"
3415 "t=0 0\r\n"
3416 "m=video 3457 RTP/SAVPF 120\r\n"
3417 "b=AS:-1000\r\n";
3418
3419 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3420}
3421
deadbeef3e8016e2017-08-03 17:49:30 -07003422// An exception to the above rule: a value of -1 for b=AS should just be
3423// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3424// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3425// limit", but this is now what ommitting the attribute entirely will do, so
3426// ignoring it will have the intended effect.
3427TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3428 static const char kSdpWithBandwidthOfNegativeOne[] =
3429 "v=0\r\n"
3430 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3431 "s=-\r\n"
3432 "t=0 0\r\n"
3433 "m=video 3457 RTP/SAVPF 120\r\n"
3434 "b=AS:-1\r\n";
3435
Steve Antona3a92c22017-12-07 10:27:41 -08003436 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003437 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003438 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003439 GetFirstVideoContentDescription(jdesc_output.description());
3440 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003441 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3442}
3443
deadbeef7bcdb692017-01-20 12:43:58 -08003444// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3445// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3446// Regression test for:
3447// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3448TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3449 // Important piece is "ufrag foo pwd bar".
3450 static const char kSdpWithIceCredentialsInCandidateString[] =
3451 "v=0\r\n"
3452 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3453 "s=-\r\n"
3454 "t=0 0\r\n"
3455 "m=audio 9 RTP/SAVPF 111\r\n"
3456 "c=IN IP4 0.0.0.0\r\n"
3457 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3458 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3459 "a=rtpmap:111 opus/48000/2\r\n"
3460 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3461 "generation 2 ufrag foo pwd bar\r\n";
3462
Steve Antona3a92c22017-12-07 10:27:41 -08003463 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003464 EXPECT_TRUE(
3465 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3466 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3467 ASSERT_NE(nullptr, candidates);
3468 ASSERT_EQ(1, candidates->count());
3469 cricket::Candidate c = candidates->at(0)->candidate();
3470 EXPECT_EQ("ufrag_voice", c.username());
3471 EXPECT_EQ("pwd_voice", c.password());
3472}
deadbeef90f1e1e2017-02-10 12:35:05 -08003473
3474// Test that SDP with an invalid port number in "a=candidate" lines is
3475// rejected, without crashing.
3476// Regression test for:
3477// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3478TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3479 static const char kSdpWithInvalidCandidatePort[] =
3480 "v=0\r\n"
3481 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3482 "s=-\r\n"
3483 "t=0 0\r\n"
3484 "m=audio 9 RTP/SAVPF 111\r\n"
3485 "c=IN IP4 0.0.0.0\r\n"
3486 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3487 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3488 "a=rtpmap:111 opus/48000/2\r\n"
3489 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3490 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3491
Steve Antona3a92c22017-12-07 10:27:41 -08003492 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003493 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3494}
deadbeefa4549d62017-02-10 17:26:22 -08003495
3496// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3497// Regression test for:
3498// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3499TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3500 static const char kSdpWithMissingTrackId[] =
3501 "v=0\r\n"
3502 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3503 "s=-\r\n"
3504 "t=0 0\r\n"
3505 "m=audio 9 RTP/SAVPF 111\r\n"
3506 "c=IN IP4 0.0.0.0\r\n"
3507 "a=rtpmap:111 opus/48000/2\r\n"
3508 "a=msid:stream_id \r\n";
3509
Steve Antona3a92c22017-12-07 10:27:41 -08003510 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003511 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3512}
3513
3514TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3515 static const char kSdpWithMissingStreamId[] =
3516 "v=0\r\n"
3517 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3518 "s=-\r\n"
3519 "t=0 0\r\n"
3520 "m=audio 9 RTP/SAVPF 111\r\n"
3521 "c=IN IP4 0.0.0.0\r\n"
3522 "a=rtpmap:111 opus/48000/2\r\n"
3523 "a=msid: track_id\r\n";
3524
Steve Antona3a92c22017-12-07 10:27:41 -08003525 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003526 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3527}
zhihuang38989e52017-03-21 11:04:53 -07003528
3529// Tests that if both session-level address and media-level address exist, use
3530// the media-level address.
3531TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003532 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003533
3534 // Sesssion-level address.
3535 std::string sdp = kSdpFullString;
3536 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3537 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3538
3539 const auto& content1 = jsep_desc.description()->contents()[0];
3540 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003541 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003542 const auto& content2 = jsep_desc.description()->contents()[1];
3543 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003544 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003545}
3546
3547// Tests that the session-level connection address will be used if the media
3548// level-addresses are not specified.
3549TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003550 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003551
3552 // Sesssion-level address.
3553 std::string sdp = kSdpString;
3554 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3555 // Remove the media level addresses.
3556 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3557 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3558 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3559
3560 const auto& content1 = jsep_desc.description()->contents()[0];
3561 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003562 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003563 const auto& content2 = jsep_desc.description()->contents()[1];
3564 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003565 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003566}
3567
3568TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003569 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003570
3571 std::string sdp = kSdpString;
3572 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3573 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3574 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3575 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3576 &sdp);
3577 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3578 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3579 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3580 &sdp);
3581 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3582 const auto& content1 = jsep_desc.description()->contents()[0];
3583 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003584 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003585 const auto& content2 = jsep_desc.description()->contents()[1];
3586 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003587 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003588}
3589
3590// Test that the invalid or unsupprted connection data cannot be parsed.
3591TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003592 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003593 std::string sdp = kSdpString;
3594 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3595
3596 // Unsupported multicast IPv4 address.
3597 sdp = kSdpFullString;
3598 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3599 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3600
3601 // Unsupported multicast IPv6 address.
3602 sdp = kSdpFullString;
3603 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3604 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3605
3606 // Mismatched address type.
3607 sdp = kSdpFullString;
3608 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3609 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3610
3611 sdp = kSdpFullString;
3612 Replace("c=IN IP4 74.125.224.39\r\n",
3613 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3614 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3615}
3616
3617TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003618 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003619 MakeDescriptionWithoutCandidates(&expected_jsep);
3620 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003621 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003622 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003623 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003624 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003625 auto audio_desc = jdesc.description()
3626 ->GetContentByName(kAudioContentName)
3627 ->media_description();
3628 auto video_desc = jdesc.description()
3629 ->GetContentByName(kVideoContentName)
3630 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003631 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3632 audio_desc->connection_address().ToString());
3633 EXPECT_EQ(video_desc_->connection_address().ToString(),
3634 video_desc->connection_address().ToString());
3635}