blob: c4cd7db2ddc87b640de54de0d34164dc212a61f3 [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;
45using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using cricket::RELAY_PORT_TYPE;
48using cricket::SessionDescription;
49using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
62using 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
772static const char kDummyString[] = "dummy";
773
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) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 JsepSessionDescription desc(kDummyString);
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:
868 WebRtcSdpTest()
869 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800870#ifdef WEBRTC_ANDROID
871 webrtc::InitializeAndroidObjects();
872#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 // AudioContentDescription
874 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800875 StreamParams audio_stream;
876 audio_stream.id = kAudioTrackId1;
877 audio_stream.cname = kStream1Cname;
878 audio_stream.sync_label = kStreamLabel1;
879 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
880 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700881 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
882 audio_desc_->set_connection_address(audio_addr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
884
885 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800886 video_desc_ = CreateVideoContentDescription();
887 StreamParams video_stream;
888 video_stream.id = kVideoTrackId1;
889 video_stream.cname = kStream1Cname;
890 video_stream.sync_label = kStreamLabel1;
891 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
892 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
893 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
894 video_stream.ssrc_groups.push_back(ssrc_group);
895 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700896 rtc::SocketAddress video_addr("74.125.224.39", 3457);
897 video_desc_->set_connection_address(video_addr);
deadbeef9d3584c2016-02-16 17:54:10 -0800898 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899
900 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800901 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
902 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
903 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
904 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905
906 // v4 host
907 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000908 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000909 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000910 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
911 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000913 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000914 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
915 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000917 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000918 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
919 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000921 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000922 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
923 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924
925 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000927 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
928 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000929 cricket::LOCAL_PORT_TYPE,
930 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000932 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
933 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000934 cricket::LOCAL_PORT_TYPE,
935 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000937 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
938 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000939 cricket::LOCAL_PORT_TYPE,
940 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000942 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
943 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000944 cricket::LOCAL_PORT_TYPE,
945 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946
947 // stun
948 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000949 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
950 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000951 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
952 address_stun, kCandidatePriority, "", "",
953 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000954 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 candidate9.set_related_address(rel_address_stun);
956
957 address_stun.SetPort(port_stun++);
958 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000959 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
960 address_stun, kCandidatePriority, "", "",
961 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000962 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 candidate10.set_related_address(rel_address_stun);
964
965 // relay
966 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000967 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000968 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
969 address_relay, kCandidatePriority, "", "",
970 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000971 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000973 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
974 address_relay, kCandidatePriority, "", "",
975 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000976 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977
978 // voice
979 candidates_.push_back(candidate1);
980 candidates_.push_back(candidate2);
981 candidates_.push_back(candidate5);
982 candidates_.push_back(candidate6);
983 candidates_.push_back(candidate9);
984 candidates_.push_back(candidate10);
985
986 // video
987 candidates_.push_back(candidate3);
988 candidates_.push_back(candidate4);
989 candidates_.push_back(candidate7);
990 candidates_.push_back(candidate8);
991 candidates_.push_back(candidate11);
992 candidates_.push_back(candidate12);
993
994 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
995 0, candidate1));
996
997 // Set up JsepSessionDescription.
998 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
999 std::string mline_id;
1000 int mline_index = 0;
1001 for (size_t i = 0; i< candidates_.size(); ++i) {
1002 // In this test, the audio m line index will be 0, and the video m line
1003 // will be 1.
1004 bool is_video = (i > 5);
1005 mline_id = is_video ? "video_content_name" : "audio_content_name";
1006 mline_index = is_video ? 1 : 0;
1007 JsepIceCandidate jice(mline_id,
1008 mline_index,
1009 candidates_.at(i));
1010 jdesc_.AddCandidate(&jice);
1011 }
1012 }
1013
deadbeef25ed4352016-12-12 18:37:36 -08001014 // Turns the existing reference description into a description using
1015 // a=bundle-only. This means no transport attributes and a 0 port value on
1016 // the m= sections not associated with the BUNDLE-tag.
1017 void MakeBundleOnlyDescription() {
1018 // Remove video candidates. JsepSessionDescription doesn't make it
1019 // simple.
1020 const IceCandidateCollection* video_candidates_collection =
1021 jdesc_.candidates(1);
1022 ASSERT_NE(nullptr, video_candidates_collection);
1023 std::vector<cricket::Candidate> video_candidates;
1024 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1025 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1026 c.set_transport_name("video_content_name");
1027 video_candidates.push_back(c);
1028 }
1029 jdesc_.RemoveCandidates(video_candidates);
1030
1031 // And the rest of the transport attributes.
1032 desc_.transport_infos()[1].description.ice_ufrag.clear();
1033 desc_.transport_infos()[1].description.ice_pwd.clear();
1034 desc_.transport_infos()[1].description.connection_role =
1035 cricket::CONNECTIONROLE_NONE;
1036
1037 // Set bundle-only flag.
1038 desc_.contents()[1].bundle_only = true;
1039
1040 // Add BUNDLE group.
1041 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1042 group.AddContentName(kAudioContentName);
1043 group.AddContentName(kVideoContentName);
1044 desc_.AddGroup(group);
1045
1046 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1047 jdesc_.session_version()));
1048 }
1049
deadbeef9d3584c2016-02-16 17:54:10 -08001050 // Turns the existing reference description into a plan B description,
1051 // with 2 audio tracks and 3 video tracks.
1052 void MakePlanBDescription() {
1053 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1054 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1055
1056 StreamParams audio_track_2;
1057 audio_track_2.id = kAudioTrackId2;
1058 audio_track_2.cname = kStream2Cname;
1059 audio_track_2.sync_label = kStreamLabel2;
1060 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1061 audio_desc_->AddStream(audio_track_2);
1062
1063 StreamParams video_track_2;
1064 video_track_2.id = kVideoTrackId2;
1065 video_track_2.cname = kStream2Cname;
1066 video_track_2.sync_label = kStreamLabel2;
1067 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1068 video_desc_->AddStream(video_track_2);
1069
1070 StreamParams video_track_3;
1071 video_track_3.id = kVideoTrackId3;
1072 video_track_3.cname = kStream2Cname;
1073 video_track_3.sync_label = kStreamLabel2;
1074 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1075 video_desc_->AddStream(video_track_3);
1076
1077 desc_.RemoveContentByName(kAudioContentName);
1078 desc_.RemoveContentByName(kVideoContentName);
1079 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1080 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1081
1082 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1083 jdesc_.session_version()));
1084 }
1085
1086 // Turns the existing reference description into a unified plan description,
1087 // with 2 audio tracks and 3 video tracks.
1088 void MakeUnifiedPlanDescription() {
1089 // Audio track 2.
1090 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1091 StreamParams audio_track_2;
1092 audio_track_2.id = kAudioTrackId2;
1093 audio_track_2.cname = kStream2Cname;
1094 audio_track_2.sync_label = kStreamLabel2;
1095 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1096 audio_desc_2->AddStream(audio_track_2);
1097 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1098 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1099 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001100 // Video track 2, in stream 2.
1101 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1102 StreamParams video_track_2;
1103 video_track_2.id = kVideoTrackId2;
1104 video_track_2.cname = kStream2Cname;
1105 video_track_2.sync_label = kStreamLabel2;
1106 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1107 video_desc_2->AddStream(video_track_2);
1108 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1109 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1110 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1111
1112 // Video track 3, in stream 2.
1113 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1114 StreamParams video_track_3;
1115 video_track_3.id = kVideoTrackId3;
1116 video_track_3.cname = kStream2Cname;
1117 video_track_3.sync_label = kStreamLabel2;
1118 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1119 video_desc_3->AddStream(video_track_3);
1120 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1121 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1122 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1123
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 =
1248 static_cast<const AudioContentDescription*>(c1.description);
1249 const AudioContentDescription* acd2 =
1250 static_cast<const AudioContentDescription*>(c2.description);
1251 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1252 }
1253
1254 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1255 if (IsVideoContent(&c1)) {
1256 const VideoContentDescription* vcd1 =
1257 static_cast<const VideoContentDescription*>(c1.description);
1258 const VideoContentDescription* vcd2 =
1259 static_cast<const VideoContentDescription*>(c2.description);
1260 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1261 }
1262
1263 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1264 if (IsDataContent(&c1)) {
1265 const DataContentDescription* dcd1 =
1266 static_cast<const DataContentDescription*>(c1.description);
1267 const DataContentDescription* dcd2 =
1268 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-17 19:48:38 -08001269 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 }
1271 }
1272
1273 // group
1274 const cricket::ContentGroups groups1 = desc1.groups();
1275 const cricket::ContentGroups groups2 = desc2.groups();
1276 EXPECT_EQ(groups1.size(), groups1.size());
1277 if (groups1.size() != groups2.size()) {
1278 ADD_FAILURE();
1279 return;
1280 }
1281 for (size_t i = 0; i < groups1.size(); ++i) {
1282 const cricket::ContentGroup group1 = groups1.at(i);
1283 const cricket::ContentGroup group2 = groups2.at(i);
1284 EXPECT_EQ(group1.semantics(), group2.semantics());
1285 const cricket::ContentNames names1 = group1.content_names();
1286 const cricket::ContentNames names2 = group2.content_names();
1287 EXPECT_EQ(names1.size(), names2.size());
1288 if (names1.size() != names2.size()) {
1289 ADD_FAILURE();
1290 return;
1291 }
1292 cricket::ContentNames::const_iterator iter1 = names1.begin();
1293 cricket::ContentNames::const_iterator iter2 = names2.begin();
1294 while (iter1 != names1.end()) {
1295 EXPECT_EQ(*iter1++, *iter2++);
1296 }
1297 }
1298
1299 // transport info
1300 const cricket::TransportInfos transports1 = desc1.transport_infos();
1301 const cricket::TransportInfos transports2 = desc2.transport_infos();
1302 EXPECT_EQ(transports1.size(), transports2.size());
1303 if (transports1.size() != transports2.size()) {
1304 ADD_FAILURE();
1305 return;
1306 }
1307 for (size_t i = 0; i < transports1.size(); ++i) {
1308 const cricket::TransportInfo transport1 = transports1.at(i);
1309 const cricket::TransportInfo transport2 = transports2.at(i);
1310 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(transport1.description.ice_ufrag,
1312 transport2.description.ice_ufrag);
1313 EXPECT_EQ(transport1.description.ice_pwd,
1314 transport2.description.ice_pwd);
1315 if (transport1.description.identity_fingerprint) {
1316 EXPECT_EQ(*transport1.description.identity_fingerprint,
1317 *transport2.description.identity_fingerprint);
1318 } else {
1319 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1320 transport2.description.identity_fingerprint.get());
1321 }
1322 EXPECT_EQ(transport1.description.transport_options,
1323 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 }
deadbeefc80741f2015-10-22 13:14:45 -07001325
1326 // global attributes
1327 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 }
1329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 bool CompareSessionDescription(
1331 const JsepSessionDescription& desc1,
1332 const JsepSessionDescription& desc2) {
1333 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1334 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1335 CompareSessionDescription(*desc1.description(), *desc2.description());
1336 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1337 return false;
1338 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1339 const IceCandidateCollection* cc1 = desc1.candidates(i);
1340 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001341 if (cc1->count() != cc2->count()) {
1342 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001344 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 for (size_t j = 0; j < cc1->count(); ++j) {
1346 const IceCandidateInterface* c1 = cc1->at(j);
1347 const IceCandidateInterface* c2 = cc2->at(j);
1348 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1349 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1350 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1351 }
1352 }
1353 return true;
1354 }
1355
1356 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1357 // them with invalid keywords so that the parser will just ignore them.
1358 bool RemoveCandidateUfragPwd(std::string* sdp) {
1359 const char ice_ufrag[] = "a=ice-ufrag";
1360 const char ice_ufragx[] = "a=xice-ufrag";
1361 const char ice_pwd[] = "a=ice-pwd";
1362 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001363 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001365 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 ice_pwdx, strlen(ice_pwdx), sdp);
1367 return true;
1368 }
1369
1370 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1371 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1372 const std::string& ufrag, const std::string& pwd) {
1373 std::string content_name;
1374 if (mline_index == 0) {
1375 content_name = kAudioContentName;
1376 } else if (mline_index == 1) {
1377 content_name = kVideoContentName;
1378 } else {
nissec80e7412017-01-11 05:56:46 -08001379 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 }
1381 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001382 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 SessionDescription* desc =
1384 const_cast<SessionDescription*>(jdesc->description());
1385 desc->RemoveTransportInfoByName(content_name);
1386 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1387 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1388 const IceCandidateCollection* cc = jdesc_.candidates(i);
1389 for (size_t j = 0; j < cc->count(); ++j) {
1390 if (cc->at(j)->sdp_mline_index() == mline_index) {
1391 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1392 ufrag);
1393 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1394 pwd);
1395 }
1396 }
1397 }
1398 return true;
1399 }
1400
1401 void AddIceOptions(const std::string& content_name,
1402 const std::vector<std::string>& transport_options) {
1403 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1404 cricket::TransportInfo transport_info =
1405 *(desc_.GetTransportInfoByName(content_name));
1406 desc_.RemoveTransportInfoByName(content_name);
1407 transport_info.description.transport_options = transport_options;
1408 desc_.AddTransportInfo(transport_info);
1409 }
1410
deadbeef3f7219b2015-12-28 15:17:14 -08001411 void SetIceUfragPwd(const std::string& content_name,
1412 const std::string& ice_ufrag,
1413 const std::string& ice_pwd) {
1414 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1415 cricket::TransportInfo transport_info =
1416 *(desc_.GetTransportInfoByName(content_name));
1417 desc_.RemoveTransportInfoByName(content_name);
1418 transport_info.description.ice_ufrag = ice_ufrag;
1419 transport_info.description.ice_pwd = ice_pwd;
1420 desc_.AddTransportInfo(transport_info);
1421 }
1422
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 void AddFingerprint() {
1424 desc_.RemoveTransportInfoByName(kAudioContentName);
1425 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001426 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 kIdentityDigest,
1428 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001429 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1430 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001431 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1432 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001433 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1434 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1435 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001436 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1437 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001438 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 }
1440
jbauch5869f502017-06-29 12:31:36 -07001441 void AddExtmap(bool encrypted) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 audio_desc_ = static_cast<AudioContentDescription*>(
1443 audio_desc_->Copy());
1444 video_desc_ = static_cast<VideoContentDescription*>(
1445 video_desc_->Copy());
jbauch5869f502017-06-29 12:31:36 -07001446 audio_desc_->AddRtpHeaderExtension(
1447 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1448 video_desc_->AddRtpHeaderExtension(
1449 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 desc_.RemoveContentByName(kAudioContentName);
1451 desc_.RemoveContentByName(kVideoContentName);
1452 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1453 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1454 }
1455
1456 void RemoveCryptos() {
1457 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1458 video_desc_->set_cryptos(std::vector<CryptoParams>());
1459 }
1460
Steve Anton4e70a722017-11-28 14:57:10 -08001461 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 audio_desc_->set_direction(direction);
1463 video_desc_->set_direction(direction);
1464 std::string new_sdp = kSdpFullString;
1465 ReplaceDirection(direction, &new_sdp);
1466
1467 if (!jdesc_.Initialize(desc_.Copy(),
1468 jdesc_.session_id(),
1469 jdesc_.session_version())) {
1470 return false;
1471 }
deadbeef9d3584c2016-02-16 17:54:10 -08001472 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_EQ(new_sdp, message);
1474 return true;
1475 }
1476
1477 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1478 audio_desc_ = static_cast<AudioContentDescription*>(
1479 audio_desc_->Copy());
1480 video_desc_ = static_cast<VideoContentDescription*>(
1481 video_desc_->Copy());
zhihuang38989e52017-03-21 11:04:53 -07001482
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 desc_.RemoveContentByName(kAudioContentName);
1484 desc_.RemoveContentByName(kVideoContentName);
1485 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1486 audio_desc_);
1487 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1488 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001489 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1490 audio_rejected ? "" : kPwdVoice);
1491 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1492 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001493
1494 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1496
deadbeef3f7219b2015-12-28 15:17:14 -08001497 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001498 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001499 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_EQ(new_sdp, message);
1501 return true;
1502 }
1503
zstein4b2e0822017-02-17 19:48:38 -08001504 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001505 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001507 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001509 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001510 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001511 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1512 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001514 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1515 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 }
1517
1518 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001519 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 data_desc_ = data.get();
1521
deadbeef67cf2c12016-04-13 10:07:16 -07001522 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 StreamParams data_stream;
1524 data_stream.id = kDataChannelMsid;
1525 data_stream.cname = kDataChannelCname;
1526 data_stream.sync_label = kDataChannelLabel;
1527 data_stream.ssrcs.push_back(kDataChannelSsrc);
1528 data_desc_->AddStream(data_stream);
1529 data_desc_->AddCrypto(CryptoParams(
1530 1, "AES_CM_128_HMAC_SHA1_80",
1531 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1532 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1533 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001534 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1535 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 }
1537
Steve Anton4e70a722017-11-28 14:57:10 -08001538 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 std::string new_sdp = kSdpFullString;
1540 ReplaceDirection(direction, &new_sdp);
1541 JsepSessionDescription new_jdesc(kDummyString);
1542
1543 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1544
1545 audio_desc_->set_direction(direction);
1546 video_desc_->set_direction(direction);
1547 if (!jdesc_.Initialize(desc_.Copy(),
1548 jdesc_.session_id(),
1549 jdesc_.session_version())) {
1550 return false;
1551 }
1552 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1553 return true;
1554 }
1555
1556 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001557 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1559 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001561
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 audio_desc_ = static_cast<AudioContentDescription*>(
1563 audio_desc_->Copy());
1564 video_desc_ = static_cast<VideoContentDescription*>(
1565 video_desc_->Copy());
1566 desc_.RemoveContentByName(kAudioContentName);
1567 desc_.RemoveContentByName(kVideoContentName);
1568 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1569 audio_desc_);
1570 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1571 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001572 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1573 audio_rejected ? "" : kPwdVoice);
1574 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1575 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001576 JsepSessionDescription jdesc_no_candidates(kDummyString);
1577 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1578 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 return false;
1580 }
deadbeef3f7219b2015-12-28 15:17:14 -08001581 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 return true;
1583 }
1584
jbauch5869f502017-06-29 12:31:36 -07001585 void TestDeserializeExtmap(bool session_level, bool media_level,
1586 bool encrypted) {
1587 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 JsepSessionDescription new_jdesc("dummy");
1589 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1590 jdesc_.session_id(),
1591 jdesc_.session_version()));
1592 JsepSessionDescription jdesc_with_extmap("dummy");
1593 std::string sdp_with_extmap = kSdpString;
1594 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001595 InjectAfter(kSessionTime,
1596 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1597 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 &sdp_with_extmap);
1599 }
1600 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001601 InjectAfter(kAttributeIcePwdVoice,
1602 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1603 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001605 InjectAfter(kAttributeIcePwdVideo,
1606 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1607 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 &sdp_with_extmap);
1609 }
1610 // The extmap can't be present at the same time in both session level and
1611 // media level.
1612 if (session_level && media_level) {
1613 SdpParseError error;
1614 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1615 &jdesc_with_extmap, &error));
1616 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1617 } else {
1618 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1619 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1620 }
1621 }
1622
1623 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1624 const std::string& name, int expected_value) {
1625 cricket::CodecParameterMap::const_iterator found = params.find(name);
1626 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001627 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 }
1629
1630 void TestDeserializeCodecParams(const CodecParams& params,
1631 JsepSessionDescription* jdesc_output) {
1632 std::string sdp =
1633 "v=0\r\n"
1634 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1635 "s=-\r\n"
1636 "t=0 0\r\n"
1637 // Include semantics for WebRTC Media Streams since it is supported by
1638 // this parser, and will be added to the SDP when serializing a session
1639 // description.
1640 "a=msid-semantic: WMS\r\n"
1641 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001642 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 // Pltype 111 listed before 103 and 104 in the map.
1644 "a=rtpmap:111 opus/48000/2\r\n"
1645 // Pltype 103 listed before 104.
1646 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001647 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001648 "a=fmtp:111 0-15,66,70\r\n"
1649 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001651 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001652 << "; sprop-stereo=" << params.sprop_stereo
1653 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001654 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 << "a=ptime:" << params.ptime << "\r\n"
1656 << "a=maxptime:" << params.max_ptime << "\r\n";
1657 sdp += os.str();
1658
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001659 os.clear();
1660 os.str("");
1661 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001662 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001663 << "a=rtpmap:99 VP8/90000\r\n"
1664 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001665 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001666 sdp += os.str();
1667
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 // Deserialize
1669 SdpParseError error;
1670 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1671
1672 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1673 ASSERT_TRUE(ac != NULL);
1674 const AudioContentDescription* acd =
1675 static_cast<const AudioContentDescription*>(ac->description);
1676 ASSERT_FALSE(acd->codecs().empty());
1677 cricket::AudioCodec opus = acd->codecs()[0];
1678 EXPECT_EQ("opus", opus.name);
1679 EXPECT_EQ(111, opus.id);
1680 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1681 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1682 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1683 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001684 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1685 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1687 cricket::AudioCodec codec = acd->codecs()[i];
1688 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1689 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001691
1692 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1693 ASSERT_TRUE(vc != NULL);
1694 const VideoContentDescription* vcd =
1695 static_cast<const VideoContentDescription*>(vc->description);
1696 ASSERT_FALSE(vcd->codecs().empty());
1697 cricket::VideoCodec vp8 = vcd->codecs()[0];
1698 EXPECT_EQ("VP8", vp8.name);
1699 EXPECT_EQ(99, vp8.id);
1700 cricket::VideoCodec rtx = vcd->codecs()[1];
1701 EXPECT_EQ("RTX", rtx.name);
1702 EXPECT_EQ(95, rtx.id);
1703 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 }
1705
1706 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1707 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001708 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 "v=0\r\n"
1710 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1711 "s=-\r\n"
1712 "t=0 0\r\n"
1713 // Include semantics for WebRTC Media Streams since it is supported by
1714 // this parser, and will be added to the SDP when serializing a session
1715 // description.
1716 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001717 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001718 "a=rtpmap:111 opus/48000/2\r\n";
1719 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 "m=video 3457 RTP/SAVPF 101\r\n"
1721 "a=rtpmap:101 VP8/90000\r\n"
1722 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001723 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001724 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001726 os << sdp_session_and_audio;
1727 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1728 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001730 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 // Deserialize
1732 SdpParseError error;
1733 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1734 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1735 ASSERT_TRUE(ac != NULL);
1736 const AudioContentDescription* acd =
1737 static_cast<const AudioContentDescription*>(ac->description);
1738 ASSERT_FALSE(acd->codecs().empty());
1739 cricket::AudioCodec opus = acd->codecs()[0];
1740 EXPECT_EQ(111, opus.id);
1741 EXPECT_TRUE(opus.HasFeedbackParam(
1742 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1743 cricket::kParamValueEmpty)));
1744
1745 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1746 ASSERT_TRUE(vc != NULL);
1747 const VideoContentDescription* vcd =
1748 static_cast<const VideoContentDescription*>(vc->description);
1749 ASSERT_FALSE(vcd->codecs().empty());
1750 cricket::VideoCodec vp8 = vcd->codecs()[0];
1751 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1752 vp8.name.c_str());
1753 EXPECT_EQ(101, vp8.id);
1754 EXPECT_TRUE(vp8.HasFeedbackParam(
1755 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1756 cricket::kParamValueEmpty)));
1757 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001758 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1759 cricket::kRtcpFbNackParamPli)));
1760 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1762 cricket::kParamValueEmpty)));
1763 EXPECT_TRUE(vp8.HasFeedbackParam(
1764 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1765 cricket::kRtcpFbCcmParamFir)));
1766 }
1767
1768 // Two SDP messages can mean the same thing but be different strings, e.g.
1769 // some of the lines can be serialized in different order.
1770 // However, a deserialized description can be compared field by field and has
1771 // no order. If deserializer has already been tested, serializing then
1772 // deserializing and comparing JsepSessionDescription will test
1773 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001774 void TestSerialize(const JsepSessionDescription& jdesc,
1775 bool unified_plan_sdp) {
1776 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 JsepSessionDescription jdesc_output_des(kDummyString);
1778 SdpParseError error;
1779 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1780 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1781 }
1782
zhihuang38989e52017-03-21 11:04:53 -07001783 // Calling 'Initialize' with a copy of the inner SessionDescription will
1784 // create a copy of the JsepSessionDescription without candidates. The
1785 // 'connection address' field, previously set from the candidates, must also
1786 // be reset.
1787 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1788 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1789 rtc::SocketAddress video_addr("0.0.0.0", 9);
1790 audio_desc_->set_connection_address(audio_addr);
1791 video_desc_->set_connection_address(video_addr);
1792 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1793 }
1794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 protected:
1796 SessionDescription desc_;
1797 AudioContentDescription* audio_desc_;
1798 VideoContentDescription* video_desc_;
1799 DataContentDescription* data_desc_;
1800 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001801 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 JsepSessionDescription jdesc_;
1803};
1804
1805void TestMismatch(const std::string& string1, const std::string& string2) {
1806 int position = 0;
1807 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1808 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001809 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 break;
1811 }
1812 }
1813 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1814 << " character\n"
1815 << " 1: " << string1.substr(position, 20) << "\n"
1816 << " 2: " << string2.substr(position, 20) << "\n";
1817}
1818
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1820 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001821 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 TestMismatch(std::string(kSdpFullString), message);
1823}
1824
1825TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1826 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001827 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828}
1829
1830// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1831// the case in a DTLS offer.
1832TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1833 AddFingerprint();
1834 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001835 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001836 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
1838 std::string sdp_with_fingerprint = kSdpString;
1839 InjectAfter(kAttributeIcePwdVoice,
1840 kFingerprint, &sdp_with_fingerprint);
1841 InjectAfter(kAttributeIcePwdVideo,
1842 kFingerprint, &sdp_with_fingerprint);
1843
1844 EXPECT_EQ(sdp_with_fingerprint, message);
1845}
1846
1847// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1848// be the case in a DTLS answer.
1849TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1850 AddFingerprint();
1851 RemoveCryptos();
1852 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001853 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001854 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855
1856 std::string sdp_with_fingerprint = kSdpString;
1857 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1858 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1859 InjectAfter(kAttributeIcePwdVoice,
1860 kFingerprint, &sdp_with_fingerprint);
1861 InjectAfter(kAttributeIcePwdVideo,
1862 kFingerprint, &sdp_with_fingerprint);
1863
1864 EXPECT_EQ(sdp_with_fingerprint, message);
1865}
1866
1867TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1868 // JsepSessionDescription with desc but without candidates.
1869 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001870 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001871 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 EXPECT_EQ(std::string(kSdpString), message);
1873}
1874
1875TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1876 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1877 group.AddContentName(kAudioContentName);
1878 group.AddContentName(kVideoContentName);
1879 desc_.AddGroup(group);
1880 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1881 jdesc_.session_id(),
1882 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001883 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 std::string sdp_with_bundle = kSdpFullString;
1885 InjectAfter(kSessionTime,
1886 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1887 &sdp_with_bundle);
1888 EXPECT_EQ(sdp_with_bundle, message);
1889}
1890
1891TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1892 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1893 GetFirstVideoContent(&desc_)->description);
1894 vcd->set_bandwidth(100 * 1000);
1895 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1896 GetFirstAudioContent(&desc_)->description);
1897 acd->set_bandwidth(50 * 1000);
1898 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1899 jdesc_.session_id(),
1900 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001901 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001903 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 "b=AS:100\r\n",
1905 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001906 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 "b=AS:50\r\n",
1908 &sdp_with_bandwidth);
1909 EXPECT_EQ(sdp_with_bandwidth, message);
1910}
1911
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1913 std::vector<std::string> transport_options;
1914 transport_options.push_back(kIceOption1);
1915 transport_options.push_back(kIceOption3);
1916 AddIceOptions(kAudioContentName, transport_options);
1917 transport_options.clear();
1918 transport_options.push_back(kIceOption2);
1919 transport_options.push_back(kIceOption3);
1920 AddIceOptions(kVideoContentName, transport_options);
1921 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1922 jdesc_.session_id(),
1923 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001924 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 std::string sdp_with_ice_options = kSdpFullString;
1926 InjectAfter(kAttributeIcePwdVoice,
1927 "a=ice-options:iceoption1 iceoption3\r\n",
1928 &sdp_with_ice_options);
1929 InjectAfter(kAttributeIcePwdVideo,
1930 "a=ice-options:iceoption2 iceoption3\r\n",
1931 &sdp_with_ice_options);
1932 EXPECT_EQ(sdp_with_ice_options, message);
1933}
1934
1935TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001936 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937}
1938
1939TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001940 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941}
1942
1943TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08001944 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945}
1946
1947TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1948 EXPECT_TRUE(TestSerializeRejected(true, false));
1949}
1950
1951TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1952 EXPECT_TRUE(TestSerializeRejected(false, true));
1953}
1954
1955TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1956 EXPECT_TRUE(TestSerializeRejected(true, true));
1957}
1958
1959TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1960 AddRtpDataChannel();
1961 JsepSessionDescription jsep_desc(kDummyString);
1962
zhihuang38989e52017-03-21 11:04:53 -07001963 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001964 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
1966 std::string expected_sdp = kSdpString;
1967 expected_sdp.append(kSdpRtpDataChannelString);
1968 EXPECT_EQ(expected_sdp, message);
1969}
1970
1971TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08001972 bool use_sctpmap = true;
1973 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 JsepSessionDescription jsep_desc(kDummyString);
1975
zhihuang38989e52017-03-21 11:04:53 -07001976 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001977 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978
1979 std::string expected_sdp = kSdpString;
1980 expected_sdp.append(kSdpSctpDataChannelString);
1981 EXPECT_EQ(message, expected_sdp);
1982}
1983
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001984TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08001985 bool use_sctpmap = true;
1986 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001987 JsepSessionDescription jsep_desc(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001988 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001989 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1990 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1991
1992 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001993 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001994 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001995 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1996 dcdesc->AddOrReplaceCodec(codec);
1997
deadbeef9d3584c2016-02-16 17:54:10 -08001998 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001999
2000 std::string expected_sdp = kSdpString;
2001 expected_sdp.append(kSdpSctpDataChannelString);
2002
2003 char default_portstr[16];
2004 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002005 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002006 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002007 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2008 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002009 new_portstr, strlen(new_portstr),
2010 &expected_sdp);
2011
2012 EXPECT_EQ(expected_sdp, message);
2013}
2014
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002015TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
zhihuang38989e52017-03-21 11:04:53 -07002016 JsepSessionDescription jsep_desc(kDummyString);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002017 AddRtpDataChannel();
2018 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002019 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08002020 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002021
2022 std::string expected_sdp = kSdpString;
2023 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002024 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002025 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 +00002026 "b=AS:100\r\n",
2027 &expected_sdp);
2028 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002029}
2030
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002032 bool encrypted = false;
2033 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 JsepSessionDescription desc_with_extmap("dummy");
zhihuang38989e52017-03-21 11:04:53 -07002035 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-16 17:54:10 -08002036 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037
2038 std::string sdp_with_extmap = kSdpString;
2039 InjectAfter("a=mid:audio_content_name\r\n",
2040 kExtmap, &sdp_with_extmap);
2041 InjectAfter("a=mid:video_content_name\r\n",
2042 kExtmap, &sdp_with_extmap);
2043
2044 EXPECT_EQ(sdp_with_extmap, message);
2045}
2046
jbauch5869f502017-06-29 12:31:36 -07002047TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2048 bool encrypted = true;
2049 AddExtmap(encrypted);
2050 JsepSessionDescription desc_with_extmap("dummy");
2051 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2052 kSessionId, kSessionVersion));
2053 TestSerialize(desc_with_extmap, false);
2054}
2055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056TEST_F(WebRtcSdpTest, SerializeCandidates) {
2057 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002058 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002059
2060 Candidate candidate_with_ufrag(candidates_.front());
2061 candidate_with_ufrag.set_username("ABC");
2062 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2063 candidate_with_ufrag));
2064 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2065 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002066
2067 Candidate candidate_with_network_info(candidates_.front());
2068 candidate_with_network_info.set_network_id(1);
2069 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2070 candidate_with_network_info));
2071 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2072 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2073 candidate_with_network_info.set_network_cost(999);
2074 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2075 candidate_with_network_info));
2076 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2077 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2078 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002081// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2082// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002083TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002084 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002085 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2086 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2087 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002088 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002089 std::unique_ptr<IceCandidateInterface> jcandidate(
2090 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002091
2092 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2093 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2094}
2095
htaa6b99442016-04-12 10:29:17 -07002096TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002097 cricket::VideoCodec h264_codec("H264");
2098 h264_codec.SetParam("profile-level-id", "42e01f");
2099 h264_codec.SetParam("level-asymmetry-allowed", "1");
2100 h264_codec.SetParam("packetization-mode", "1");
2101 video_desc_->AddCodec(h264_codec);
2102
htaa6b99442016-04-12 10:29:17 -07002103 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2104
2105 std::string message = webrtc::SdpSerialize(jdesc_, false);
2106 size_t after_pt = message.find(" H264/90000");
2107 ASSERT_NE(after_pt, std::string::npos);
2108 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2109 ASSERT_NE(before_pt, std::string::npos);
2110 before_pt += strlen("a=rtpmap:");
2111 std::string pt = message.substr(before_pt, after_pt - before_pt);
2112 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2113 std::string to_find = "a=fmtp:" + pt + " ";
2114 size_t fmtp_pos = message.find(to_find);
2115 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2116 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2117 ASSERT_NE(std::string::npos, fmtp_endpos);
2118 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2119 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2120 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2121 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002122 // Check that there are no spaces after semicolons.
2123 // https://bugs.webrtc.org/5793
2124 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002125}
2126
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2128 JsepSessionDescription jdesc(kDummyString);
2129 // Deserialize
2130 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2131 // Verify
2132 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2133}
2134
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002135TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2136 JsepSessionDescription jdesc(kDummyString);
2137 const char kSdpWithoutMline[] =
2138 "v=0\r\n"
2139 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2140 "s=-\r\n"
2141 "t=0 0\r\n"
2142 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2143 // Deserialize
2144 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2145 EXPECT_EQ(0u, jdesc.description()->contents().size());
2146}
2147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2149 JsepSessionDescription jdesc(kDummyString);
2150 std::string sdp_without_carriage_return = kSdpFullString;
2151 Replace("\r\n", "\n", &sdp_without_carriage_return);
2152 // Deserialize
2153 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2154 // Verify
2155 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2156}
2157
2158TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2159 // SessionDescription with desc but without candidates.
2160 JsepSessionDescription jdesc_no_candidates(kDummyString);
2161 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2162 kSessionId, kSessionVersion));
2163 JsepSessionDescription new_jdesc(kDummyString);
2164 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2165 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2166}
2167
2168TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2169 static const char kSdpNoRtpmapString[] =
2170 "v=0\r\n"
2171 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2172 "s=-\r\n"
2173 "t=0 0\r\n"
2174 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2175 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002176 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 // The rtpmap line for static payload codec is optional.
2178 "a=rtpmap:18 G729/16000\r\n"
2179 "a=rtpmap:103 ISAC/16000\r\n";
2180
2181 JsepSessionDescription jdesc(kDummyString);
2182 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2183 cricket::AudioContentDescription* audio =
2184 static_cast<AudioContentDescription*>(
2185 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2186 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002187 // The codecs in the AudioContentDescription should be in the same order as
2188 // the payload types (<fmt>s) on the m= line.
2189 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2190 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002191 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 EXPECT_EQ(ref_codecs, audio->codecs());
2193}
2194
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002195TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2196 static const char kSdpNoRtpmapString[] =
2197 "v=0\r\n"
2198 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2199 "s=-\r\n"
2200 "t=0 0\r\n"
2201 "m=audio 49232 RTP/AVP 18 103\r\n"
2202 "a=fmtp:18 annexb=yes\r\n"
2203 "a=rtpmap:103 ISAC/16000\r\n";
2204
2205 JsepSessionDescription jdesc(kDummyString);
2206 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2207 cricket::AudioContentDescription* audio =
2208 static_cast<AudioContentDescription*>(
2209 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2210
2211 cricket::AudioCodec g729 = audio->codecs()[0];
2212 EXPECT_EQ("G729", g729.name);
2213 EXPECT_EQ(8000, g729.clockrate);
2214 EXPECT_EQ(18, g729.id);
2215 cricket::CodecParameterMap::iterator found =
2216 g729.params.find("annexb");
2217 ASSERT_TRUE(found != g729.params.end());
2218 EXPECT_EQ(found->second, "yes");
2219
2220 cricket::AudioCodec isac = audio->codecs()[1];
2221 EXPECT_EQ("ISAC", isac.name);
2222 EXPECT_EQ(103, isac.id);
2223 EXPECT_EQ(16000, isac.clockrate);
2224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226// Ensure that we can deserialize SDP with a=fingerprint properly.
2227TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2228 // Add a DTLS a=fingerprint attribute to our session description.
2229 AddFingerprint();
2230 JsepSessionDescription new_jdesc(kDummyString);
2231 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2232 jdesc_.session_id(),
2233 jdesc_.session_version()));
2234
2235 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2236 std::string sdp_with_fingerprint = kSdpString;
2237 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2238 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2239 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2240 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2241}
2242
2243TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2244 JsepSessionDescription jdesc_with_bundle(kDummyString);
2245 std::string sdp_with_bundle = kSdpFullString;
2246 InjectAfter(kSessionTime,
2247 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2248 &sdp_with_bundle);
2249 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2250 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2251 group.AddContentName(kAudioContentName);
2252 group.AddContentName(kVideoContentName);
2253 desc_.AddGroup(group);
2254 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2255 jdesc_.session_id(),
2256 jdesc_.session_version()));
2257 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2258}
2259
2260TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2261 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2262 std::string sdp_with_bandwidth = kSdpFullString;
2263 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2264 "b=AS:100\r\n",
2265 &sdp_with_bandwidth);
2266 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2267 "b=AS:50\r\n",
2268 &sdp_with_bandwidth);
2269 EXPECT_TRUE(
2270 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2271 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2272 GetFirstVideoContent(&desc_)->description);
2273 vcd->set_bandwidth(100 * 1000);
2274 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2275 GetFirstAudioContent(&desc_)->description);
2276 acd->set_bandwidth(50 * 1000);
2277 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2278 jdesc_.session_id(),
2279 jdesc_.session_version()));
2280 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2281}
2282
2283TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2284 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2285 std::string sdp_with_ice_options = kSdpFullString;
2286 InjectAfter(kSessionTime,
2287 "a=ice-options:iceoption3\r\n",
2288 &sdp_with_ice_options);
2289 InjectAfter(kAttributeIcePwdVoice,
2290 "a=ice-options:iceoption1\r\n",
2291 &sdp_with_ice_options);
2292 InjectAfter(kAttributeIcePwdVideo,
2293 "a=ice-options:iceoption2\r\n",
2294 &sdp_with_ice_options);
2295 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2296 std::vector<std::string> transport_options;
2297 transport_options.push_back(kIceOption3);
2298 transport_options.push_back(kIceOption1);
2299 AddIceOptions(kAudioContentName, transport_options);
2300 transport_options.clear();
2301 transport_options.push_back(kIceOption3);
2302 transport_options.push_back(kIceOption2);
2303 AddIceOptions(kVideoContentName, transport_options);
2304 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2305 jdesc_.session_id(),
2306 jdesc_.session_version()));
2307 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2308}
2309
2310TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2311 // Remove the original ice-ufrag and ice-pwd
2312 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2313 std::string sdp_with_ufrag_pwd = kSdpFullString;
2314 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2315 // Add session level ufrag and pwd
2316 InjectAfter(kSessionTime,
2317 "a=ice-pwd:session+level+icepwd\r\n"
2318 "a=ice-ufrag:session+level+iceufrag\r\n",
2319 &sdp_with_ufrag_pwd);
2320 // Add media level ufrag and pwd for audio
2321 InjectAfter("a=mid:audio_content_name\r\n",
2322 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2323 &sdp_with_ufrag_pwd);
2324 // Update the candidate ufrag and pwd to the expected ones.
2325 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2326 "media+level+iceufrag", "media+level+icepwd"));
2327 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2328 "session+level+iceufrag", "session+level+icepwd"));
2329 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2330 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2331}
2332
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002334 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002338 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002342 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343}
2344
2345TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2346 EXPECT_TRUE(TestDeserializeRejected(true, false));
2347}
2348
2349TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2350 EXPECT_TRUE(TestDeserializeRejected(false, true));
2351}
2352
2353TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2354 EXPECT_TRUE(TestDeserializeRejected(true, true));
2355}
2356
2357// Tests that we can still handle the sdp uses mslabel and label instead of
2358// msid for backward compatibility.
2359TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002360 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 JsepSessionDescription jdesc(kDummyString);
2362 std::string sdp_without_msid = kSdpFullString;
2363 Replace("msid", "xmsid", &sdp_without_msid);
2364 // Deserialize
2365 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2366 // Verify
2367 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2368}
2369
2370TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2371 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2372
2373 std::string sdp = kSdpOneCandidate;
2374 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2375 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2376 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2377 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002378 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 // Candidate line without generation extension.
2381 sdp = kSdpOneCandidate;
2382 Replace(" generation 2", "", &sdp);
2383 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2384 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2385 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2386 Candidate expected = jcandidate_->candidate();
2387 expected.set_generation(0);
2388 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2389
honghaiza0c44ea2016-03-23 16:07:48 -07002390 // Candidate with network id and/or cost.
2391 sdp = kSdpOneCandidate;
2392 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2393 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2394 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2395 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2396 expected = jcandidate_->candidate();
2397 expected.set_network_id(2);
2398 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2399 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2400 // Add network cost
2401 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2402 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2403 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2404 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2405
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002406 sdp = kSdpTcpActiveCandidate;
2407 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2408 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002409 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002410 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2411 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2412 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002413 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2414 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002415 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2416 jcandidate_template->candidate()));
2417 sdp = kSdpTcpPassiveCandidate;
2418 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2419 sdp = kSdpTcpSOCandidate;
2420 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421}
2422
2423// This test verifies the deserialization of candidate-attribute
2424// as per RFC 5245. Candiate-attribute will be of the format
2425// candidate:<blah>. This format will be used when candidates
2426// are trickled.
2427TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2428 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2429
2430 std::string candidate_attribute = kRawCandidate;
2431 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2432 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2433 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2434 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2435 EXPECT_EQ(2u, jcandidate.candidate().generation());
2436
2437 // Candidate line without generation extension.
2438 candidate_attribute = kRawCandidate;
2439 Replace(" generation 2", "", &candidate_attribute);
2440 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2441 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2442 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2443 Candidate expected = jcandidate_->candidate();
2444 expected.set_generation(0);
2445 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2446
2447 // Candidate line without candidate:
2448 candidate_attribute = kRawCandidate;
2449 Replace("candidate:", "", &candidate_attribute);
2450 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2451
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002452 // Candidate line with IPV6 address.
2453 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2454}
2455
2456// This test verifies that the deserialization of an invalid candidate string
2457// fails.
2458TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2459 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2460
2461 std::string candidate_attribute = kRawCandidate;
2462 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002464
2465 candidate_attribute = kSdpOneCandidate;
2466 candidate_attribute.replace(0, 1, "x");
2467 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2468
2469 candidate_attribute = kRawCandidate;
2470 candidate_attribute.append("\r\n");
2471 candidate_attribute.append(kRawCandidate);
2472 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2473
2474 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475}
2476
2477TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2478 AddRtpDataChannel();
2479 JsepSessionDescription jdesc(kDummyString);
2480 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2481
2482 std::string sdp_with_data = kSdpString;
2483 sdp_with_data.append(kSdpRtpDataChannelString);
2484 JsepSessionDescription jdesc_output(kDummyString);
2485
2486 // Deserialize
2487 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2488 // Verify
2489 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2490}
2491
2492TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002493 bool use_sctpmap = true;
2494 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 JsepSessionDescription jdesc(kDummyString);
2496 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2497
2498 std::string sdp_with_data = kSdpString;
2499 sdp_with_data.append(kSdpSctpDataChannelString);
2500 JsepSessionDescription jdesc_output(kDummyString);
2501
lally@webrtc.org36300852015-02-24 20:19:35 +00002502 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2503 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2505
2506 // Verify with UDP/DTLS/SCTP.
2507 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2508 strlen(kDtlsSctp), kUdpDtlsSctp);
2509 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2510 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2511
2512 // Verify with TCP/DTLS/SCTP.
2513 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2514 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2516 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2517}
2518
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002519TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002520 bool use_sctpmap = false;
2521 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002522 JsepSessionDescription jdesc(kDummyString);
2523 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2524
2525 std::string sdp_with_data = kSdpString;
2526 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2527 JsepSessionDescription jdesc_output(kDummyString);
2528
lally@webrtc.org36300852015-02-24 20:19:35 +00002529 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002530 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2531 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002532
lally@webrtc.org36300852015-02-24 20:19:35 +00002533 // Verify with UDP/DTLS/SCTP.
2534 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2535 strlen(kDtlsSctp), kUdpDtlsSctp);
2536 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2537 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002538
lally@webrtc.org36300852015-02-24 20:19:35 +00002539 // Verify with TCP/DTLS/SCTP.
2540 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2541 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002542 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2543 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2544}
2545
lally69f57602015-10-08 10:15:04 -07002546TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002547 bool use_sctpmap = false;
2548 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 10:15:04 -07002549 JsepSessionDescription jdesc(kDummyString);
2550 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2551
2552 std::string sdp_with_data = kSdpString;
2553 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2554 JsepSessionDescription jdesc_output(kDummyString);
2555
2556 // Verify with DTLS/SCTP.
2557 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2558 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2559
2560 // Verify with UDP/DTLS/SCTP.
2561 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2562 strlen(kDtlsSctp), kUdpDtlsSctp);
2563 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2564 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2565
2566 // Verify with TCP/DTLS/SCTP.
2567 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2568 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2569 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2570 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2571}
2572
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002573// Test to check the behaviour if sctp-port is specified
2574// on the m= line and in a=sctp-port.
2575TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002576 bool use_sctpmap = true;
2577 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002578 JsepSessionDescription jdesc(kDummyString);
2579 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2580
2581 std::string sdp_with_data = kSdpString;
2582 // Append m= attributes
2583 sdp_with_data.append(kSdpSctpDataChannelString);
2584 // Append a=sctp-port attribute
2585 sdp_with_data.append("a=sctp-port 5000\r\n");
2586 JsepSessionDescription jdesc_output(kDummyString);
2587
2588 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2589}
2590
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002591// For crbug/344475.
2592TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2593 std::string sdp_with_data = kSdpString;
2594 sdp_with_data.append(kSdpSctpDataChannelString);
2595 // Remove the "\n" at the end.
2596 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2597 JsepSessionDescription jdesc_output(kDummyString);
2598
2599 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2600 // No crash is a pass.
2601}
2602
Steve Anton36b29d12017-10-30 09:57:42 -07002603void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002604 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002605 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002606 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:02 +00002607 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2608 mutant->GetContentDescriptionByName(kDataContentName));
2609 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002610 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002611 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002612 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002613 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002614
2615 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002616 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002617 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002618}
2619
2620TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2621 bool use_sctpmap = true;
2622 AddSctpDataChannel(use_sctpmap);
2623
2624 // First setup the expected JsepSessionDescription.
2625 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 09:57:42 -07002626 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002627
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002628 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002629 std::string sdp_with_data = kSdpString;
2630 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002631 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2632 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2633 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:02 +00002634 JsepSessionDescription jdesc_output(kDummyString);
2635
2636 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2637 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002638}
2639
2640TEST_F(WebRtcSdpTest,
2641 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2642 bool use_sctpmap = false;
2643 AddSctpDataChannel(use_sctpmap);
2644
2645 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 09:57:42 -07002646 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002647
2648 // We need to test the deserialized JsepSessionDescription from
2649 // kSdpSctpDataChannelStringWithSctpPort for
2650 // draft-ietf-mmusic-sctp-sdp-07
2651 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002652 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002653 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002654 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2655 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2656 &sdp_with_data);
2657 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002658
2659 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2660 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002661}
2662
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002663TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002664 // We want to test that deserializing data content limits bandwidth
2665 // settings (it should never be greater than the default).
2666 // This should prevent someone from using unlimited data bandwidth through
2667 // JS and "breaking the Internet".
2668 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002669 std::string sdp_with_bandwidth = kSdpString;
2670 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2671 InjectAfter("a=mid:data_content_name\r\n",
2672 "b=AS:100\r\n",
2673 &sdp_with_bandwidth);
2674 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2675
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002676 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2677}
2678
2679TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002680 bool use_sctpmap = true;
2681 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002682 JsepSessionDescription jdesc(kDummyString);
2683 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2684 GetFirstDataContent(&desc_)->description);
2685 dcd->set_bandwidth(100 * 1000);
2686 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2687
2688 std::string sdp_with_bandwidth = kSdpString;
2689 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2690 InjectAfter("a=mid:data_content_name\r\n",
2691 "b=AS:100\r\n",
2692 &sdp_with_bandwidth);
2693 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2694
2695 // SCTP has congestion control, so we shouldn't limit the bandwidth
2696 // as we do for RTP.
2697 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2699}
2700
jbauch5869f502017-06-29 12:31:36 -07002701class WebRtcSdpExtmapTest
2702 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2703};
2704
2705TEST_P(WebRtcSdpExtmapTest,
2706 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2707 bool encrypted = GetParam();
2708 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709}
2710
jbauch5869f502017-06-29 12:31:36 -07002711TEST_P(WebRtcSdpExtmapTest,
2712 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2713 bool encrypted = GetParam();
2714 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715}
2716
jbauch5869f502017-06-29 12:31:36 -07002717TEST_P(WebRtcSdpExtmapTest,
2718 DeserializeSessionDescriptionWithInvalidExtmap) {
2719 bool encrypted = GetParam();
2720 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721}
2722
jbauch5869f502017-06-29 12:31:36 -07002723INSTANTIATE_TEST_CASE_P(Encrypted,
2724 WebRtcSdpExtmapTest,
2725 ::testing::Values(false, true));
2726
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002727TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2728 JsepSessionDescription jdesc(kDummyString);
2729 std::string sdp = kSdpFullString;
2730 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2731 // Deserialize
2732 SdpParseError error;
2733 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002734 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002735 EXPECT_EQ(lastline, error.line);
2736 EXPECT_EQ("Invalid SDP line.", error.description);
2737}
2738
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2740 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2741 std::string new_sdp = kSdpOneCandidate;
2742 Replace("udp", "unsupported_transport", &new_sdp);
2743 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2744 new_sdp = kSdpOneCandidate;
2745 Replace("udp", "uDP", &new_sdp);
2746 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2747 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2748 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2749 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2750}
2751
honghaiza54a0802015-12-16 18:37:23 -08002752TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002754 EXPECT_TRUE(
2755 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2757 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2758 Candidate ref_candidate = jcandidate_->candidate();
2759 ref_candidate.set_username("user_rtp");
2760 ref_candidate.set_password("password_rtp");
2761 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2762}
2763
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002764TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2765 JsepSessionDescription jdesc(kDummyString);
2766
2767 // Deserialize
2768 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2769
2770 // Verify
2771 cricket::AudioContentDescription* audio =
2772 static_cast<AudioContentDescription*>(
2773 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2774 EXPECT_TRUE(audio->conference_mode());
2775
2776 cricket::VideoContentDescription* video =
2777 static_cast<VideoContentDescription*>(
2778 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2779 EXPECT_TRUE(video->conference_mode());
2780}
2781
deadbeefd45aea82017-09-16 01:24:29 -07002782TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
2783 JsepSessionDescription jdesc(kDummyString);
2784
2785 // We tested deserialization already above, so just test that if we serialize
2786 // and deserialize the flag doesn't disappear.
2787 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2788 std::string reserialized = webrtc::SdpSerialize(jdesc, false);
2789 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2790
2791 // Verify.
2792 cricket::AudioContentDescription* audio =
2793 static_cast<AudioContentDescription*>(
2794 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2795 EXPECT_TRUE(audio->conference_mode());
2796
2797 cricket::VideoContentDescription* video =
2798 static_cast<VideoContentDescription*>(
2799 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2800 EXPECT_TRUE(video->conference_mode());
2801}
2802
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2804 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002805 const char kSdpEmptyType[] = " =candidate";
2806 const char kSdpEqualAsPlus[] = "a+candidate";
2807 const char kSdpSpaceAfterEqual[] = "a= candidate";
2808 const char kSdpUpperType[] = "A=candidate";
2809 const char kSdpEmptyLine[] = "";
2810 const char kSdpMissingValue[] = "a=";
2811
2812 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 "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 +00002814 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 "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 +00002816 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 "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 +00002818 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002819 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002820 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821
2822 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002823 ExpectParseFailure("v=", kSdpDestroyer);
2824 ExpectParseFailure("o=", kSdpDestroyer);
2825 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002827 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828
2829 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002830 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2831 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002832
2833 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002834 ExpectParseFailure("a=candidate", kSdpEmptyType);
2835 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2836 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2837 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838
2839 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2840 // because it's orthogonal to what we are replacing and hence
2841 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002842 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2843 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2844 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2845 ExpectParseFailure("a=sendrecv", kSdpMd5);
2846
2847 // Empty Line
2848 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2849 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002850}
2851
2852TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2853 // ssrc
2854 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002855 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002856 // crypto
2857 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2858 // rtpmap
2859 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2860 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2861 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2862 // candidate
2863 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2864 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2865 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2866 ExpectParseFailure("rport 2346", "rport badvalue");
2867 ExpectParseFailure("rport 2346 generation 2",
2868 "rport 2346 generation badvalue");
2869 // m line
2870 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2871 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2872
2873 // bandwidth
2874 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2875 "b=AS:badvalue\r\n",
2876 "b=AS:badvalue");
2877 // rtcp-fb
2878 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2879 "a=rtcp-fb:badvalue nack\r\n",
2880 "a=rtcp-fb:badvalue nack");
2881 // extmap
2882 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2883 "a=extmap:badvalue http://example.com\r\n",
2884 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885}
2886
2887TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2888 JsepSessionDescription jdesc_output(kDummyString);
2889
2890 const char kSdpWithReorderedPlTypesString[] =
2891 "v=0\r\n"
2892 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2893 "s=-\r\n"
2894 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002895 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2897 // in the map.
2898 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002899 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900
2901 // Deserialize
2902 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2903
2904 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2905 ASSERT_TRUE(ac != NULL);
2906 const AudioContentDescription* acd =
2907 static_cast<const AudioContentDescription*>(ac->description);
2908 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002909 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2910 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 EXPECT_EQ(104, acd->codecs()[0].id);
2912}
2913
2914TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2915 JsepSessionDescription jdesc_output(kDummyString);
2916 CodecParams params;
2917 params.max_ptime = 40;
2918 params.ptime = 30;
2919 params.min_ptime = 10;
2920 params.sprop_stereo = 1;
2921 params.stereo = 1;
2922 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002923 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002924 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002925 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926}
2927
2928TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2929 const bool kUseWildcard = false;
2930 JsepSessionDescription jdesc_output(kDummyString);
2931 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002932 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933}
2934
2935TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2936 const bool kUseWildcard = true;
2937 JsepSessionDescription jdesc_output(kDummyString);
2938 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002939 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940}
2941
2942TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2943 JsepSessionDescription jdesc_output(kDummyString);
2944
2945 const char kSdpWithFmtpString[] =
2946 "v=0\r\n"
2947 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2948 "s=-\r\n"
2949 "t=0 0\r\n"
2950 "m=video 3457 RTP/SAVPF 120\r\n"
2951 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002952 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2953
2954 // Deserialize
2955 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002956 EXPECT_TRUE(
2957 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002958
2959 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2960 ASSERT_TRUE(vc != NULL);
2961 const VideoContentDescription* vcd =
2962 static_cast<const VideoContentDescription*>(vc->description);
2963 ASSERT_FALSE(vcd->codecs().empty());
2964 cricket::VideoCodec vp8 = vcd->codecs()[0];
2965 EXPECT_EQ("VP8", vp8.name);
2966 EXPECT_EQ(120, vp8.id);
2967 cricket::CodecParameterMap::iterator found =
2968 vp8.params.find("x-google-min-bitrate");
2969 ASSERT_TRUE(found != vp8.params.end());
2970 EXPECT_EQ(found->second, "10");
2971 found = vp8.params.find("x-google-max-quantization");
2972 ASSERT_TRUE(found != vp8.params.end());
2973 EXPECT_EQ(found->second, "40");
2974}
2975
johan2d8d23e2016-06-03 01:22:42 -07002976TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2977 JsepSessionDescription jdesc_output(kDummyString);
2978
2979 const char kSdpWithFmtpString[] =
2980 "v=0\r\n"
2981 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2982 "s=-\r\n"
2983 "t=0 0\r\n"
2984 "m=video 49170 RTP/AVP 98\r\n"
2985 "a=rtpmap:98 H264/90000\r\n"
2986 "a=fmtp:98 profile-level-id=42A01E; "
2987 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2988
2989 // Deserialize.
2990 SdpParseError error;
2991 EXPECT_TRUE(
2992 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2993
2994 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2995 ASSERT_TRUE(vc != NULL);
2996 const VideoContentDescription* vcd =
2997 static_cast<const VideoContentDescription*>(vc->description);
2998 ASSERT_TRUE(vcd != NULL);
2999 ASSERT_FALSE(vcd->codecs().empty());
3000 cricket::VideoCodec h264 = vcd->codecs()[0];
3001 EXPECT_EQ("H264", h264.name);
3002 EXPECT_EQ(98, h264.id);
3003 cricket::CodecParameterMap::const_iterator found =
3004 h264.params.find("profile-level-id");
3005 ASSERT_TRUE(found != h264.params.end());
3006 EXPECT_EQ(found->second, "42A01E");
3007 found = h264.params.find("sprop-parameter-sets");
3008 ASSERT_TRUE(found != h264.params.end());
3009 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3010}
3011
Donald Curtis0e07f922015-05-15 09:21:23 -07003012TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
3013 JsepSessionDescription jdesc_output(kDummyString);
3014
3015 const char kSdpWithFmtpString[] =
3016 "v=0\r\n"
3017 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3018 "s=-\r\n"
3019 "t=0 0\r\n"
3020 "m=video 3457 RTP/SAVPF 120\r\n"
3021 "a=rtpmap:120 VP8/90000\r\n"
3022 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023
3024 // Deserialize
3025 SdpParseError error;
3026 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3027 &error));
3028
3029 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3030 ASSERT_TRUE(vc != NULL);
3031 const VideoContentDescription* vcd =
3032 static_cast<const VideoContentDescription*>(vc->description);
3033 ASSERT_FALSE(vcd->codecs().empty());
3034 cricket::VideoCodec vp8 = vcd->codecs()[0];
3035 EXPECT_EQ("VP8", vp8.name);
3036 EXPECT_EQ(120, vp8.id);
3037 cricket::CodecParameterMap::iterator found =
3038 vp8.params.find("x-google-min-bitrate");
3039 ASSERT_TRUE(found != vp8.params.end());
3040 EXPECT_EQ(found->second, "10");
3041 found = vp8.params.find("x-google-max-quantization");
3042 ASSERT_TRUE(found != vp8.params.end());
3043 EXPECT_EQ(found->second, "40");
3044}
3045
ossuaa4b0772017-01-30 07:41:18 -08003046TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
3047 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3048 GetFirstAudioContent(&desc_)->description);
3049
3050 cricket::AudioCodecs codecs = acd->codecs();
3051 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3052 acd->set_codecs(codecs);
3053
3054 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3055 jdesc_.session_id(),
3056 jdesc_.session_version()));
3057 std::string message = webrtc::SdpSerialize(jdesc_, false);
3058 std::string sdp_with_fmtp = kSdpFullString;
3059 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3060 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3061 &sdp_with_fmtp);
3062 EXPECT_EQ(sdp_with_fmtp, message);
3063}
3064
3065TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3066 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3067 GetFirstAudioContent(&desc_)->description);
3068
3069 cricket::AudioCodecs codecs = acd->codecs();
3070 codecs[0].params["stereo"] = "1";
3071 acd->set_codecs(codecs);
3072
3073 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3074 jdesc_.session_id(),
3075 jdesc_.session_version()));
3076 std::string message = webrtc::SdpSerialize(jdesc_, false);
3077 std::string sdp_with_fmtp = kSdpFullString;
3078 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3079 "a=fmtp:111 stereo=1\r\n",
3080 &sdp_with_fmtp);
3081 EXPECT_EQ(sdp_with_fmtp, message);
3082}
3083
3084TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3085 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3086 GetFirstAudioContent(&desc_)->description);
3087
3088 cricket::AudioCodecs codecs = acd->codecs();
3089 codecs[0].params["ptime"] = "20";
3090 codecs[0].params["maxptime"] = "120";
3091 acd->set_codecs(codecs);
3092
3093 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3094 jdesc_.session_id(),
3095 jdesc_.session_version()));
3096 std::string message = webrtc::SdpSerialize(jdesc_, false);
3097 std::string sdp_with_fmtp = kSdpFullString;
3098 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3099 "a=maxptime:120\r\n" // No comma here. String merging!
3100 "a=ptime:20\r\n",
3101 &sdp_with_fmtp);
3102 EXPECT_EQ(sdp_with_fmtp, message);
3103}
3104
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3106 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3107 GetFirstVideoContent(&desc_)->description);
3108
3109 cricket::VideoCodecs codecs = vcd->codecs();
3110 codecs[0].params["x-google-min-bitrate"] = "10";
3111 vcd->set_codecs(codecs);
3112
3113 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3114 jdesc_.session_id(),
3115 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003116 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117 std::string sdp_with_fmtp = kSdpFullString;
3118 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3119 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3120 &sdp_with_fmtp);
3121 EXPECT_EQ(sdp_with_fmtp, message);
3122}
3123
3124TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3125 JsepSessionDescription jdesc_with_icelite(kDummyString);
3126 std::string sdp_with_icelite = kSdpFullString;
3127 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3128 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3129 const cricket::TransportInfo* tinfo1 =
3130 desc->GetTransportInfoByName("audio_content_name");
3131 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3132 const cricket::TransportInfo* tinfo2 =
3133 desc->GetTransportInfoByName("video_content_name");
3134 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3135 InjectAfter(kSessionTime,
3136 "a=ice-lite\r\n",
3137 &sdp_with_icelite);
3138 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3139 desc = jdesc_with_icelite.description();
3140 const cricket::TransportInfo* atinfo =
3141 desc->GetTransportInfoByName("audio_content_name");
3142 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3143 const cricket::TransportInfo* vtinfo =
3144 desc->GetTransportInfoByName("video_content_name");
3145 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3146}
3147
3148// Verifies that the candidates in the input SDP are parsed and serialized
3149// correctly in the output SDP.
3150TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3151 std::string sdp_with_data = kSdpString;
3152 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3153 JsepSessionDescription jdesc_output(kDummyString);
3154
3155 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003156 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003158
3159TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3160 AddFingerprint();
3161 TransportInfo audio_transport_info =
3162 *(desc_.GetTransportInfoByName(kAudioContentName));
3163 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3164 audio_transport_info.description.connection_role);
3165 audio_transport_info.description.connection_role =
3166 cricket::CONNECTIONROLE_ACTIVE;
3167
3168 TransportInfo video_transport_info =
3169 *(desc_.GetTransportInfoByName(kVideoContentName));
3170 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3171 video_transport_info.description.connection_role);
3172 video_transport_info.description.connection_role =
3173 cricket::CONNECTIONROLE_ACTIVE;
3174
3175 desc_.RemoveTransportInfoByName(kAudioContentName);
3176 desc_.RemoveTransportInfoByName(kVideoContentName);
3177
3178 desc_.AddTransportInfo(audio_transport_info);
3179 desc_.AddTransportInfo(video_transport_info);
3180
3181 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3182 jdesc_.session_id(),
3183 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003184 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003185 std::string sdp_with_dtlssetup = kSdpFullString;
3186
3187 // Fingerprint attribute is necessary to add DTLS setup attribute.
3188 InjectAfter(kAttributeIcePwdVoice,
3189 kFingerprint, &sdp_with_dtlssetup);
3190 InjectAfter(kAttributeIcePwdVideo,
3191 kFingerprint, &sdp_with_dtlssetup);
3192 // Now adding |setup| attribute.
3193 InjectAfter(kFingerprint,
3194 "a=setup:active\r\n", &sdp_with_dtlssetup);
3195 EXPECT_EQ(sdp_with_dtlssetup, message);
3196}
3197
3198TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3199 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3200 std::string sdp_with_dtlssetup = kSdpFullString;
3201 InjectAfter(kSessionTime,
3202 "a=setup:actpass\r\n",
3203 &sdp_with_dtlssetup);
3204 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3205 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3206 const cricket::TransportInfo* atinfo =
3207 desc->GetTransportInfoByName("audio_content_name");
3208 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3209 atinfo->description.connection_role);
3210 const cricket::TransportInfo* vtinfo =
3211 desc->GetTransportInfoByName("video_content_name");
3212 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3213 vtinfo->description.connection_role);
3214}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003215
3216// Verifies that the order of the serialized m-lines follows the order of the
3217// ContentInfo in SessionDescription, and vise versa for deserialization.
3218TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3219 JsepSessionDescription jdesc(kDummyString);
3220 const std::string media_content_sdps[3] = {
3221 kSdpAudioString,
3222 kSdpVideoString,
3223 kSdpSctpDataChannelString
3224 };
3225 const cricket::MediaType media_types[3] = {
3226 cricket::MEDIA_TYPE_AUDIO,
3227 cricket::MEDIA_TYPE_VIDEO,
3228 cricket::MEDIA_TYPE_DATA
3229 };
3230
3231 // Verifies all 6 permutations.
3232 for (size_t i = 0; i < 6; ++i) {
3233 size_t media_content_in_sdp[3];
3234 // The index of the first media content.
3235 media_content_in_sdp[0] = i / 2;
3236 // The index of the second media content.
3237 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3238 // The index of the third media content.
3239 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3240
3241 std::string sdp_string = kSdpSessionString;
3242 for (size_t i = 0; i < 3; ++i)
3243 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3244
3245 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3246 cricket::SessionDescription* desc = jdesc.description();
3247 EXPECT_EQ(3u, desc->contents().size());
3248
3249 for (size_t i = 0; i < 3; ++i) {
3250 const cricket::MediaContentDescription* mdesc =
3251 static_cast<const cricket::MediaContentDescription*>(
3252 desc->contents()[i].description);
3253 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3254 }
3255
deadbeef9d3584c2016-02-16 17:54:10 -08003256 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003257 EXPECT_EQ(sdp_string, serialized_sdp);
3258 }
3259}
deadbeef9d3584c2016-02-16 17:54:10 -08003260
deadbeef25ed4352016-12-12 18:37:36 -08003261TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3262 MakeBundleOnlyDescription();
3263 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 13:53:47 -08003264 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003265 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3266 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3267}
3268
deadbeef12771a12017-01-03 13:53:47 -08003269// The semantics of "a=bundle-only" are only defined when it's used in
3270// combination with a 0 port on the m= line. We should ignore it if used with a
3271// nonzero port.
3272TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3273 // Make the base bundle-only description but unset the bundle-only flag.
3274 MakeBundleOnlyDescription();
3275 jdesc_.description()->contents()[1].bundle_only = false;
3276
3277 std::string modified_sdp = kBundleOnlySdpFullString;
3278 Replace("m=video 0", "m=video 9", &modified_sdp);
3279 JsepSessionDescription deserialized_description(kDummyString);
3280 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3281 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003282}
3283
3284TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3285 MakeBundleOnlyDescription();
3286 TestSerialize(jdesc_, false);
3287}
3288
deadbeef9d3584c2016-02-16 17:54:10 -08003289TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3290 MakePlanBDescription();
3291
3292 JsepSessionDescription deserialized_description(kDummyString);
3293 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3294
3295 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3296}
3297
3298TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3299 MakePlanBDescription();
3300 TestSerialize(jdesc_, false);
3301}
3302
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003303// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3304// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3305// some extent). If we parse this, the Plan B msid attribute (which is more
3306// specific, since it's at the SSRC level) should take priority.
3307TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3308 MakePlanBDescription();
3309
3310 JsepSessionDescription deserialized_description(kDummyString);
3311 EXPECT_TRUE(
3312 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3313
3314 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3315}
3316
deadbeef9d3584c2016-02-16 17:54:10 -08003317TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3318 MakeUnifiedPlanDescription();
3319
3320 JsepSessionDescription deserialized_description(kDummyString);
3321 EXPECT_TRUE(
3322 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3323
3324 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3325}
3326
3327TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3328 MakeUnifiedPlanDescription();
3329 TestSerialize(jdesc_, true);
3330}
deadbeef7e146cb2016-09-28 10:04:34 -07003331
3332// Regression test for heap overflow bug:
3333// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3334TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003335 // The issue occurs when the sctp-port attribute is found in a video
3336 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003337 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003338 "v=0\r\n"
3339 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3340 "s=-\r\n"
3341 "t=0 0\r\n"
3342 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3343 "a=sctp-port 5000\r\n"
3344 "a=fmtp:108 foo=10\r\n";
3345
3346 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3347 "sctp-port");
3348}
deadbeefb2362572016-12-13 16:37:06 -08003349
3350// Regression test for integer overflow bug:
3351// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3352TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003353 // Bandwidth attribute is the max signed 32-bit int, which will get
3354 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003355 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003356 "v=0\r\n"
3357 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3358 "s=-\r\n"
3359 "t=0 0\r\n"
3360 "m=video 3457 RTP/SAVPF 120\r\n"
3361 "b=AS:2147483647\r\n"
3362 "foo=fail\r\n";
3363
3364 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3365}
deadbeef7bcdb692017-01-20 12:43:58 -08003366
deadbeefbc88c6b2017-08-02 11:26:34 -07003367// Similar to the above, except that negative values are illegal, not just
3368// error-prone as large values are.
3369// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3370TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3371 static const char kSdpWithNegativeBandwidth[] =
3372 "v=0\r\n"
3373 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3374 "s=-\r\n"
3375 "t=0 0\r\n"
3376 "m=video 3457 RTP/SAVPF 120\r\n"
3377 "b=AS:-1000\r\n";
3378
3379 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3380}
3381
deadbeef3e8016e2017-08-03 17:49:30 -07003382// An exception to the above rule: a value of -1 for b=AS should just be
3383// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3384// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3385// limit", but this is now what ommitting the attribute entirely will do, so
3386// ignoring it will have the intended effect.
3387TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3388 static const char kSdpWithBandwidthOfNegativeOne[] =
3389 "v=0\r\n"
3390 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3391 "s=-\r\n"
3392 "t=0 0\r\n"
3393 "m=video 3457 RTP/SAVPF 120\r\n"
3394 "b=AS:-1\r\n";
3395
3396 JsepSessionDescription jdesc_output(kDummyString);
3397 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
3398 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3399 ASSERT_NE(nullptr, vc);
3400 const VideoContentDescription* vcd =
3401 static_cast<const VideoContentDescription*>(vc->description);
3402 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3403}
3404
deadbeef7bcdb692017-01-20 12:43:58 -08003405// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3406// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3407// Regression test for:
3408// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3409TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3410 // Important piece is "ufrag foo pwd bar".
3411 static const char kSdpWithIceCredentialsInCandidateString[] =
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=audio 9 RTP/SAVPF 111\r\n"
3417 "c=IN IP4 0.0.0.0\r\n"
3418 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3419 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3420 "a=rtpmap:111 opus/48000/2\r\n"
3421 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3422 "generation 2 ufrag foo pwd bar\r\n";
3423
3424 JsepSessionDescription jdesc_output(kDummyString);
3425 EXPECT_TRUE(
3426 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3427 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3428 ASSERT_NE(nullptr, candidates);
3429 ASSERT_EQ(1, candidates->count());
3430 cricket::Candidate c = candidates->at(0)->candidate();
3431 EXPECT_EQ("ufrag_voice", c.username());
3432 EXPECT_EQ("pwd_voice", c.password());
3433}
deadbeef90f1e1e2017-02-10 12:35:05 -08003434
3435// Test that SDP with an invalid port number in "a=candidate" lines is
3436// rejected, without crashing.
3437// Regression test for:
3438// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3439TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3440 static const char kSdpWithInvalidCandidatePort[] =
3441 "v=0\r\n"
3442 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3443 "s=-\r\n"
3444 "t=0 0\r\n"
3445 "m=audio 9 RTP/SAVPF 111\r\n"
3446 "c=IN IP4 0.0.0.0\r\n"
3447 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3448 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3449 "a=rtpmap:111 opus/48000/2\r\n"
3450 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3451 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3452
3453 JsepSessionDescription jdesc_output(kDummyString);
3454 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3455}
deadbeefa4549d62017-02-10 17:26:22 -08003456
3457// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3458// Regression test for:
3459// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3460TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3461 static const char kSdpWithMissingTrackId[] =
3462 "v=0\r\n"
3463 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3464 "s=-\r\n"
3465 "t=0 0\r\n"
3466 "m=audio 9 RTP/SAVPF 111\r\n"
3467 "c=IN IP4 0.0.0.0\r\n"
3468 "a=rtpmap:111 opus/48000/2\r\n"
3469 "a=msid:stream_id \r\n";
3470
3471 JsepSessionDescription jdesc_output(kDummyString);
3472 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3473}
3474
3475TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3476 static const char kSdpWithMissingStreamId[] =
3477 "v=0\r\n"
3478 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3479 "s=-\r\n"
3480 "t=0 0\r\n"
3481 "m=audio 9 RTP/SAVPF 111\r\n"
3482 "c=IN IP4 0.0.0.0\r\n"
3483 "a=rtpmap:111 opus/48000/2\r\n"
3484 "a=msid: track_id\r\n";
3485
3486 JsepSessionDescription jdesc_output(kDummyString);
3487 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3488}
zhihuang38989e52017-03-21 11:04:53 -07003489
3490// Tests that if both session-level address and media-level address exist, use
3491// the media-level address.
3492TEST_F(WebRtcSdpTest, ParseConnectionData) {
3493 JsepSessionDescription jsep_desc(kDummyString);
3494
3495 // Sesssion-level address.
3496 std::string sdp = kSdpFullString;
3497 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3498 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3499
3500 const auto& content1 = jsep_desc.description()->contents()[0];
3501 EXPECT_EQ("74.125.127.126:2345",
3502 static_cast<cricket::MediaContentDescription*>(content1.description)
3503 ->connection_address()
3504 .ToString());
3505 const auto& content2 = jsep_desc.description()->contents()[1];
3506 EXPECT_EQ("74.125.224.39:3457",
3507 static_cast<cricket::MediaContentDescription*>(content2.description)
3508 ->connection_address()
3509 .ToString());
3510}
3511
3512// Tests that the session-level connection address will be used if the media
3513// level-addresses are not specified.
3514TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
3515 JsepSessionDescription jsep_desc(kDummyString);
3516
3517 // Sesssion-level address.
3518 std::string sdp = kSdpString;
3519 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3520 // Remove the media level addresses.
3521 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3522 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3523 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3524
3525 const auto& content1 = jsep_desc.description()->contents()[0];
3526 EXPECT_EQ("192.168.0.3:9",
3527 static_cast<cricket::MediaContentDescription*>(content1.description)
3528 ->connection_address()
3529 .ToString());
3530 const auto& content2 = jsep_desc.description()->contents()[1];
3531 EXPECT_EQ("192.168.0.3:9",
3532 static_cast<cricket::MediaContentDescription*>(content2.description)
3533 ->connection_address()
3534 .ToString());
3535}
3536
3537TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
3538 JsepSessionDescription jsep_desc(kDummyString);
3539
3540 std::string sdp = kSdpString;
3541 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3542 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3543 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3544 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3545 &sdp);
3546 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3547 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3548 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3549 &sdp);
3550 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3551 const auto& content1 = jsep_desc.description()->contents()[0];
3552 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
3553 static_cast<cricket::MediaContentDescription*>(content1.description)
3554 ->connection_address()
3555 .ToString());
3556 const auto& content2 = jsep_desc.description()->contents()[1];
3557 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
3558 static_cast<cricket::MediaContentDescription*>(content2.description)
3559 ->connection_address()
3560 .ToString());
3561}
3562
3563// Test that the invalid or unsupprted connection data cannot be parsed.
3564TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
3565 JsepSessionDescription jsep_desc(kDummyString);
3566 std::string sdp = kSdpString;
3567 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3568
3569 // Unsupported multicast IPv4 address.
3570 sdp = kSdpFullString;
3571 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3572 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3573
3574 // Unsupported multicast IPv6 address.
3575 sdp = kSdpFullString;
3576 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3577 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3578
3579 // Mismatched address type.
3580 sdp = kSdpFullString;
3581 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3582 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3583
3584 sdp = kSdpFullString;
3585 Replace("c=IN IP4 74.125.224.39\r\n",
3586 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3587 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3588}
3589
3590TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
3591 JsepSessionDescription expected_jsep(kDummyString);
3592 MakeDescriptionWithoutCandidates(&expected_jsep);
3593 // Serialization.
3594 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3595 // Deserialization.
3596 JsepSessionDescription jdesc(kDummyString);
3597 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3598 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3599 jdesc.description()->GetContentByName(kAudioContentName)->description);
3600 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3601 jdesc.description()->GetContentByName(kVideoContentName)->description);
3602 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3603 audio_desc->connection_address().ToString());
3604 EXPECT_EQ(video_desc_->connection_address().ToString(),
3605 video_desc->connection_address().ToString());
3606}