blob: 3c6643f2aac384dd2ac623b2a3ee7eef61abd9f9 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
17#ifdef WEBRTC_ANDROID
18#include "webrtc/api/test/androidtestinitializer.h"
19#endif
20#include "webrtc/api/webrtcsdp.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000021#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/messagedigest.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000024#include "webrtc/base/sslfingerprint.h"
25#include "webrtc/base/stringencode.h"
26#include "webrtc/base/stringutils.h"
kjellanderf4752772016-03-02 05:42:30 -080027#include "webrtc/media/base/mediaconstants.h"
htaa6b99442016-04-12 10:29:17 -070028#include "webrtc/media/engine/webrtcvideoengine2.h"
29#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
kjellanderf4752772016-03-02 05:42:30 -080030#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010031#include "webrtc/pc/mediasession.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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::SdpParseError;
61using webrtc::SessionDescriptionInterface;
62
63typedef std::vector<AudioCodec> AudioCodecs;
64typedef std::vector<Candidate> Candidates;
65
Peter Boström0c4e06b2015-10-07 12:23:21 +020066static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080069static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080071static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074static const char kCandidateFoundation1[] = "a0+B/1";
75static const char kCandidateFoundation2[] = "a0+B/2";
76static const char kCandidateFoundation3[] = "a0+B/3";
77static const char kCandidateFoundation4[] = "a0+B/4";
78static const char kAttributeCryptoVoice[] =
79 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
80 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
81 "dummy_session_params\r\n";
82static const char kAttributeCryptoVideo[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
84 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
85static const char kFingerprint[] = "a=fingerprint:sha-1 "
86 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
87static const int kExtmapId = 1;
88static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
89static const char kExtmap[] =
90 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
91static const char kExtmapWithDirectionAndAttribute[] =
92 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
93
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint8_t kIdentityDigest[] = {
95 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
96 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097
lally@webrtc.org34807282015-02-24 20:19:39 +000098static const char kDtlsSctp[] = "DTLS/SCTP";
99static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
100static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000101
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102struct CodecParams {
103 int max_ptime;
104 int ptime;
105 int min_ptime;
106 int sprop_stereo;
107 int stereo;
108 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000109 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110};
111
deadbeef9d3584c2016-02-16 17:54:10 -0800112// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
113// instead of "a=crypto", and have an explicit test for adding "a=crypto".
114// Currently it's the other way around.
115
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116// Reference sdp string
117static const char kSdpFullString[] =
118 "v=0\r\n"
119 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
120 "s=-\r\n"
121 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800122 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
124 "c=IN IP4 74.125.127.126\r\n"
125 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
126 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
127 "generation 2\r\n"
128 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
129 "generation 2\r\n"
130 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
135 "raddr 192.168.1.5 rport 2346 "
136 "generation 2\r\n"
137 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
138 "raddr 192.168.1.5 rport 2348 "
139 "generation 2\r\n"
140 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
141 "a=mid:audio_content_name\r\n"
142 "a=sendrecv\r\n"
143 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800144 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
146 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
147 "dummy_session_params\r\n"
148 "a=rtpmap:111 opus/48000/2\r\n"
149 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000150 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 "a=ssrc:1 cname:stream_1_cname\r\n"
152 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
153 "a=ssrc:1 mslabel:local_stream_1\r\n"
154 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "m=video 3457 RTP/SAVPF 120\r\n"
156 "c=IN IP4 74.125.224.39\r\n"
157 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
158 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
167 "generation 2\r\n"
168 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
169 "generation 2\r\n"
170 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
171 "a=mid:video_content_name\r\n"
172 "a=sendrecv\r\n"
173 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
174 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
175 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800176 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 "a=ssrc:2 cname:stream_1_cname\r\n"
178 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
179 "a=ssrc:2 mslabel:local_stream_1\r\n"
180 "a=ssrc:2 label:video_track_id_1\r\n"
181 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800182 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800184 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185
186// SDP reference string without the candidates.
187static const char kSdpString[] =
188 "v=0\r\n"
189 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800192 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000193 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000194 "c=IN IP4 0.0.0.0\r\n"
195 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
197 "a=mid:audio_content_name\r\n"
198 "a=sendrecv\r\n"
199 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800200 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
202 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
203 "dummy_session_params\r\n"
204 "a=rtpmap:111 opus/48000/2\r\n"
205 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000206 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 "a=ssrc:1 cname:stream_1_cname\r\n"
208 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
209 "a=ssrc:1 mslabel:local_stream_1\r\n"
210 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000211 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000212 "c=IN IP4 0.0.0.0\r\n"
213 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
215 "a=mid:video_content_name\r\n"
216 "a=sendrecv\r\n"
217 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
218 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
219 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800220 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 "a=ssrc:2 cname:stream_1_cname\r\n"
222 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
223 "a=ssrc:2 mslabel:local_stream_1\r\n"
224 "a=ssrc:2 label:video_track_id_1\r\n"
225 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800228 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229
230static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000231 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000232 "c=IN IP4 0.0.0.0\r\n"
233 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 "a=ice-ufrag:ufrag_data\r\n"
235 "a=ice-pwd:pwd_data\r\n"
236 "a=mid:data_content_name\r\n"
237 "a=sendrecv\r\n"
238 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
239 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
240 "a=rtpmap:101 google-data/90000\r\n"
241 "a=ssrc:10 cname:data_channel_cname\r\n"
242 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
243 "a=ssrc:10 mslabel:data_channel\r\n"
244 "a=ssrc:10 label:data_channeld0\r\n";
245
246static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000247 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000248 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 "a=ice-ufrag:ufrag_data\r\n"
250 "a=ice-pwd:pwd_data\r\n"
251 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000252 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000254// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000255static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000256 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
257 "a=max-message-size=100000\r\n"
258 "a=sctp-port 5000\r\n"
259 "c=IN IP4 0.0.0.0\r\n"
260 "a=ice-ufrag:ufrag_data\r\n"
261 "a=ice-pwd:pwd_data\r\n"
262 "a=mid:data_content_name\r\n";
263
lally69f57602015-10-08 10:15:04 -0700264static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
265 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
266 "a=max-message-size=100000\r\n"
267 "a=sctp-port:5000\r\n"
268 "c=IN IP4 0.0.0.0\r\n"
269 "a=ice-ufrag:ufrag_data\r\n"
270 "a=ice-pwd:pwd_data\r\n"
271 "a=mid:data_content_name\r\n";
272
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273static const char kSdpSctpDataChannelWithCandidatesString[] =
274 "m=application 2345 DTLS/SCTP 5000\r\n"
275 "c=IN IP4 74.125.127.126\r\n"
276 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
277 "generation 2\r\n"
278 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
279 "generation 2\r\n"
280 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
281 "raddr 192.168.1.5 rport 2346 "
282 "generation 2\r\n"
283 "a=ice-ufrag:ufrag_data\r\n"
284 "a=ice-pwd:pwd_data\r\n"
285 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000286 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000288static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000289 "v=0\r\n"
290 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
291 "s=-\r\n"
292 "t=0 0\r\n"
293 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000294 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000295 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000296 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000297 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000298 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 "a=x-google-flag:conference\r\n";
300
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000301static const char kSdpSessionString[] =
302 "v=0\r\n"
303 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
304 "s=-\r\n"
305 "t=0 0\r\n"
306 "a=msid-semantic: WMS local_stream\r\n";
307
308static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000309 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000310 "c=IN IP4 0.0.0.0\r\n"
311 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000312 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
313 "a=mid:audio_content_name\r\n"
314 "a=sendrecv\r\n"
315 "a=rtpmap:111 opus/48000/2\r\n"
316 "a=ssrc:1 cname:stream_1_cname\r\n"
317 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
318 "a=ssrc:1 mslabel:local_stream\r\n"
319 "a=ssrc:1 label:audio_track_id_1\r\n";
320
321static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000322 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000323 "c=IN IP4 0.0.0.0\r\n"
324 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
326 "a=mid:video_content_name\r\n"
327 "a=sendrecv\r\n"
328 "a=rtpmap:120 VP8/90000\r\n"
329 "a=ssrc:2 cname:stream_1_cname\r\n"
330 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
331 "a=ssrc:2 mslabel:local_stream\r\n"
332 "a=ssrc:2 label:video_track_id_1\r\n";
333
deadbeef9d3584c2016-02-16 17:54:10 -0800334// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
335// tracks.
336static const char kPlanBSdpFullString[] =
337 "v=0\r\n"
338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
339 "s=-\r\n"
340 "t=0 0\r\n"
341 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
342 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
343 "c=IN IP4 74.125.127.126\r\n"
344 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
345 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
346 "generation 2\r\n"
347 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
348 "generation 2\r\n"
349 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
352 "generation 2\r\n"
353 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
354 "raddr 192.168.1.5 rport 2346 "
355 "generation 2\r\n"
356 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
357 "raddr 192.168.1.5 rport 2348 "
358 "generation 2\r\n"
359 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
360 "a=mid:audio_content_name\r\n"
361 "a=sendrecv\r\n"
362 "a=rtcp-mux\r\n"
363 "a=rtcp-rsize\r\n"
364 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
365 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
366 "dummy_session_params\r\n"
367 "a=rtpmap:111 opus/48000/2\r\n"
368 "a=rtpmap:103 ISAC/16000\r\n"
369 "a=rtpmap:104 ISAC/32000\r\n"
370 "a=ssrc:1 cname:stream_1_cname\r\n"
371 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
372 "a=ssrc:1 mslabel:local_stream_1\r\n"
373 "a=ssrc:1 label:audio_track_id_1\r\n"
374 "a=ssrc:4 cname:stream_2_cname\r\n"
375 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
376 "a=ssrc:4 mslabel:local_stream_2\r\n"
377 "a=ssrc:4 label:audio_track_id_2\r\n"
378 "m=video 3457 RTP/SAVPF 120\r\n"
379 "c=IN IP4 74.125.224.39\r\n"
380 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
381 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
388 "generation 2\r\n"
389 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
390 "generation 2\r\n"
391 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
392 "generation 2\r\n"
393 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
394 "a=mid:video_content_name\r\n"
395 "a=sendrecv\r\n"
396 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
397 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
398 "a=rtpmap:120 VP8/90000\r\n"
399 "a=ssrc-group:FEC 2 3\r\n"
400 "a=ssrc:2 cname:stream_1_cname\r\n"
401 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
402 "a=ssrc:2 mslabel:local_stream_1\r\n"
403 "a=ssrc:2 label:video_track_id_1\r\n"
404 "a=ssrc:3 cname:stream_1_cname\r\n"
405 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
406 "a=ssrc:3 mslabel:local_stream_1\r\n"
407 "a=ssrc:3 label:video_track_id_1\r\n"
408 "a=ssrc:5 cname:stream_2_cname\r\n"
409 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
410 "a=ssrc:5 mslabel:local_stream_2\r\n"
411 "a=ssrc:5 label:video_track_id_2\r\n"
412 "a=ssrc:6 cname:stream_2_cname\r\n"
413 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
414 "a=ssrc:6 mslabel:local_stream_2\r\n"
415 "a=ssrc:6 label:video_track_id_3\r\n";
416
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800417// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
418// tracks, but with the unified plan "a=msid" attribute.
419static const char kPlanBSdpFullStringWithMsid[] =
420 "v=0\r\n"
421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
422 "s=-\r\n"
423 "t=0 0\r\n"
424 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
425 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
426 "c=IN IP4 74.125.127.126\r\n"
427 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
428 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
437 "raddr 192.168.1.5 rport 2346 "
438 "generation 2\r\n"
439 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
440 "raddr 192.168.1.5 rport 2348 "
441 "generation 2\r\n"
442 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
443 "a=mid:audio_content_name\r\n"
444 "a=msid:local_stream_1 audio_track_id_1\r\n"
445 "a=sendrecv\r\n"
446 "a=rtcp-mux\r\n"
447 "a=rtcp-rsize\r\n"
448 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
449 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
450 "dummy_session_params\r\n"
451 "a=rtpmap:111 opus/48000/2\r\n"
452 "a=rtpmap:103 ISAC/16000\r\n"
453 "a=rtpmap:104 ISAC/32000\r\n"
454 "a=ssrc:1 cname:stream_1_cname\r\n"
455 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
456 "a=ssrc:1 mslabel:local_stream_1\r\n"
457 "a=ssrc:1 label:audio_track_id_1\r\n"
458 "a=ssrc:4 cname:stream_2_cname\r\n"
459 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
460 "a=ssrc:4 mslabel:local_stream_2\r\n"
461 "a=ssrc:4 label:audio_track_id_2\r\n"
462 "m=video 3457 RTP/SAVPF 120\r\n"
463 "c=IN IP4 74.125.224.39\r\n"
464 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
465 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
466 "generation 2\r\n"
467 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
468 "generation 2\r\n"
469 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
470 "generation 2\r\n"
471 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
472 "generation 2\r\n"
473 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
474 "generation 2\r\n"
475 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
476 "generation 2\r\n"
477 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
478 "a=mid:video_content_name\r\n"
479 "a=msid:local_stream_1 video_track_id_1\r\n"
480 "a=sendrecv\r\n"
481 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
482 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
483 "a=rtpmap:120 VP8/90000\r\n"
484 "a=ssrc-group:FEC 2 3\r\n"
485 "a=ssrc:2 cname:stream_1_cname\r\n"
486 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
487 "a=ssrc:2 mslabel:local_stream_1\r\n"
488 "a=ssrc:2 label:video_track_id_1\r\n"
489 "a=ssrc:3 cname:stream_1_cname\r\n"
490 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
491 "a=ssrc:3 mslabel:local_stream_1\r\n"
492 "a=ssrc:3 label:video_track_id_1\r\n"
493 "a=ssrc:5 cname:stream_2_cname\r\n"
494 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
495 "a=ssrc:5 mslabel:local_stream_2\r\n"
496 "a=ssrc:5 label:video_track_id_2\r\n"
497 "a=ssrc:6 cname:stream_2_cname\r\n"
498 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
499 "a=ssrc:6 mslabel:local_stream_2\r\n"
500 "a=ssrc:6 label:video_track_id_3\r\n";
501
deadbeef9d3584c2016-02-16 17:54:10 -0800502// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
503// tracks.
504static const char kUnifiedPlanSdpFullString[] =
505 "v=0\r\n"
506 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
507 "s=-\r\n"
508 "t=0 0\r\n"
509 "a=msid-semantic: WMS local_stream_1\r\n"
510 // Audio track 1, stream 1 (with candidates).
511 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
512 "c=IN IP4 74.125.127.126\r\n"
513 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
514 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
515 "generation 2\r\n"
516 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
523 "raddr 192.168.1.5 rport 2346 "
524 "generation 2\r\n"
525 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
526 "raddr 192.168.1.5 rport 2348 "
527 "generation 2\r\n"
528 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
529 "a=mid:audio_content_name\r\n"
530 "a=msid:local_stream_1 audio_track_id_1\r\n"
531 "a=sendrecv\r\n"
532 "a=rtcp-mux\r\n"
533 "a=rtcp-rsize\r\n"
534 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
535 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
536 "dummy_session_params\r\n"
537 "a=rtpmap:111 opus/48000/2\r\n"
538 "a=rtpmap:103 ISAC/16000\r\n"
539 "a=rtpmap:104 ISAC/32000\r\n"
540 "a=ssrc:1 cname:stream_1_cname\r\n"
541 // Video track 1, stream 1 (with candidates).
542 "m=video 3457 RTP/SAVPF 120\r\n"
543 "c=IN IP4 74.125.224.39\r\n"
544 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
545 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
546 "generation 2\r\n"
547 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
554 "generation 2\r\n"
555 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
556 "generation 2\r\n"
557 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
558 "a=mid:video_content_name\r\n"
559 "a=msid:local_stream_1 video_track_id_1\r\n"
560 "a=sendrecv\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
562 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
563 "a=rtpmap:120 VP8/90000\r\n"
564 "a=ssrc-group:FEC 2 3\r\n"
565 "a=ssrc:2 cname:stream_1_cname\r\n"
566 "a=ssrc:3 cname:stream_1_cname\r\n"
567 // Audio track 2, stream 2.
568 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
569 "c=IN IP4 0.0.0.0\r\n"
570 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
571 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
572 "a=mid:audio_content_name_2\r\n"
573 "a=msid:local_stream_2 audio_track_id_2\r\n"
574 "a=sendrecv\r\n"
575 "a=rtcp-mux\r\n"
576 "a=rtcp-rsize\r\n"
577 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
578 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
579 "dummy_session_params\r\n"
580 "a=rtpmap:111 opus/48000/2\r\n"
581 "a=rtpmap:103 ISAC/16000\r\n"
582 "a=rtpmap:104 ISAC/32000\r\n"
583 "a=ssrc:4 cname:stream_2_cname\r\n"
584 // Video track 2, stream 2.
585 "m=video 9 RTP/SAVPF 120\r\n"
586 "c=IN IP4 0.0.0.0\r\n"
587 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
588 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
589 "a=mid:video_content_name_2\r\n"
590 "a=msid:local_stream_2 video_track_id_2\r\n"
591 "a=sendrecv\r\n"
592 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
593 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
594 "a=rtpmap:120 VP8/90000\r\n"
595 "a=ssrc:5 cname:stream_2_cname\r\n"
596 // Video track 3, stream 2.
597 "m=video 9 RTP/SAVPF 120\r\n"
598 "c=IN IP4 0.0.0.0\r\n"
599 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
600 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
601 "a=mid:video_content_name_3\r\n"
602 "a=msid:local_stream_2 video_track_id_3\r\n"
603 "a=sendrecv\r\n"
604 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
605 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
606 "a=rtpmap:120 VP8/90000\r\n"
607 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608
609// One candidate reference string as per W3c spec.
610// candidate:<blah> not a=candidate:<blah>CRLF
611static const char kRawCandidate[] =
612 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
613// One candidate reference string.
614static const char kSdpOneCandidate[] =
615 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
616 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000617
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000618static const char kSdpTcpActiveCandidate[] =
619 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
620 "tcptype active generation 2";
621static const char kSdpTcpPassiveCandidate[] =
622 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
623 "tcptype passive generation 2";
624static const char kSdpTcpSOCandidate[] =
625 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
626 "tcptype so generation 2";
627static const char kSdpTcpInvalidCandidate[] =
628 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
629 "tcptype invalid generation 2";
630
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000631// One candidate reference string with IPV6 address.
632static const char kRawIPV6Candidate[] =
633 "candidate:a0+B/1 1 udp 2130706432 "
634 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635
636// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800637static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800639 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640
641// Session id and version
642static const char kSessionId[] = "18446744069414584320";
643static const char kSessionVersion[] = "18446462598732840960";
644
deadbeef9d3584c2016-02-16 17:54:10 -0800645// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646static const char kIceOption1[] = "iceoption1";
647static const char kIceOption2[] = "iceoption2";
648static const char kIceOption3[] = "iceoption3";
649
deadbeef9d3584c2016-02-16 17:54:10 -0800650// ICE ufrags/passwords.
651static const char kUfragVoice[] = "ufrag_voice";
652static const char kPwdVoice[] = "pwd_voice";
653static const char kUfragVideo[] = "ufrag_video";
654static const char kPwdVideo[] = "pwd_video";
655static const char kUfragData[] = "ufrag_data";
656static const char kPwdData[] = "pwd_data";
657
658// Extra ufrags/passwords for extra unified plan m= sections.
659static const char kUfragVoice2[] = "ufrag_voice_2";
660static const char kPwdVoice2[] = "pwd_voice_2";
661static const char kUfragVideo2[] = "ufrag_video_2";
662static const char kPwdVideo2[] = "pwd_video_2";
663static const char kUfragVideo3[] = "ufrag_video_3";
664static const char kPwdVideo3[] = "pwd_video_3";
665
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666// Content name
667static const char kAudioContentName[] = "audio_content_name";
668static const char kVideoContentName[] = "video_content_name";
669static const char kDataContentName[] = "data_content_name";
670
deadbeef9d3584c2016-02-16 17:54:10 -0800671// Extra content names for extra unified plan m= sections.
672static const char kAudioContentName2[] = "audio_content_name_2";
673static const char kVideoContentName2[] = "video_content_name_2";
674static const char kVideoContentName3[] = "video_content_name_3";
675
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676// MediaStream 1
677static const char kStreamLabel1[] = "local_stream_1";
678static const char kStream1Cname[] = "stream_1_cname";
679static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200680static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800682static const uint32_t kVideoTrack1Ssrc1 = 2;
683static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684
685// MediaStream 2
686static const char kStreamLabel2[] = "local_stream_2";
687static const char kStream2Cname[] = "stream_2_cname";
688static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200689static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800690static const char kVideoTrackId2[] = "video_track_id_2";
691static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800693static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694
695// DataChannel
696static const char kDataChannelLabel[] = "data_channel";
697static const char kDataChannelMsid[] = "data_channeld0";
698static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200699static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700
701// Candidate
702static const char kDummyMid[] = "dummy_mid";
703static const int kDummyIndex = 123;
704
705// Misc
706static const char kDummyString[] = "dummy";
707
708// Helper functions
709
710static bool SdpDeserialize(const std::string& message,
711 JsepSessionDescription* jdesc) {
712 return webrtc::SdpDeserialize(message, jdesc, NULL);
713}
714
715static bool SdpDeserializeCandidate(const std::string& message,
716 JsepIceCandidate* candidate) {
717 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
718}
719
720// Add some extra |newlines| to the |message| after |line|.
721static void InjectAfter(const std::string& line,
722 const std::string& newlines,
723 std::string* message) {
724 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000725 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 tmp.c_str(), tmp.length(), message);
727}
728
729static void Replace(const std::string& line,
730 const std::string& newlines,
731 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000732 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 newlines.c_str(), newlines.length(), message);
734}
735
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000736// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
737// message.
738static void ExpectParseFailure(const std::string& bad_sdp,
739 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000742 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000744 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
745}
746
747// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
748static void ExpectParseFailure(const char* good_part, const char* bad_part) {
749 std::string bad_sdp = kSdpFullString;
750 Replace(good_part, bad_part, &bad_sdp);
751 ExpectParseFailure(bad_sdp, bad_part);
752}
753
754// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
755static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
756 const std::string& newlines,
757 const std::string& bad_part) {
758 std::string bad_sdp = kSdpFullString;
759 InjectAfter(injectpoint, newlines, &bad_sdp);
760 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761}
762
763static void ReplaceDirection(cricket::MediaContentDirection direction,
764 std::string* message) {
765 std::string new_direction;
766 switch (direction) {
767 case cricket::MD_INACTIVE:
768 new_direction = "a=inactive";
769 break;
770 case cricket::MD_SENDONLY:
771 new_direction = "a=sendonly";
772 break;
773 case cricket::MD_RECVONLY:
774 new_direction = "a=recvonly";
775 break;
776 case cricket::MD_SENDRECV:
777 default:
778 new_direction = "a=sendrecv";
779 break;
780 }
781 Replace("a=sendrecv", new_direction, message);
782}
783
784static void ReplaceRejected(bool audio_rejected, bool video_rejected,
785 std::string* message) {
786 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800787 Replace("m=audio 9", "m=audio 0", message);
788 Replace(kAttributeIceUfragVoice, "", message);
789 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 }
791 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800792 Replace("m=video 9", "m=video 0", message);
793 Replace(kAttributeIceUfragVideo, "", message);
794 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 }
796}
797
798// WebRtcSdpTest
799
800class WebRtcSdpTest : public testing::Test {
801 public:
802 WebRtcSdpTest()
803 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800804#ifdef WEBRTC_ANDROID
805 webrtc::InitializeAndroidObjects();
806#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 // AudioContentDescription
808 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800809 StreamParams audio_stream;
810 audio_stream.id = kAudioTrackId1;
811 audio_stream.cname = kStream1Cname;
812 audio_stream.sync_label = kStreamLabel1;
813 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
814 audio_desc_->AddStream(audio_stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
816
817 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800818 video_desc_ = CreateVideoContentDescription();
819 StreamParams video_stream;
820 video_stream.id = kVideoTrackId1;
821 video_stream.cname = kStream1Cname;
822 video_stream.sync_label = kStreamLabel1;
823 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
824 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
825 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
826 video_stream.ssrc_groups.push_back(ssrc_group);
827 video_desc_->AddStream(video_stream);
828 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829
830 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800831 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
832 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
833 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
834 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835
836 // v4 host
837 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000838 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000839 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000840 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
841 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000843 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000844 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
845 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000847 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000848 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
849 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000851 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000852 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
853 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854
855 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000856 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000857 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
858 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000859 cricket::LOCAL_PORT_TYPE,
860 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000862 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
863 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000864 cricket::LOCAL_PORT_TYPE,
865 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000867 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
868 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000869 cricket::LOCAL_PORT_TYPE,
870 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000872 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
873 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000874 cricket::LOCAL_PORT_TYPE,
875 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876
877 // stun
878 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000879 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
880 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000881 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
882 address_stun, kCandidatePriority, "", "",
883 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000884 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 candidate9.set_related_address(rel_address_stun);
886
887 address_stun.SetPort(port_stun++);
888 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000889 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
890 address_stun, kCandidatePriority, "", "",
891 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000892 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 candidate10.set_related_address(rel_address_stun);
894
895 // relay
896 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000897 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000898 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
899 address_relay, kCandidatePriority, "", "",
900 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000901 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000903 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
904 address_relay, kCandidatePriority, "", "",
905 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000906 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907
908 // voice
909 candidates_.push_back(candidate1);
910 candidates_.push_back(candidate2);
911 candidates_.push_back(candidate5);
912 candidates_.push_back(candidate6);
913 candidates_.push_back(candidate9);
914 candidates_.push_back(candidate10);
915
916 // video
917 candidates_.push_back(candidate3);
918 candidates_.push_back(candidate4);
919 candidates_.push_back(candidate7);
920 candidates_.push_back(candidate8);
921 candidates_.push_back(candidate11);
922 candidates_.push_back(candidate12);
923
924 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
925 0, candidate1));
926
927 // Set up JsepSessionDescription.
928 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
929 std::string mline_id;
930 int mline_index = 0;
931 for (size_t i = 0; i< candidates_.size(); ++i) {
932 // In this test, the audio m line index will be 0, and the video m line
933 // will be 1.
934 bool is_video = (i > 5);
935 mline_id = is_video ? "video_content_name" : "audio_content_name";
936 mline_index = is_video ? 1 : 0;
937 JsepIceCandidate jice(mline_id,
938 mline_index,
939 candidates_.at(i));
940 jdesc_.AddCandidate(&jice);
941 }
942 }
943
deadbeef9d3584c2016-02-16 17:54:10 -0800944 // Turns the existing reference description into a plan B description,
945 // with 2 audio tracks and 3 video tracks.
946 void MakePlanBDescription() {
947 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
948 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
949
950 StreamParams audio_track_2;
951 audio_track_2.id = kAudioTrackId2;
952 audio_track_2.cname = kStream2Cname;
953 audio_track_2.sync_label = kStreamLabel2;
954 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
955 audio_desc_->AddStream(audio_track_2);
956
957 StreamParams video_track_2;
958 video_track_2.id = kVideoTrackId2;
959 video_track_2.cname = kStream2Cname;
960 video_track_2.sync_label = kStreamLabel2;
961 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
962 video_desc_->AddStream(video_track_2);
963
964 StreamParams video_track_3;
965 video_track_3.id = kVideoTrackId3;
966 video_track_3.cname = kStream2Cname;
967 video_track_3.sync_label = kStreamLabel2;
968 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
969 video_desc_->AddStream(video_track_3);
970
971 desc_.RemoveContentByName(kAudioContentName);
972 desc_.RemoveContentByName(kVideoContentName);
973 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
974 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
975
976 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
977 jdesc_.session_version()));
978 }
979
980 // Turns the existing reference description into a unified plan description,
981 // with 2 audio tracks and 3 video tracks.
982 void MakeUnifiedPlanDescription() {
983 // Audio track 2.
984 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
985 StreamParams audio_track_2;
986 audio_track_2.id = kAudioTrackId2;
987 audio_track_2.cname = kStream2Cname;
988 audio_track_2.sync_label = kStreamLabel2;
989 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
990 audio_desc_2->AddStream(audio_track_2);
991 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
992 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
993 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
994
995 // Video track 2, in stream 2.
996 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
997 StreamParams video_track_2;
998 video_track_2.id = kVideoTrackId2;
999 video_track_2.cname = kStream2Cname;
1000 video_track_2.sync_label = kStreamLabel2;
1001 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1002 video_desc_2->AddStream(video_track_2);
1003 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1004 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1005 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1006
1007 // Video track 3, in stream 2.
1008 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1009 StreamParams video_track_3;
1010 video_track_3.id = kVideoTrackId3;
1011 video_track_3.cname = kStream2Cname;
1012 video_track_3.sync_label = kStreamLabel2;
1013 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1014 video_desc_3->AddStream(video_track_3);
1015 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1016 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1017 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1018
1019 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1020 jdesc_.session_version()));
1021 }
1022
1023 // Creates an audio content description with no streams, and some default
1024 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 AudioContentDescription* CreateAudioContentDescription() {
1026 AudioContentDescription* audio = new AudioContentDescription();
1027 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001028 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1030 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1031 "dummy_session_params"));
1032 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001033 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001034 audio->AddCodec(opus);
deadbeef67cf2c12016-04-13 10:07:16 -07001035 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1));
1036 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 return audio;
1038 }
1039
deadbeef9d3584c2016-02-16 17:54:10 -08001040 // Creates a video content description with no streams, and some default
1041 // configuration.
1042 VideoContentDescription* CreateVideoContentDescription() {
1043 VideoContentDescription* video = new VideoContentDescription();
1044 video->AddCrypto(CryptoParams(
1045 1, "AES_CM_128_HMAC_SHA1_80",
1046 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1047 video->set_protocol(cricket::kMediaProtocolSavpf);
1048 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001049 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001050 return video;
1051 }
1052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 template <class MCD>
1054 void CompareMediaContentDescription(const MCD* cd1,
1055 const MCD* cd2) {
1056 // type
1057 EXPECT_EQ(cd1->type(), cd1->type());
1058
1059 // content direction
1060 EXPECT_EQ(cd1->direction(), cd2->direction());
1061
1062 // rtcp_mux
1063 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1064
deadbeef13871492015-12-09 12:37:51 -08001065 // rtcp_reduced_size
1066 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1067
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // cryptos
1069 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1070 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1071 ADD_FAILURE();
1072 return;
1073 }
1074 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1075 const CryptoParams c1 = cd1->cryptos().at(i);
1076 const CryptoParams c2 = cd2->cryptos().at(i);
1077 EXPECT_TRUE(c1.Matches(c2));
1078 EXPECT_EQ(c1.key_params, c2.key_params);
1079 EXPECT_EQ(c1.session_params, c2.session_params);
1080 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001081
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001083 // Use an equivalence class here, for old and new versions of the
1084 // protocol description.
1085 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001086 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1087 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1088 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001089 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001090 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1091 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1092 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001093 } else {
1094 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1095 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096
1097 // codecs
1098 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1099
1100 // bandwidth
1101 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1102
1103 // streams
1104 EXPECT_EQ(cd1->streams(), cd2->streams());
1105
1106 // extmap
1107 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1108 cd2->rtp_header_extensions().size());
1109 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001110 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1111 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 EXPECT_EQ(ext1.uri, ext2.uri);
1113 EXPECT_EQ(ext1.id, ext2.id);
1114 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 }
1116
1117
1118 void CompareSessionDescription(const SessionDescription& desc1,
1119 const SessionDescription& desc2) {
1120 // Compare content descriptions.
1121 if (desc1.contents().size() != desc2.contents().size()) {
1122 ADD_FAILURE();
1123 return;
1124 }
1125 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1126 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1127 const cricket::ContentInfo& c2 = desc2.contents().at(i);
1128 // content name
1129 EXPECT_EQ(c1.name, c2.name);
1130 // content type
1131 // Note, ASSERT will return from the function, but will not stop the test.
1132 ASSERT_EQ(c1.type, c2.type);
1133
1134 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1135 if (IsAudioContent(&c1)) {
1136 const AudioContentDescription* acd1 =
1137 static_cast<const AudioContentDescription*>(c1.description);
1138 const AudioContentDescription* acd2 =
1139 static_cast<const AudioContentDescription*>(c2.description);
1140 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1141 }
1142
1143 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1144 if (IsVideoContent(&c1)) {
1145 const VideoContentDescription* vcd1 =
1146 static_cast<const VideoContentDescription*>(c1.description);
1147 const VideoContentDescription* vcd2 =
1148 static_cast<const VideoContentDescription*>(c2.description);
1149 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1150 }
1151
1152 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1153 if (IsDataContent(&c1)) {
1154 const DataContentDescription* dcd1 =
1155 static_cast<const DataContentDescription*>(c1.description);
1156 const DataContentDescription* dcd2 =
1157 static_cast<const DataContentDescription*>(c2.description);
1158 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1159 }
1160 }
1161
1162 // group
1163 const cricket::ContentGroups groups1 = desc1.groups();
1164 const cricket::ContentGroups groups2 = desc2.groups();
1165 EXPECT_EQ(groups1.size(), groups1.size());
1166 if (groups1.size() != groups2.size()) {
1167 ADD_FAILURE();
1168 return;
1169 }
1170 for (size_t i = 0; i < groups1.size(); ++i) {
1171 const cricket::ContentGroup group1 = groups1.at(i);
1172 const cricket::ContentGroup group2 = groups2.at(i);
1173 EXPECT_EQ(group1.semantics(), group2.semantics());
1174 const cricket::ContentNames names1 = group1.content_names();
1175 const cricket::ContentNames names2 = group2.content_names();
1176 EXPECT_EQ(names1.size(), names2.size());
1177 if (names1.size() != names2.size()) {
1178 ADD_FAILURE();
1179 return;
1180 }
1181 cricket::ContentNames::const_iterator iter1 = names1.begin();
1182 cricket::ContentNames::const_iterator iter2 = names2.begin();
1183 while (iter1 != names1.end()) {
1184 EXPECT_EQ(*iter1++, *iter2++);
1185 }
1186 }
1187
1188 // transport info
1189 const cricket::TransportInfos transports1 = desc1.transport_infos();
1190 const cricket::TransportInfos transports2 = desc2.transport_infos();
1191 EXPECT_EQ(transports1.size(), transports2.size());
1192 if (transports1.size() != transports2.size()) {
1193 ADD_FAILURE();
1194 return;
1195 }
1196 for (size_t i = 0; i < transports1.size(); ++i) {
1197 const cricket::TransportInfo transport1 = transports1.at(i);
1198 const cricket::TransportInfo transport2 = transports2.at(i);
1199 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 EXPECT_EQ(transport1.description.ice_ufrag,
1201 transport2.description.ice_ufrag);
1202 EXPECT_EQ(transport1.description.ice_pwd,
1203 transport2.description.ice_pwd);
1204 if (transport1.description.identity_fingerprint) {
1205 EXPECT_EQ(*transport1.description.identity_fingerprint,
1206 *transport2.description.identity_fingerprint);
1207 } else {
1208 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1209 transport2.description.identity_fingerprint.get());
1210 }
1211 EXPECT_EQ(transport1.description.transport_options,
1212 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 }
deadbeefc80741f2015-10-22 13:14:45 -07001214
1215 // global attributes
1216 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 }
1218
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 bool CompareSessionDescription(
1220 const JsepSessionDescription& desc1,
1221 const JsepSessionDescription& desc2) {
1222 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1223 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1224 CompareSessionDescription(*desc1.description(), *desc2.description());
1225 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1226 return false;
1227 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1228 const IceCandidateCollection* cc1 = desc1.candidates(i);
1229 const IceCandidateCollection* cc2 = desc2.candidates(i);
1230 if (cc1->count() != cc2->count())
1231 return false;
1232 for (size_t j = 0; j < cc1->count(); ++j) {
1233 const IceCandidateInterface* c1 = cc1->at(j);
1234 const IceCandidateInterface* c2 = cc2->at(j);
1235 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1236 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1237 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1238 }
1239 }
1240 return true;
1241 }
1242
1243 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1244 // them with invalid keywords so that the parser will just ignore them.
1245 bool RemoveCandidateUfragPwd(std::string* sdp) {
1246 const char ice_ufrag[] = "a=ice-ufrag";
1247 const char ice_ufragx[] = "a=xice-ufrag";
1248 const char ice_pwd[] = "a=ice-pwd";
1249 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001250 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 ice_pwdx, strlen(ice_pwdx), sdp);
1254 return true;
1255 }
1256
1257 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1258 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1259 const std::string& ufrag, const std::string& pwd) {
1260 std::string content_name;
1261 if (mline_index == 0) {
1262 content_name = kAudioContentName;
1263 } else if (mline_index == 1) {
1264 content_name = kVideoContentName;
1265 } else {
1266 ASSERT(false);
1267 }
1268 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001269 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 SessionDescription* desc =
1271 const_cast<SessionDescription*>(jdesc->description());
1272 desc->RemoveTransportInfoByName(content_name);
1273 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1274 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1275 const IceCandidateCollection* cc = jdesc_.candidates(i);
1276 for (size_t j = 0; j < cc->count(); ++j) {
1277 if (cc->at(j)->sdp_mline_index() == mline_index) {
1278 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1279 ufrag);
1280 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1281 pwd);
1282 }
1283 }
1284 }
1285 return true;
1286 }
1287
1288 void AddIceOptions(const std::string& content_name,
1289 const std::vector<std::string>& transport_options) {
1290 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1291 cricket::TransportInfo transport_info =
1292 *(desc_.GetTransportInfoByName(content_name));
1293 desc_.RemoveTransportInfoByName(content_name);
1294 transport_info.description.transport_options = transport_options;
1295 desc_.AddTransportInfo(transport_info);
1296 }
1297
deadbeef3f7219b2015-12-28 15:17:14 -08001298 void SetIceUfragPwd(const std::string& content_name,
1299 const std::string& ice_ufrag,
1300 const std::string& ice_pwd) {
1301 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1302 cricket::TransportInfo transport_info =
1303 *(desc_.GetTransportInfoByName(content_name));
1304 desc_.RemoveTransportInfoByName(content_name);
1305 transport_info.description.ice_ufrag = ice_ufrag;
1306 transport_info.description.ice_pwd = ice_pwd;
1307 desc_.AddTransportInfo(transport_info);
1308 }
1309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 void AddFingerprint() {
1311 desc_.RemoveTransportInfoByName(kAudioContentName);
1312 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001313 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 kIdentityDigest,
1315 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001316 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1317 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001318 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1319 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001320 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1321 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1322 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001323 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1324 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001325 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 }
1327
1328 void AddExtmap() {
1329 audio_desc_ = static_cast<AudioContentDescription*>(
1330 audio_desc_->Copy());
1331 video_desc_ = static_cast<VideoContentDescription*>(
1332 video_desc_->Copy());
isheriff6f8d6862016-05-26 11:24:55 -07001333 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
1334 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 desc_.RemoveContentByName(kAudioContentName);
1336 desc_.RemoveContentByName(kVideoContentName);
1337 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1338 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1339 }
1340
1341 void RemoveCryptos() {
1342 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1343 video_desc_->set_cryptos(std::vector<CryptoParams>());
1344 }
1345
1346 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1347 audio_desc_->set_direction(direction);
1348 video_desc_->set_direction(direction);
1349 std::string new_sdp = kSdpFullString;
1350 ReplaceDirection(direction, &new_sdp);
1351
1352 if (!jdesc_.Initialize(desc_.Copy(),
1353 jdesc_.session_id(),
1354 jdesc_.session_version())) {
1355 return false;
1356 }
deadbeef9d3584c2016-02-16 17:54:10 -08001357 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 EXPECT_EQ(new_sdp, message);
1359 return true;
1360 }
1361
1362 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1363 audio_desc_ = static_cast<AudioContentDescription*>(
1364 audio_desc_->Copy());
1365 video_desc_ = static_cast<VideoContentDescription*>(
1366 video_desc_->Copy());
1367 desc_.RemoveContentByName(kAudioContentName);
1368 desc_.RemoveContentByName(kVideoContentName);
1369 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1370 audio_desc_);
1371 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1372 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001373 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1374 audio_rejected ? "" : kPwdVoice);
1375 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1376 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001377
1378 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1380
deadbeef3f7219b2015-12-28 15:17:14 -08001381 JsepSessionDescription jdesc_no_candidates(kDummyString);
1382 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1383 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 return false;
1385 }
deadbeef9d3584c2016-02-16 17:54:10 -08001386 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 EXPECT_EQ(new_sdp, message);
1388 return true;
1389 }
1390
1391 void AddSctpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001392 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 data_desc_ = data.get();
1394 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001395 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001396 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001397 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1398 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001400 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1401 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 }
1403
1404 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001405 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 data_desc_ = data.get();
1407
deadbeef67cf2c12016-04-13 10:07:16 -07001408 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 StreamParams data_stream;
1410 data_stream.id = kDataChannelMsid;
1411 data_stream.cname = kDataChannelCname;
1412 data_stream.sync_label = kDataChannelLabel;
1413 data_stream.ssrcs.push_back(kDataChannelSsrc);
1414 data_desc_->AddStream(data_stream);
1415 data_desc_->AddCrypto(CryptoParams(
1416 1, "AES_CM_128_HMAC_SHA1_80",
1417 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1418 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1419 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001420 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1421 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 }
1423
1424 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1425 std::string new_sdp = kSdpFullString;
1426 ReplaceDirection(direction, &new_sdp);
1427 JsepSessionDescription new_jdesc(kDummyString);
1428
1429 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1430
1431 audio_desc_->set_direction(direction);
1432 video_desc_->set_direction(direction);
1433 if (!jdesc_.Initialize(desc_.Copy(),
1434 jdesc_.session_id(),
1435 jdesc_.session_version())) {
1436 return false;
1437 }
1438 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1439 return true;
1440 }
1441
1442 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001443 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1445 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 audio_desc_ = static_cast<AudioContentDescription*>(
1449 audio_desc_->Copy());
1450 video_desc_ = static_cast<VideoContentDescription*>(
1451 video_desc_->Copy());
1452 desc_.RemoveContentByName(kAudioContentName);
1453 desc_.RemoveContentByName(kVideoContentName);
1454 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1455 audio_desc_);
1456 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1457 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001458 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1459 audio_rejected ? "" : kPwdVoice);
1460 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1461 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001462 JsepSessionDescription jdesc_no_candidates(kDummyString);
1463 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1464 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 return false;
1466 }
deadbeef3f7219b2015-12-28 15:17:14 -08001467 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 return true;
1469 }
1470
1471 void TestDeserializeExtmap(bool session_level, bool media_level) {
1472 AddExtmap();
1473 JsepSessionDescription new_jdesc("dummy");
1474 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1475 jdesc_.session_id(),
1476 jdesc_.session_version()));
1477 JsepSessionDescription jdesc_with_extmap("dummy");
1478 std::string sdp_with_extmap = kSdpString;
1479 if (session_level) {
1480 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1481 &sdp_with_extmap);
1482 }
1483 if (media_level) {
1484 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1485 &sdp_with_extmap);
1486 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1487 &sdp_with_extmap);
1488 }
1489 // The extmap can't be present at the same time in both session level and
1490 // media level.
1491 if (session_level && media_level) {
1492 SdpParseError error;
1493 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1494 &jdesc_with_extmap, &error));
1495 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1496 } else {
1497 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1498 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1499 }
1500 }
1501
1502 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1503 const std::string& name, int expected_value) {
1504 cricket::CodecParameterMap::const_iterator found = params.find(name);
1505 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001506 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 }
1508
1509 void TestDeserializeCodecParams(const CodecParams& params,
1510 JsepSessionDescription* jdesc_output) {
1511 std::string sdp =
1512 "v=0\r\n"
1513 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1514 "s=-\r\n"
1515 "t=0 0\r\n"
1516 // Include semantics for WebRTC Media Streams since it is supported by
1517 // this parser, and will be added to the SDP when serializing a session
1518 // description.
1519 "a=msid-semantic: WMS\r\n"
1520 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001521 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 // Pltype 111 listed before 103 and 104 in the map.
1523 "a=rtpmap:111 opus/48000/2\r\n"
1524 // Pltype 103 listed before 104.
1525 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001526 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001527 "a=fmtp:111 0-15,66,70\r\n"
1528 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001530 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001531 << "; sprop-stereo=" << params.sprop_stereo
1532 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001533 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 << "a=ptime:" << params.ptime << "\r\n"
1535 << "a=maxptime:" << params.max_ptime << "\r\n";
1536 sdp += os.str();
1537
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001538 os.clear();
1539 os.str("");
1540 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001541 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001542 << "a=rtpmap:99 VP8/90000\r\n"
1543 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001544 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001545 sdp += os.str();
1546
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 // Deserialize
1548 SdpParseError error;
1549 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1550
1551 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1552 ASSERT_TRUE(ac != NULL);
1553 const AudioContentDescription* acd =
1554 static_cast<const AudioContentDescription*>(ac->description);
1555 ASSERT_FALSE(acd->codecs().empty());
1556 cricket::AudioCodec opus = acd->codecs()[0];
1557 EXPECT_EQ("opus", opus.name);
1558 EXPECT_EQ(111, opus.id);
1559 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1560 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1561 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1562 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001563 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1564 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1566 cricket::AudioCodec codec = acd->codecs()[i];
1567 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1568 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1569 if (codec.name == "ISAC") {
1570 if (codec.clockrate == 16000) {
1571 EXPECT_EQ(32000, codec.bitrate);
1572 } else {
1573 EXPECT_EQ(56000, codec.bitrate);
1574 }
1575 }
1576 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001577
1578 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1579 ASSERT_TRUE(vc != NULL);
1580 const VideoContentDescription* vcd =
1581 static_cast<const VideoContentDescription*>(vc->description);
1582 ASSERT_FALSE(vcd->codecs().empty());
1583 cricket::VideoCodec vp8 = vcd->codecs()[0];
1584 EXPECT_EQ("VP8", vp8.name);
1585 EXPECT_EQ(99, vp8.id);
1586 cricket::VideoCodec rtx = vcd->codecs()[1];
1587 EXPECT_EQ("RTX", rtx.name);
1588 EXPECT_EQ(95, rtx.id);
1589 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 }
1591
1592 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1593 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001594 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 "v=0\r\n"
1596 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1597 "s=-\r\n"
1598 "t=0 0\r\n"
1599 // Include semantics for WebRTC Media Streams since it is supported by
1600 // this parser, and will be added to the SDP when serializing a session
1601 // description.
1602 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001603 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001604 "a=rtpmap:111 opus/48000/2\r\n";
1605 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 "m=video 3457 RTP/SAVPF 101\r\n"
1607 "a=rtpmap:101 VP8/90000\r\n"
1608 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001609 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001610 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001612 os << sdp_session_and_audio;
1613 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1614 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001616 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 // Deserialize
1618 SdpParseError error;
1619 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1620 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1621 ASSERT_TRUE(ac != NULL);
1622 const AudioContentDescription* acd =
1623 static_cast<const AudioContentDescription*>(ac->description);
1624 ASSERT_FALSE(acd->codecs().empty());
1625 cricket::AudioCodec opus = acd->codecs()[0];
1626 EXPECT_EQ(111, opus.id);
1627 EXPECT_TRUE(opus.HasFeedbackParam(
1628 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1629 cricket::kParamValueEmpty)));
1630
1631 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1632 ASSERT_TRUE(vc != NULL);
1633 const VideoContentDescription* vcd =
1634 static_cast<const VideoContentDescription*>(vc->description);
1635 ASSERT_FALSE(vcd->codecs().empty());
1636 cricket::VideoCodec vp8 = vcd->codecs()[0];
1637 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1638 vp8.name.c_str());
1639 EXPECT_EQ(101, vp8.id);
1640 EXPECT_TRUE(vp8.HasFeedbackParam(
1641 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1642 cricket::kParamValueEmpty)));
1643 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001644 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1645 cricket::kRtcpFbNackParamPli)));
1646 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1648 cricket::kParamValueEmpty)));
1649 EXPECT_TRUE(vp8.HasFeedbackParam(
1650 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1651 cricket::kRtcpFbCcmParamFir)));
1652 }
1653
1654 // Two SDP messages can mean the same thing but be different strings, e.g.
1655 // some of the lines can be serialized in different order.
1656 // However, a deserialized description can be compared field by field and has
1657 // no order. If deserializer has already been tested, serializing then
1658 // deserializing and comparing JsepSessionDescription will test
1659 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001660 void TestSerialize(const JsepSessionDescription& jdesc,
1661 bool unified_plan_sdp) {
1662 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 JsepSessionDescription jdesc_output_des(kDummyString);
1664 SdpParseError error;
1665 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1666 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1667 }
1668
1669 protected:
1670 SessionDescription desc_;
1671 AudioContentDescription* audio_desc_;
1672 VideoContentDescription* video_desc_;
1673 DataContentDescription* data_desc_;
1674 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001675 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 JsepSessionDescription jdesc_;
1677};
1678
1679void TestMismatch(const std::string& string1, const std::string& string2) {
1680 int position = 0;
1681 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1682 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001683 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 break;
1685 }
1686 }
1687 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1688 << " character\n"
1689 << " 1: " << string1.substr(position, 20) << "\n"
1690 << " 2: " << string2.substr(position, 20) << "\n";
1691}
1692
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1694 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001695 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 TestMismatch(std::string(kSdpFullString), message);
1697}
1698
1699TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1700 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001701 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702}
1703
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001704// This tests serialization of SDP with only IPv6 candidates and verifies that
1705// IPv6 is used as default address in c line according to preference.
1706TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1707 // Only test 1 m line.
1708 desc_.RemoveContentByName("video_content_name");
1709 // Stun has a high preference than local host.
1710 cricket::Candidate candidate1(
1711 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1712 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1713 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1714 cricket::Candidate candidate2(
1715 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1716 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1717 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1718 JsepSessionDescription jdesc(kDummyString);
1719 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1720
1721 // Only add the candidates to audio m line.
1722 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1723 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1724 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1725 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001726 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001727
1728 // Audio line should have a c line like this one.
1729 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1730 // Shouldn't have a IP4 c line.
1731 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1732}
1733
1734// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1735// verifies that IPv4 is used as default address in c line even if the
1736// preference of IPv4 is lower.
1737TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1738 // Only test 1 m line.
1739 desc_.RemoveContentByName("video_content_name");
1740 cricket::Candidate candidate_v4(
1741 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1742 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1743 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1744 cricket::Candidate candidate_v6(
1745 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1746 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1747 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1748 JsepSessionDescription jdesc(kDummyString);
1749 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1750
1751 // Only add the candidates to audio m line.
1752 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1753 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1754 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1755 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
deadbeef9d3584c2016-02-16 17:54:10 -08001756 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001757
1758 // Audio line should have a c line like this one.
1759 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1760 // Shouldn't have a IP6 c line.
1761 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1762}
1763
1764// This tests serialization of SDP with both UDP and TCP candidates and
1765// verifies that UDP is used as default address in c line even if the
1766// preference of UDP is lower.
1767TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1768 // Only test 1 m line.
1769 desc_.RemoveContentByName("video_content_name");
1770 // Stun has a high preference than local host.
1771 cricket::Candidate candidate1(
1772 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1773 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1774 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1775 cricket::Candidate candidate2(
1776 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1777 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1778 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1779 kCandidateFoundation1);
1780 JsepSessionDescription jdesc(kDummyString);
1781 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1782
1783 // Only add the candidates to audio m line.
1784 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1785 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1786 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1787 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001788 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001789
1790 // Audio line should have a c line like this one.
1791 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1792 std::string::npos);
1793 // Shouldn't have a IP4 c line.
1794 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1795}
1796
1797// This tests serialization of SDP with only TCP candidates and verifies that
1798// null IPv4 is used as default address in c line.
1799TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1800 // Only test 1 m line.
1801 desc_.RemoveContentByName("video_content_name");
1802 // Stun has a high preference than local host.
1803 cricket::Candidate candidate1(
1804 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1805 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1806 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1807 cricket::Candidate candidate2(
1808 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1809 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1810 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1811 JsepSessionDescription jdesc(kDummyString);
1812 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1813
1814 // Only add the candidates to audio m line.
1815 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1816 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1817 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1818 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001819 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001820
1821 // Audio line should have a c line like this one when no any default exists.
1822 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1823}
1824
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1826// the case in a DTLS offer.
1827TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1828 AddFingerprint();
1829 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1830 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1831 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001832 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833
1834 std::string sdp_with_fingerprint = kSdpString;
1835 InjectAfter(kAttributeIcePwdVoice,
1836 kFingerprint, &sdp_with_fingerprint);
1837 InjectAfter(kAttributeIcePwdVideo,
1838 kFingerprint, &sdp_with_fingerprint);
1839
1840 EXPECT_EQ(sdp_with_fingerprint, message);
1841}
1842
1843// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1844// be the case in a DTLS answer.
1845TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1846 AddFingerprint();
1847 RemoveCryptos();
1848 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1849 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1850 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001851 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852
1853 std::string sdp_with_fingerprint = kSdpString;
1854 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1855 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1856 InjectAfter(kAttributeIcePwdVoice,
1857 kFingerprint, &sdp_with_fingerprint);
1858 InjectAfter(kAttributeIcePwdVideo,
1859 kFingerprint, &sdp_with_fingerprint);
1860
1861 EXPECT_EQ(sdp_with_fingerprint, message);
1862}
1863
1864TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1865 // JsepSessionDescription with desc but without candidates.
1866 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001867 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1868 kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001869 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 EXPECT_EQ(std::string(kSdpString), message);
1871}
1872
1873TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1874 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1875 group.AddContentName(kAudioContentName);
1876 group.AddContentName(kVideoContentName);
1877 desc_.AddGroup(group);
1878 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1879 jdesc_.session_id(),
1880 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001881 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 std::string sdp_with_bundle = kSdpFullString;
1883 InjectAfter(kSessionTime,
1884 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1885 &sdp_with_bundle);
1886 EXPECT_EQ(sdp_with_bundle, message);
1887}
1888
1889TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1890 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1891 GetFirstVideoContent(&desc_)->description);
1892 vcd->set_bandwidth(100 * 1000);
1893 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1894 GetFirstAudioContent(&desc_)->description);
1895 acd->set_bandwidth(50 * 1000);
1896 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1897 jdesc_.session_id(),
1898 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001899 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001901 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 "b=AS:100\r\n",
1903 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001904 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 "b=AS:50\r\n",
1906 &sdp_with_bandwidth);
1907 EXPECT_EQ(sdp_with_bandwidth, message);
1908}
1909
1910TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1911 std::vector<std::string> transport_options;
1912 transport_options.push_back(kIceOption1);
1913 transport_options.push_back(kIceOption3);
1914 AddIceOptions(kAudioContentName, transport_options);
1915 transport_options.clear();
1916 transport_options.push_back(kIceOption2);
1917 transport_options.push_back(kIceOption3);
1918 AddIceOptions(kVideoContentName, transport_options);
1919 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1920 jdesc_.session_id(),
1921 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001922 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 std::string sdp_with_ice_options = kSdpFullString;
1924 InjectAfter(kAttributeIcePwdVoice,
1925 "a=ice-options:iceoption1 iceoption3\r\n",
1926 &sdp_with_ice_options);
1927 InjectAfter(kAttributeIcePwdVideo,
1928 "a=ice-options:iceoption2 iceoption3\r\n",
1929 &sdp_with_ice_options);
1930 EXPECT_EQ(sdp_with_ice_options, message);
1931}
1932
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1934 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1935}
1936
1937TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1938 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1939}
1940
1941TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1942 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1943}
1944
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1946 EXPECT_TRUE(TestSerializeRejected(true, false));
1947}
1948
1949TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1950 EXPECT_TRUE(TestSerializeRejected(false, true));
1951}
1952
1953TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1954 EXPECT_TRUE(TestSerializeRejected(true, true));
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1958 AddRtpDataChannel();
1959 JsepSessionDescription jsep_desc(kDummyString);
1960
1961 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001962 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963
1964 std::string expected_sdp = kSdpString;
1965 expected_sdp.append(kSdpRtpDataChannelString);
1966 EXPECT_EQ(expected_sdp, message);
1967}
1968
1969TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1970 AddSctpDataChannel();
1971 JsepSessionDescription jsep_desc(kDummyString);
1972
1973 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001974 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975
1976 std::string expected_sdp = kSdpString;
1977 expected_sdp.append(kSdpSctpDataChannelString);
1978 EXPECT_EQ(message, expected_sdp);
1979}
1980
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001981TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1982 AddSctpDataChannel();
1983 JsepSessionDescription jsep_desc(kDummyString);
1984
1985 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1986 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1987 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1988
1989 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001990 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001991 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001992 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1993 dcdesc->AddOrReplaceCodec(codec);
1994
deadbeef9d3584c2016-02-16 17:54:10 -08001995 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001996
1997 std::string expected_sdp = kSdpString;
1998 expected_sdp.append(kSdpSctpDataChannelString);
1999
2000 char default_portstr[16];
2001 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002002 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002003 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002004 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2005 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002006 new_portstr, strlen(new_portstr),
2007 &expected_sdp);
2008
2009 EXPECT_EQ(expected_sdp, message);
2010}
2011
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002012TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
2013 AddRtpDataChannel();
2014 data_desc_->set_bandwidth(100*1000);
2015 JsepSessionDescription jsep_desc(kDummyString);
2016
2017 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002018 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002019
2020 std::string expected_sdp = kSdpString;
2021 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002022 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002023 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 +00002024 "b=AS:100\r\n",
2025 &expected_sdp);
2026 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002027}
2028
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2030 AddExtmap();
2031 JsepSessionDescription desc_with_extmap("dummy");
2032 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2033 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002034 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
2036 std::string sdp_with_extmap = kSdpString;
2037 InjectAfter("a=mid:audio_content_name\r\n",
2038 kExtmap, &sdp_with_extmap);
2039 InjectAfter("a=mid:video_content_name\r\n",
2040 kExtmap, &sdp_with_extmap);
2041
2042 EXPECT_EQ(sdp_with_extmap, message);
2043}
2044
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045TEST_F(WebRtcSdpTest, SerializeCandidates) {
2046 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002047 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002048
2049 Candidate candidate_with_ufrag(candidates_.front());
2050 candidate_with_ufrag.set_username("ABC");
2051 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2052 candidate_with_ufrag));
2053 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2054 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002055
2056 Candidate candidate_with_network_info(candidates_.front());
2057 candidate_with_network_info.set_network_id(1);
2058 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2059 candidate_with_network_info));
2060 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2061 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2062 candidate_with_network_info.set_network_cost(999);
2063 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2064 candidate_with_network_info));
2065 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2066 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2067 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002070// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2071// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002072TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002073 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002074 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2075 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2076 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002077 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002078 std::unique_ptr<IceCandidateInterface> jcandidate(
2079 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002080
2081 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2082 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2083}
2084
htaa6b99442016-04-12 10:29:17 -07002085TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjedeacbaea2016-11-17 08:51:59 -08002086 if (!webrtc::H264Encoder::IsSupported())
2087 return;
2088 for (const auto& codec : cricket::DefaultVideoCodecList()) {
2089 video_desc_->AddCodec(codec);
2090 }
htaa6b99442016-04-12 10:29:17 -07002091 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2092
2093 std::string message = webrtc::SdpSerialize(jdesc_, false);
2094 size_t after_pt = message.find(" H264/90000");
2095 ASSERT_NE(after_pt, std::string::npos);
2096 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2097 ASSERT_NE(before_pt, std::string::npos);
2098 before_pt += strlen("a=rtpmap:");
2099 std::string pt = message.substr(before_pt, after_pt - before_pt);
2100 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2101 std::string to_find = "a=fmtp:" + pt + " ";
2102 size_t fmtp_pos = message.find(to_find);
2103 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2104 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2105 ASSERT_NE(std::string::npos, fmtp_endpos);
2106 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2107 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2108 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2109 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002110 // Check that there are no spaces after semicolons.
2111 // https://bugs.webrtc.org/5793
2112 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2116 JsepSessionDescription jdesc(kDummyString);
2117 // Deserialize
2118 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2119 // Verify
2120 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2121}
2122
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002123TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2124 JsepSessionDescription jdesc(kDummyString);
2125 const char kSdpWithoutMline[] =
2126 "v=0\r\n"
2127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2128 "s=-\r\n"
2129 "t=0 0\r\n"
2130 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2131 // Deserialize
2132 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2133 EXPECT_EQ(0u, jdesc.description()->contents().size());
2134}
2135
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2137 JsepSessionDescription jdesc(kDummyString);
2138 std::string sdp_without_carriage_return = kSdpFullString;
2139 Replace("\r\n", "\n", &sdp_without_carriage_return);
2140 // Deserialize
2141 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2142 // Verify
2143 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2144}
2145
2146TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2147 // SessionDescription with desc but without candidates.
2148 JsepSessionDescription jdesc_no_candidates(kDummyString);
2149 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2150 kSessionId, kSessionVersion));
2151 JsepSessionDescription new_jdesc(kDummyString);
2152 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2153 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2154}
2155
2156TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2157 static const char kSdpNoRtpmapString[] =
2158 "v=0\r\n"
2159 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2160 "s=-\r\n"
2161 "t=0 0\r\n"
2162 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2163 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002164 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 // The rtpmap line for static payload codec is optional.
2166 "a=rtpmap:18 G729/16000\r\n"
2167 "a=rtpmap:103 ISAC/16000\r\n";
2168
2169 JsepSessionDescription jdesc(kDummyString);
2170 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2171 cricket::AudioContentDescription* audio =
2172 static_cast<AudioContentDescription*>(
2173 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2174 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002175 // The codecs in the AudioContentDescription should be in the same order as
2176 // the payload types (<fmt>s) on the m= line.
2177 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2178 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
2179 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 EXPECT_EQ(ref_codecs, audio->codecs());
2181}
2182
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002183TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2184 static const char kSdpNoRtpmapString[] =
2185 "v=0\r\n"
2186 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2187 "s=-\r\n"
2188 "t=0 0\r\n"
2189 "m=audio 49232 RTP/AVP 18 103\r\n"
2190 "a=fmtp:18 annexb=yes\r\n"
2191 "a=rtpmap:103 ISAC/16000\r\n";
2192
2193 JsepSessionDescription jdesc(kDummyString);
2194 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2195 cricket::AudioContentDescription* audio =
2196 static_cast<AudioContentDescription*>(
2197 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2198
2199 cricket::AudioCodec g729 = audio->codecs()[0];
2200 EXPECT_EQ("G729", g729.name);
2201 EXPECT_EQ(8000, g729.clockrate);
2202 EXPECT_EQ(18, g729.id);
2203 cricket::CodecParameterMap::iterator found =
2204 g729.params.find("annexb");
2205 ASSERT_TRUE(found != g729.params.end());
2206 EXPECT_EQ(found->second, "yes");
2207
2208 cricket::AudioCodec isac = audio->codecs()[1];
2209 EXPECT_EQ("ISAC", isac.name);
2210 EXPECT_EQ(103, isac.id);
2211 EXPECT_EQ(16000, isac.clockrate);
2212}
2213
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214// Ensure that we can deserialize SDP with a=fingerprint properly.
2215TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2216 // Add a DTLS a=fingerprint attribute to our session description.
2217 AddFingerprint();
2218 JsepSessionDescription new_jdesc(kDummyString);
2219 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2220 jdesc_.session_id(),
2221 jdesc_.session_version()));
2222
2223 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2224 std::string sdp_with_fingerprint = kSdpString;
2225 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2226 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2227 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2228 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2229}
2230
2231TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2232 JsepSessionDescription jdesc_with_bundle(kDummyString);
2233 std::string sdp_with_bundle = kSdpFullString;
2234 InjectAfter(kSessionTime,
2235 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2236 &sdp_with_bundle);
2237 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2238 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2239 group.AddContentName(kAudioContentName);
2240 group.AddContentName(kVideoContentName);
2241 desc_.AddGroup(group);
2242 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2243 jdesc_.session_id(),
2244 jdesc_.session_version()));
2245 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2246}
2247
2248TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2249 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2250 std::string sdp_with_bandwidth = kSdpFullString;
2251 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2252 "b=AS:100\r\n",
2253 &sdp_with_bandwidth);
2254 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2255 "b=AS:50\r\n",
2256 &sdp_with_bandwidth);
2257 EXPECT_TRUE(
2258 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2259 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2260 GetFirstVideoContent(&desc_)->description);
2261 vcd->set_bandwidth(100 * 1000);
2262 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2263 GetFirstAudioContent(&desc_)->description);
2264 acd->set_bandwidth(50 * 1000);
2265 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2266 jdesc_.session_id(),
2267 jdesc_.session_version()));
2268 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2269}
2270
2271TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2272 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2273 std::string sdp_with_ice_options = kSdpFullString;
2274 InjectAfter(kSessionTime,
2275 "a=ice-options:iceoption3\r\n",
2276 &sdp_with_ice_options);
2277 InjectAfter(kAttributeIcePwdVoice,
2278 "a=ice-options:iceoption1\r\n",
2279 &sdp_with_ice_options);
2280 InjectAfter(kAttributeIcePwdVideo,
2281 "a=ice-options:iceoption2\r\n",
2282 &sdp_with_ice_options);
2283 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2284 std::vector<std::string> transport_options;
2285 transport_options.push_back(kIceOption3);
2286 transport_options.push_back(kIceOption1);
2287 AddIceOptions(kAudioContentName, transport_options);
2288 transport_options.clear();
2289 transport_options.push_back(kIceOption3);
2290 transport_options.push_back(kIceOption2);
2291 AddIceOptions(kVideoContentName, transport_options);
2292 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2293 jdesc_.session_id(),
2294 jdesc_.session_version()));
2295 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2296}
2297
2298TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2299 // Remove the original ice-ufrag and ice-pwd
2300 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2301 std::string sdp_with_ufrag_pwd = kSdpFullString;
2302 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2303 // Add session level ufrag and pwd
2304 InjectAfter(kSessionTime,
2305 "a=ice-pwd:session+level+icepwd\r\n"
2306 "a=ice-ufrag:session+level+iceufrag\r\n",
2307 &sdp_with_ufrag_pwd);
2308 // Add media level ufrag and pwd for audio
2309 InjectAfter("a=mid:audio_content_name\r\n",
2310 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2311 &sdp_with_ufrag_pwd);
2312 // Update the candidate ufrag and pwd to the expected ones.
2313 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2314 "media+level+iceufrag", "media+level+icepwd"));
2315 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2316 "session+level+iceufrag", "session+level+icepwd"));
2317 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2318 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2319}
2320
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2322 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2323}
2324
2325TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2326 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2327}
2328
2329TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2330 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2331}
2332
2333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2334 EXPECT_TRUE(TestDeserializeRejected(true, false));
2335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2338 EXPECT_TRUE(TestDeserializeRejected(false, true));
2339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2342 EXPECT_TRUE(TestDeserializeRejected(true, true));
2343}
2344
2345// Tests that we can still handle the sdp uses mslabel and label instead of
2346// msid for backward compatibility.
2347TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002348 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 JsepSessionDescription jdesc(kDummyString);
2350 std::string sdp_without_msid = kSdpFullString;
2351 Replace("msid", "xmsid", &sdp_without_msid);
2352 // Deserialize
2353 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2354 // Verify
2355 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2356}
2357
2358TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2359 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2360
2361 std::string sdp = kSdpOneCandidate;
2362 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2363 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2364 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2365 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002366 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
2368 // Candidate line without generation extension.
2369 sdp = kSdpOneCandidate;
2370 Replace(" generation 2", "", &sdp);
2371 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2372 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2373 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2374 Candidate expected = jcandidate_->candidate();
2375 expected.set_generation(0);
2376 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2377
honghaiza0c44ea2016-03-23 16:07:48 -07002378 // Candidate with network id and/or cost.
2379 sdp = kSdpOneCandidate;
2380 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2381 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2382 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2383 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2384 expected = jcandidate_->candidate();
2385 expected.set_network_id(2);
2386 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2387 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2388 // Add network cost
2389 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2390 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2391 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2392 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2393
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002394 sdp = kSdpTcpActiveCandidate;
2395 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2396 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002397 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002398 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2399 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2400 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002401 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2402 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002403 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2404 jcandidate_template->candidate()));
2405 sdp = kSdpTcpPassiveCandidate;
2406 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2407 sdp = kSdpTcpSOCandidate;
2408 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409}
2410
2411// This test verifies the deserialization of candidate-attribute
2412// as per RFC 5245. Candiate-attribute will be of the format
2413// candidate:<blah>. This format will be used when candidates
2414// are trickled.
2415TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2416 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2417
2418 std::string candidate_attribute = kRawCandidate;
2419 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2420 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2421 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2422 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2423 EXPECT_EQ(2u, jcandidate.candidate().generation());
2424
2425 // Candidate line without generation extension.
2426 candidate_attribute = kRawCandidate;
2427 Replace(" generation 2", "", &candidate_attribute);
2428 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2429 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2430 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2431 Candidate expected = jcandidate_->candidate();
2432 expected.set_generation(0);
2433 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2434
2435 // Candidate line without candidate:
2436 candidate_attribute = kRawCandidate;
2437 Replace("candidate:", "", &candidate_attribute);
2438 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2439
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002440 // Candidate line with IPV6 address.
2441 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2442}
2443
2444// This test verifies that the deserialization of an invalid candidate string
2445// fails.
2446TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2447 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2448
2449 std::string candidate_attribute = kRawCandidate;
2450 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002452
2453 candidate_attribute = kSdpOneCandidate;
2454 candidate_attribute.replace(0, 1, "x");
2455 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2456
2457 candidate_attribute = kRawCandidate;
2458 candidate_attribute.append("\r\n");
2459 candidate_attribute.append(kRawCandidate);
2460 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2461
2462 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463}
2464
2465TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2466 AddRtpDataChannel();
2467 JsepSessionDescription jdesc(kDummyString);
2468 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2469
2470 std::string sdp_with_data = kSdpString;
2471 sdp_with_data.append(kSdpRtpDataChannelString);
2472 JsepSessionDescription jdesc_output(kDummyString);
2473
2474 // Deserialize
2475 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2476 // Verify
2477 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2478}
2479
2480TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2481 AddSctpDataChannel();
2482 JsepSessionDescription jdesc(kDummyString);
2483 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2484
2485 std::string sdp_with_data = kSdpString;
2486 sdp_with_data.append(kSdpSctpDataChannelString);
2487 JsepSessionDescription jdesc_output(kDummyString);
2488
lally@webrtc.org36300852015-02-24 20:19:35 +00002489 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2490 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2491 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2492
2493 // Verify with UDP/DTLS/SCTP.
2494 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2495 strlen(kDtlsSctp), kUdpDtlsSctp);
2496 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2497 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2498
2499 // Verify with TCP/DTLS/SCTP.
2500 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2501 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2503 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2504}
2505
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002506TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2507 AddSctpDataChannel();
2508 JsepSessionDescription jdesc(kDummyString);
2509 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2510
2511 std::string sdp_with_data = kSdpString;
2512 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2513 JsepSessionDescription jdesc_output(kDummyString);
2514
lally@webrtc.org36300852015-02-24 20:19:35 +00002515 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002516 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2517 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002518
lally@webrtc.org36300852015-02-24 20:19:35 +00002519 // Verify with UDP/DTLS/SCTP.
2520 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2521 strlen(kDtlsSctp), kUdpDtlsSctp);
2522 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2523 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002524
lally@webrtc.org36300852015-02-24 20:19:35 +00002525 // Verify with TCP/DTLS/SCTP.
2526 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2527 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002528 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2529 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2530}
2531
lally69f57602015-10-08 10:15:04 -07002532TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2533 AddSctpDataChannel();
2534 JsepSessionDescription jdesc(kDummyString);
2535 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2536
2537 std::string sdp_with_data = kSdpString;
2538 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2539 JsepSessionDescription jdesc_output(kDummyString);
2540
2541 // Verify with DTLS/SCTP.
2542 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2543 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2544
2545 // Verify with UDP/DTLS/SCTP.
2546 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2547 strlen(kDtlsSctp), kUdpDtlsSctp);
2548 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2549 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2550
2551 // Verify with TCP/DTLS/SCTP.
2552 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2553 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2554 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2555 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2556}
2557
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002558// Test to check the behaviour if sctp-port is specified
2559// on the m= line and in a=sctp-port.
2560TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2561 AddSctpDataChannel();
2562 JsepSessionDescription jdesc(kDummyString);
2563 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2564
2565 std::string sdp_with_data = kSdpString;
2566 // Append m= attributes
2567 sdp_with_data.append(kSdpSctpDataChannelString);
2568 // Append a=sctp-port attribute
2569 sdp_with_data.append("a=sctp-port 5000\r\n");
2570 JsepSessionDescription jdesc_output(kDummyString);
2571
2572 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2573}
2574
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002575// For crbug/344475.
2576TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2577 std::string sdp_with_data = kSdpString;
2578 sdp_with_data.append(kSdpSctpDataChannelString);
2579 // Remove the "\n" at the end.
2580 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2581 JsepSessionDescription jdesc_output(kDummyString);
2582
2583 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2584 // No crash is a pass.
2585}
2586
wu@webrtc.org78187522013-10-07 23:32:02 +00002587TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2588 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002589 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002590 char default_portstr[16];
2591 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002592 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002593 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002594 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002595 kUnusualSctpPort);
2596
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002597 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002598 JsepSessionDescription jdesc(kDummyString);
2599 // take our pre-built session description and change the SCTP port.
2600 cricket::SessionDescription* mutant = desc_.Copy();
2601 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2602 mutant->GetContentDescriptionByName(kDataContentName));
2603 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002604 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002605 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002606 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002607 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002608
2609 // note: mutant's owned by jdesc now.
2610 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2611 mutant = NULL;
2612
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002613 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002614 std::string sdp_with_data = kSdpString;
2615 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002616 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002617 unusual_portstr, strlen(unusual_portstr),
2618 &sdp_with_data);
2619 JsepSessionDescription jdesc_output(kDummyString);
2620
2621 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2622 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002623
2624 // We need to test the deserialized JsepSessionDescription from
2625 // kSdpSctpDataChannelStringWithSctpPort for
2626 // draft-ietf-mmusic-sctp-sdp-07
2627 // a=sctp-port
2628 sdp_with_data = kSdpString;
2629 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2630 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2631 unusual_portstr, strlen(unusual_portstr),
2632 &sdp_with_data);
2633
2634 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2635 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002636}
2637
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002638TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002639 // We want to test that deserializing data content limits bandwidth
2640 // settings (it should never be greater than the default).
2641 // This should prevent someone from using unlimited data bandwidth through
2642 // JS and "breaking the Internet".
2643 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002644 std::string sdp_with_bandwidth = kSdpString;
2645 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2646 InjectAfter("a=mid:data_content_name\r\n",
2647 "b=AS:100\r\n",
2648 &sdp_with_bandwidth);
2649 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2650
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002651 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2652}
2653
2654TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2655 AddSctpDataChannel();
2656 JsepSessionDescription jdesc(kDummyString);
2657 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2658 GetFirstDataContent(&desc_)->description);
2659 dcd->set_bandwidth(100 * 1000);
2660 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2661
2662 std::string sdp_with_bandwidth = kSdpString;
2663 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2664 InjectAfter("a=mid:data_content_name\r\n",
2665 "b=AS:100\r\n",
2666 &sdp_with_bandwidth);
2667 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2668
2669 // SCTP has congestion control, so we shouldn't limit the bandwidth
2670 // as we do for RTP.
2671 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002672 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2673}
2674
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2676 TestDeserializeExtmap(true, false);
2677}
2678
2679TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2680 TestDeserializeExtmap(false, true);
2681}
2682
2683TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2684 TestDeserializeExtmap(true, true);
2685}
2686
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002687TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2688 JsepSessionDescription jdesc(kDummyString);
2689 std::string sdp = kSdpFullString;
2690 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2691 // Deserialize
2692 SdpParseError error;
2693 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002694 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002695 EXPECT_EQ(lastline, error.line);
2696 EXPECT_EQ("Invalid SDP line.", error.description);
2697}
2698
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2700 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2701 std::string new_sdp = kSdpOneCandidate;
2702 Replace("udp", "unsupported_transport", &new_sdp);
2703 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2704 new_sdp = kSdpOneCandidate;
2705 Replace("udp", "uDP", &new_sdp);
2706 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2707 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2708 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2709 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2710}
2711
honghaiza54a0802015-12-16 18:37:23 -08002712TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002714 EXPECT_TRUE(
2715 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2717 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2718 Candidate ref_candidate = jcandidate_->candidate();
2719 ref_candidate.set_username("user_rtp");
2720 ref_candidate.set_password("password_rtp");
2721 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2722}
2723
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002724TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2725 JsepSessionDescription jdesc(kDummyString);
2726
2727 // Deserialize
2728 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2729
2730 // Verify
2731 cricket::AudioContentDescription* audio =
2732 static_cast<AudioContentDescription*>(
2733 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2734 EXPECT_TRUE(audio->conference_mode());
2735
2736 cricket::VideoContentDescription* video =
2737 static_cast<VideoContentDescription*>(
2738 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2739 EXPECT_TRUE(video->conference_mode());
2740}
2741
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2743 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002744 const char kSdpEmptyType[] = " =candidate";
2745 const char kSdpEqualAsPlus[] = "a+candidate";
2746 const char kSdpSpaceAfterEqual[] = "a= candidate";
2747 const char kSdpUpperType[] = "A=candidate";
2748 const char kSdpEmptyLine[] = "";
2749 const char kSdpMissingValue[] = "a=";
2750
2751 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 "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 +00002753 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 "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 +00002755 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 "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 +00002757 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002758 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002759 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760
2761 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002762 ExpectParseFailure("v=", kSdpDestroyer);
2763 ExpectParseFailure("o=", kSdpDestroyer);
2764 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002766 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767
2768 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002769 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2770 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771
2772 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002773 ExpectParseFailure("a=candidate", kSdpEmptyType);
2774 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2775 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2776 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777
2778 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2779 // because it's orthogonal to what we are replacing and hence
2780 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002781 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2782 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2783 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2784 ExpectParseFailure("a=sendrecv", kSdpMd5);
2785
2786 // Empty Line
2787 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2788 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002789}
2790
2791TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2792 // ssrc
2793 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002794 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002795 // crypto
2796 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2797 // rtpmap
2798 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2799 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2800 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2801 // candidate
2802 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2803 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2804 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2805 ExpectParseFailure("rport 2346", "rport badvalue");
2806 ExpectParseFailure("rport 2346 generation 2",
2807 "rport 2346 generation badvalue");
2808 // m line
2809 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2810 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2811
2812 // bandwidth
2813 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2814 "b=AS:badvalue\r\n",
2815 "b=AS:badvalue");
2816 // rtcp-fb
2817 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2818 "a=rtcp-fb:badvalue nack\r\n",
2819 "a=rtcp-fb:badvalue nack");
2820 // extmap
2821 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2822 "a=extmap:badvalue http://example.com\r\n",
2823 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824}
2825
2826TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2827 JsepSessionDescription jdesc_output(kDummyString);
2828
2829 const char kSdpWithReorderedPlTypesString[] =
2830 "v=0\r\n"
2831 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2832 "s=-\r\n"
2833 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002834 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2836 // in the map.
2837 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002838 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839
2840 // Deserialize
2841 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2842
2843 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2844 ASSERT_TRUE(ac != NULL);
2845 const AudioContentDescription* acd =
2846 static_cast<const AudioContentDescription*>(ac->description);
2847 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002848 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2849 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850 EXPECT_EQ(104, acd->codecs()[0].id);
2851}
2852
2853TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2854 JsepSessionDescription jdesc_output(kDummyString);
2855 CodecParams params;
2856 params.max_ptime = 40;
2857 params.ptime = 30;
2858 params.min_ptime = 10;
2859 params.sprop_stereo = 1;
2860 params.stereo = 1;
2861 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002862 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002864 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865}
2866
2867TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2868 const bool kUseWildcard = false;
2869 JsepSessionDescription jdesc_output(kDummyString);
2870 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002871 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002872}
2873
2874TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2875 const bool kUseWildcard = true;
2876 JsepSessionDescription jdesc_output(kDummyString);
2877 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002878 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879}
2880
2881TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2882 JsepSessionDescription jdesc_output(kDummyString);
2883
2884 const char kSdpWithFmtpString[] =
2885 "v=0\r\n"
2886 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2887 "s=-\r\n"
2888 "t=0 0\r\n"
2889 "m=video 3457 RTP/SAVPF 120\r\n"
2890 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002891 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2892
2893 // Deserialize
2894 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002895 EXPECT_TRUE(
2896 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002897
2898 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2899 ASSERT_TRUE(vc != NULL);
2900 const VideoContentDescription* vcd =
2901 static_cast<const VideoContentDescription*>(vc->description);
2902 ASSERT_FALSE(vcd->codecs().empty());
2903 cricket::VideoCodec vp8 = vcd->codecs()[0];
2904 EXPECT_EQ("VP8", vp8.name);
2905 EXPECT_EQ(120, vp8.id);
2906 cricket::CodecParameterMap::iterator found =
2907 vp8.params.find("x-google-min-bitrate");
2908 ASSERT_TRUE(found != vp8.params.end());
2909 EXPECT_EQ(found->second, "10");
2910 found = vp8.params.find("x-google-max-quantization");
2911 ASSERT_TRUE(found != vp8.params.end());
2912 EXPECT_EQ(found->second, "40");
2913}
2914
johan2d8d23e2016-06-03 01:22:42 -07002915TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2916 JsepSessionDescription jdesc_output(kDummyString);
2917
2918 const char kSdpWithFmtpString[] =
2919 "v=0\r\n"
2920 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2921 "s=-\r\n"
2922 "t=0 0\r\n"
2923 "m=video 49170 RTP/AVP 98\r\n"
2924 "a=rtpmap:98 H264/90000\r\n"
2925 "a=fmtp:98 profile-level-id=42A01E; "
2926 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2927
2928 // Deserialize.
2929 SdpParseError error;
2930 EXPECT_TRUE(
2931 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2932
2933 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2934 ASSERT_TRUE(vc != NULL);
2935 const VideoContentDescription* vcd =
2936 static_cast<const VideoContentDescription*>(vc->description);
2937 ASSERT_TRUE(vcd != NULL);
2938 ASSERT_FALSE(vcd->codecs().empty());
2939 cricket::VideoCodec h264 = vcd->codecs()[0];
2940 EXPECT_EQ("H264", h264.name);
2941 EXPECT_EQ(98, h264.id);
2942 cricket::CodecParameterMap::const_iterator found =
2943 h264.params.find("profile-level-id");
2944 ASSERT_TRUE(found != h264.params.end());
2945 EXPECT_EQ(found->second, "42A01E");
2946 found = h264.params.find("sprop-parameter-sets");
2947 ASSERT_TRUE(found != h264.params.end());
2948 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
2949}
2950
Donald Curtis0e07f922015-05-15 09:21:23 -07002951TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2952 JsepSessionDescription jdesc_output(kDummyString);
2953
2954 const char kSdpWithFmtpString[] =
2955 "v=0\r\n"
2956 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2957 "s=-\r\n"
2958 "t=0 0\r\n"
2959 "m=video 3457 RTP/SAVPF 120\r\n"
2960 "a=rtpmap:120 VP8/90000\r\n"
2961 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962
2963 // Deserialize
2964 SdpParseError error;
2965 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2966 &error));
2967
2968 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2969 ASSERT_TRUE(vc != NULL);
2970 const VideoContentDescription* vcd =
2971 static_cast<const VideoContentDescription*>(vc->description);
2972 ASSERT_FALSE(vcd->codecs().empty());
2973 cricket::VideoCodec vp8 = vcd->codecs()[0];
2974 EXPECT_EQ("VP8", vp8.name);
2975 EXPECT_EQ(120, vp8.id);
2976 cricket::CodecParameterMap::iterator found =
2977 vp8.params.find("x-google-min-bitrate");
2978 ASSERT_TRUE(found != vp8.params.end());
2979 EXPECT_EQ(found->second, "10");
2980 found = vp8.params.find("x-google-max-quantization");
2981 ASSERT_TRUE(found != vp8.params.end());
2982 EXPECT_EQ(found->second, "40");
2983}
2984
2985TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2986 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2987 GetFirstVideoContent(&desc_)->description);
2988
2989 cricket::VideoCodecs codecs = vcd->codecs();
2990 codecs[0].params["x-google-min-bitrate"] = "10";
2991 vcd->set_codecs(codecs);
2992
2993 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2994 jdesc_.session_id(),
2995 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08002996 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997 std::string sdp_with_fmtp = kSdpFullString;
2998 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2999 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3000 &sdp_with_fmtp);
3001 EXPECT_EQ(sdp_with_fmtp, message);
3002}
3003
3004TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3005 JsepSessionDescription jdesc_with_icelite(kDummyString);
3006 std::string sdp_with_icelite = kSdpFullString;
3007 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3008 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3009 const cricket::TransportInfo* tinfo1 =
3010 desc->GetTransportInfoByName("audio_content_name");
3011 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3012 const cricket::TransportInfo* tinfo2 =
3013 desc->GetTransportInfoByName("video_content_name");
3014 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3015 InjectAfter(kSessionTime,
3016 "a=ice-lite\r\n",
3017 &sdp_with_icelite);
3018 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3019 desc = jdesc_with_icelite.description();
3020 const cricket::TransportInfo* atinfo =
3021 desc->GetTransportInfoByName("audio_content_name");
3022 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3023 const cricket::TransportInfo* vtinfo =
3024 desc->GetTransportInfoByName("video_content_name");
3025 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3026}
3027
3028// Verifies that the candidates in the input SDP are parsed and serialized
3029// correctly in the output SDP.
3030TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3031 std::string sdp_with_data = kSdpString;
3032 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3033 JsepSessionDescription jdesc_output(kDummyString);
3034
3035 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003036 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003037}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003038
3039TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3040 AddFingerprint();
3041 TransportInfo audio_transport_info =
3042 *(desc_.GetTransportInfoByName(kAudioContentName));
3043 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3044 audio_transport_info.description.connection_role);
3045 audio_transport_info.description.connection_role =
3046 cricket::CONNECTIONROLE_ACTIVE;
3047
3048 TransportInfo video_transport_info =
3049 *(desc_.GetTransportInfoByName(kVideoContentName));
3050 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3051 video_transport_info.description.connection_role);
3052 video_transport_info.description.connection_role =
3053 cricket::CONNECTIONROLE_ACTIVE;
3054
3055 desc_.RemoveTransportInfoByName(kAudioContentName);
3056 desc_.RemoveTransportInfoByName(kVideoContentName);
3057
3058 desc_.AddTransportInfo(audio_transport_info);
3059 desc_.AddTransportInfo(video_transport_info);
3060
3061 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3062 jdesc_.session_id(),
3063 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003064 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003065 std::string sdp_with_dtlssetup = kSdpFullString;
3066
3067 // Fingerprint attribute is necessary to add DTLS setup attribute.
3068 InjectAfter(kAttributeIcePwdVoice,
3069 kFingerprint, &sdp_with_dtlssetup);
3070 InjectAfter(kAttributeIcePwdVideo,
3071 kFingerprint, &sdp_with_dtlssetup);
3072 // Now adding |setup| attribute.
3073 InjectAfter(kFingerprint,
3074 "a=setup:active\r\n", &sdp_with_dtlssetup);
3075 EXPECT_EQ(sdp_with_dtlssetup, message);
3076}
3077
3078TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3079 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3080 std::string sdp_with_dtlssetup = kSdpFullString;
3081 InjectAfter(kSessionTime,
3082 "a=setup:actpass\r\n",
3083 &sdp_with_dtlssetup);
3084 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3085 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3086 const cricket::TransportInfo* atinfo =
3087 desc->GetTransportInfoByName("audio_content_name");
3088 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3089 atinfo->description.connection_role);
3090 const cricket::TransportInfo* vtinfo =
3091 desc->GetTransportInfoByName("video_content_name");
3092 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3093 vtinfo->description.connection_role);
3094}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003095
3096// Verifies that the order of the serialized m-lines follows the order of the
3097// ContentInfo in SessionDescription, and vise versa for deserialization.
3098TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3099 JsepSessionDescription jdesc(kDummyString);
3100 const std::string media_content_sdps[3] = {
3101 kSdpAudioString,
3102 kSdpVideoString,
3103 kSdpSctpDataChannelString
3104 };
3105 const cricket::MediaType media_types[3] = {
3106 cricket::MEDIA_TYPE_AUDIO,
3107 cricket::MEDIA_TYPE_VIDEO,
3108 cricket::MEDIA_TYPE_DATA
3109 };
3110
3111 // Verifies all 6 permutations.
3112 for (size_t i = 0; i < 6; ++i) {
3113 size_t media_content_in_sdp[3];
3114 // The index of the first media content.
3115 media_content_in_sdp[0] = i / 2;
3116 // The index of the second media content.
3117 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3118 // The index of the third media content.
3119 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3120
3121 std::string sdp_string = kSdpSessionString;
3122 for (size_t i = 0; i < 3; ++i)
3123 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3124
3125 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3126 cricket::SessionDescription* desc = jdesc.description();
3127 EXPECT_EQ(3u, desc->contents().size());
3128
3129 for (size_t i = 0; i < 3; ++i) {
3130 const cricket::MediaContentDescription* mdesc =
3131 static_cast<const cricket::MediaContentDescription*>(
3132 desc->contents()[i].description);
3133 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3134 }
3135
deadbeef9d3584c2016-02-16 17:54:10 -08003136 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003137 EXPECT_EQ(sdp_string, serialized_sdp);
3138 }
3139}
deadbeef9d3584c2016-02-16 17:54:10 -08003140
3141TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3142 MakePlanBDescription();
3143
3144 JsepSessionDescription deserialized_description(kDummyString);
3145 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3146
3147 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3148}
3149
3150TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3151 MakePlanBDescription();
3152 TestSerialize(jdesc_, false);
3153}
3154
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003155// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3156// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3157// some extent). If we parse this, the Plan B msid attribute (which is more
3158// specific, since it's at the SSRC level) should take priority.
3159TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3160 MakePlanBDescription();
3161
3162 JsepSessionDescription deserialized_description(kDummyString);
3163 EXPECT_TRUE(
3164 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3165
3166 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3167}
3168
deadbeef9d3584c2016-02-16 17:54:10 -08003169TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3170 MakeUnifiedPlanDescription();
3171
3172 JsepSessionDescription deserialized_description(kDummyString);
3173 EXPECT_TRUE(
3174 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3175
3176 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3177}
3178
3179TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3180 MakeUnifiedPlanDescription();
3181 TestSerialize(jdesc_, true);
3182}
deadbeef7e146cb2016-09-28 10:04:34 -07003183
3184// Regression test for heap overflow bug:
3185// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3186TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
3187 JsepSessionDescription jdesc_output(kDummyString);
3188
3189 // The issue occurs when the sctp-port attribute is found in a video
3190 // description. The actual heap overflow occurs when parsing the fmtp line.
3191 const char kSdpWithSctpPortInVideoDescription[] =
3192 "v=0\r\n"
3193 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3194 "s=-\r\n"
3195 "t=0 0\r\n"
3196 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3197 "a=sctp-port 5000\r\n"
3198 "a=fmtp:108 foo=10\r\n";
3199
3200 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3201 "sctp-port");
3202}