blob: f68010902b973945c80daddee5678ced1928dfb6 [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
11#include <set>
12#include <string>
13#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/jsepsessiondescription.h"
16#ifdef WEBRTC_ANDROID
17#include "webrtc/api/test/androidtestinitializer.h"
18#endif
19#include "webrtc/api/webrtcsdp.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/gunit.h"
21#include "webrtc/base/logging.h"
22#include "webrtc/base/messagedigest.h"
23#include "webrtc/base/scoped_ptr.h"
24#include "webrtc/base/sslfingerprint.h"
25#include "webrtc/base/stringencode.h"
26#include "webrtc/base/stringutils.h"
kjellandera96e2d72016-02-04 23:52:28 -080027#include "webrtc/media/base/constants.h"
28#include "webrtc/p2p/base/constants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010029#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31using cricket::AudioCodec;
32using cricket::AudioContentDescription;
33using cricket::Candidate;
34using cricket::ContentInfo;
35using cricket::CryptoParams;
36using cricket::ContentGroup;
37using cricket::DataCodec;
38using cricket::DataContentDescription;
39using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
40using cricket::ICE_CANDIDATE_COMPONENT_RTP;
41using cricket::kFecSsrcGroupSemantics;
42using cricket::LOCAL_PORT_TYPE;
43using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044using cricket::NS_JINGLE_RTP;
45using cricket::RtpHeaderExtension;
46using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
48using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
58using webrtc::SdpParseError;
59using webrtc::SessionDescriptionInterface;
60
61typedef std::vector<AudioCodec> AudioCodecs;
62typedef std::vector<Candidate> Candidates;
63
Peter Boström0c4e06b2015-10-07 12:23:21 +020064static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020066static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080067static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080069static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020071static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kCandidateFoundation1[] = "a0+B/1";
73static const char kCandidateFoundation2[] = "a0+B/2";
74static const char kCandidateFoundation3[] = "a0+B/3";
75static const char kCandidateFoundation4[] = "a0+B/4";
76static const char kAttributeCryptoVoice[] =
77 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
78 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
79 "dummy_session_params\r\n";
80static const char kAttributeCryptoVideo[] =
81 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
82 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
83static const char kFingerprint[] = "a=fingerprint:sha-1 "
84 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
85static const int kExtmapId = 1;
86static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
87static const char kExtmap[] =
88 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
89static const char kExtmapWithDirectionAndAttribute[] =
90 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
91
Peter Boström0c4e06b2015-10-07 12:23:21 +020092static const uint8_t kIdentityDigest[] = {
93 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
94 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
lally@webrtc.org34807282015-02-24 20:19:39 +000096static const char kDtlsSctp[] = "DTLS/SCTP";
97static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
98static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +000099
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100struct CodecParams {
101 int max_ptime;
102 int ptime;
103 int min_ptime;
104 int sprop_stereo;
105 int stereo;
106 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000107 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108};
109
deadbeef9d3584c2016-02-16 17:54:10 -0800110// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
111// instead of "a=crypto", and have an explicit test for adding "a=crypto".
112// Currently it's the other way around.
113
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114// Reference sdp string
115static const char kSdpFullString[] =
116 "v=0\r\n"
117 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
118 "s=-\r\n"
119 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800120 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
122 "c=IN IP4 74.125.127.126\r\n"
123 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
124 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
125 "generation 2\r\n"
126 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
127 "generation 2\r\n"
128 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
129 "generation 2\r\n"
130 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
133 "raddr 192.168.1.5 rport 2346 "
134 "generation 2\r\n"
135 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
136 "raddr 192.168.1.5 rport 2348 "
137 "generation 2\r\n"
138 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
139 "a=mid:audio_content_name\r\n"
140 "a=sendrecv\r\n"
141 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800142 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
144 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
145 "dummy_session_params\r\n"
146 "a=rtpmap:111 opus/48000/2\r\n"
147 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000148 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 "a=ssrc:1 cname:stream_1_cname\r\n"
150 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
151 "a=ssrc:1 mslabel:local_stream_1\r\n"
152 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 "m=video 3457 RTP/SAVPF 120\r\n"
154 "c=IN IP4 74.125.224.39\r\n"
155 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
156 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
165 "generation 2\r\n"
166 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
167 "generation 2\r\n"
168 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
169 "a=mid:video_content_name\r\n"
170 "a=sendrecv\r\n"
171 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
172 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
173 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800174 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 "a=ssrc:2 cname:stream_1_cname\r\n"
176 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
177 "a=ssrc:2 mslabel:local_stream_1\r\n"
178 "a=ssrc:2 label:video_track_id_1\r\n"
179 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800180 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800182 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183
184// SDP reference string without the candidates.
185static const char kSdpString[] =
186 "v=0\r\n"
187 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
188 "s=-\r\n"
189 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800190 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000191 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000192 "c=IN IP4 0.0.0.0\r\n"
193 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
195 "a=mid:audio_content_name\r\n"
196 "a=sendrecv\r\n"
197 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800198 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
200 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
201 "dummy_session_params\r\n"
202 "a=rtpmap:111 opus/48000/2\r\n"
203 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000204 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=ssrc:1 cname:stream_1_cname\r\n"
206 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
207 "a=ssrc:1 mslabel:local_stream_1\r\n"
208 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000209 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000210 "c=IN IP4 0.0.0.0\r\n"
211 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
213 "a=mid:video_content_name\r\n"
214 "a=sendrecv\r\n"
215 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
216 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
217 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800218 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 "a=ssrc:2 cname:stream_1_cname\r\n"
220 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
221 "a=ssrc:2 mslabel:local_stream_1\r\n"
222 "a=ssrc:2 label:video_track_id_1\r\n"
223 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800224 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227
228static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000229 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000230 "c=IN IP4 0.0.0.0\r\n"
231 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=ice-ufrag:ufrag_data\r\n"
233 "a=ice-pwd:pwd_data\r\n"
234 "a=mid:data_content_name\r\n"
235 "a=sendrecv\r\n"
236 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
237 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
238 "a=rtpmap:101 google-data/90000\r\n"
239 "a=ssrc:10 cname:data_channel_cname\r\n"
240 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
241 "a=ssrc:10 mslabel:data_channel\r\n"
242 "a=ssrc:10 label:data_channeld0\r\n";
243
244static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000245 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000246 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 "a=ice-ufrag:ufrag_data\r\n"
248 "a=ice-pwd:pwd_data\r\n"
249 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000252// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000253static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000254 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
255 "a=max-message-size=100000\r\n"
256 "a=sctp-port 5000\r\n"
257 "c=IN IP4 0.0.0.0\r\n"
258 "a=ice-ufrag:ufrag_data\r\n"
259 "a=ice-pwd:pwd_data\r\n"
260 "a=mid:data_content_name\r\n";
261
lally69f57602015-10-08 10:15:04 -0700262static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port:5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271static const char kSdpSctpDataChannelWithCandidatesString[] =
272 "m=application 2345 DTLS/SCTP 5000\r\n"
273 "c=IN IP4 74.125.127.126\r\n"
274 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
275 "generation 2\r\n"
276 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
277 "generation 2\r\n"
278 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
279 "raddr 192.168.1.5 rport 2346 "
280 "generation 2\r\n"
281 "a=ice-ufrag:ufrag_data\r\n"
282 "a=ice-pwd:pwd_data\r\n"
283 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000284 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000286static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000287 "v=0\r\n"
288 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
289 "s=-\r\n"
290 "t=0 0\r\n"
291 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000292 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000293 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000294 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000295 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000296 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000297 "a=x-google-flag:conference\r\n";
298
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000299static const char kSdpSessionString[] =
300 "v=0\r\n"
301 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
302 "s=-\r\n"
303 "t=0 0\r\n"
304 "a=msid-semantic: WMS local_stream\r\n";
305
306static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
309 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000310 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
311 "a=mid:audio_content_name\r\n"
312 "a=sendrecv\r\n"
313 "a=rtpmap:111 opus/48000/2\r\n"
314 "a=ssrc:1 cname:stream_1_cname\r\n"
315 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
316 "a=ssrc:1 mslabel:local_stream\r\n"
317 "a=ssrc:1 label:audio_track_id_1\r\n";
318
319static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000320 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000321 "c=IN IP4 0.0.0.0\r\n"
322 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000323 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
324 "a=mid:video_content_name\r\n"
325 "a=sendrecv\r\n"
326 "a=rtpmap:120 VP8/90000\r\n"
327 "a=ssrc:2 cname:stream_1_cname\r\n"
328 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
329 "a=ssrc:2 mslabel:local_stream\r\n"
330 "a=ssrc:2 label:video_track_id_1\r\n";
331
deadbeef9d3584c2016-02-16 17:54:10 -0800332// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
333// tracks.
334static const char kPlanBSdpFullString[] =
335 "v=0\r\n"
336 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
337 "s=-\r\n"
338 "t=0 0\r\n"
339 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
340 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
341 "c=IN IP4 74.125.127.126\r\n"
342 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
343 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
344 "generation 2\r\n"
345 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
346 "generation 2\r\n"
347 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
348 "generation 2\r\n"
349 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
352 "raddr 192.168.1.5 rport 2346 "
353 "generation 2\r\n"
354 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
355 "raddr 192.168.1.5 rport 2348 "
356 "generation 2\r\n"
357 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
358 "a=mid:audio_content_name\r\n"
359 "a=sendrecv\r\n"
360 "a=rtcp-mux\r\n"
361 "a=rtcp-rsize\r\n"
362 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
363 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
364 "dummy_session_params\r\n"
365 "a=rtpmap:111 opus/48000/2\r\n"
366 "a=rtpmap:103 ISAC/16000\r\n"
367 "a=rtpmap:104 ISAC/32000\r\n"
368 "a=ssrc:1 cname:stream_1_cname\r\n"
369 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
370 "a=ssrc:1 mslabel:local_stream_1\r\n"
371 "a=ssrc:1 label:audio_track_id_1\r\n"
372 "a=ssrc:4 cname:stream_2_cname\r\n"
373 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
374 "a=ssrc:4 mslabel:local_stream_2\r\n"
375 "a=ssrc:4 label:audio_track_id_2\r\n"
376 "m=video 3457 RTP/SAVPF 120\r\n"
377 "c=IN IP4 74.125.224.39\r\n"
378 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
379 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
388 "generation 2\r\n"
389 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
390 "generation 2\r\n"
391 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
392 "a=mid:video_content_name\r\n"
393 "a=sendrecv\r\n"
394 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
395 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
396 "a=rtpmap:120 VP8/90000\r\n"
397 "a=ssrc-group:FEC 2 3\r\n"
398 "a=ssrc:2 cname:stream_1_cname\r\n"
399 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:2 mslabel:local_stream_1\r\n"
401 "a=ssrc:2 label:video_track_id_1\r\n"
402 "a=ssrc:3 cname:stream_1_cname\r\n"
403 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
404 "a=ssrc:3 mslabel:local_stream_1\r\n"
405 "a=ssrc:3 label:video_track_id_1\r\n"
406 "a=ssrc:5 cname:stream_2_cname\r\n"
407 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
408 "a=ssrc:5 mslabel:local_stream_2\r\n"
409 "a=ssrc:5 label:video_track_id_2\r\n"
410 "a=ssrc:6 cname:stream_2_cname\r\n"
411 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
412 "a=ssrc:6 mslabel:local_stream_2\r\n"
413 "a=ssrc:6 label:video_track_id_3\r\n";
414
415// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
416// tracks.
417static const char kUnifiedPlanSdpFullString[] =
418 "v=0\r\n"
419 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
420 "s=-\r\n"
421 "t=0 0\r\n"
422 "a=msid-semantic: WMS local_stream_1\r\n"
423 // Audio track 1, stream 1 (with candidates).
424 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
425 "c=IN IP4 74.125.127.126\r\n"
426 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
427 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
428 "generation 2\r\n"
429 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
430 "generation 2\r\n"
431 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
432 "generation 2\r\n"
433 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
434 "generation 2\r\n"
435 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
436 "raddr 192.168.1.5 rport 2346 "
437 "generation 2\r\n"
438 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
439 "raddr 192.168.1.5 rport 2348 "
440 "generation 2\r\n"
441 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
442 "a=mid:audio_content_name\r\n"
443 "a=msid:local_stream_1 audio_track_id_1\r\n"
444 "a=sendrecv\r\n"
445 "a=rtcp-mux\r\n"
446 "a=rtcp-rsize\r\n"
447 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
448 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
449 "dummy_session_params\r\n"
450 "a=rtpmap:111 opus/48000/2\r\n"
451 "a=rtpmap:103 ISAC/16000\r\n"
452 "a=rtpmap:104 ISAC/32000\r\n"
453 "a=ssrc:1 cname:stream_1_cname\r\n"
454 // Video track 1, stream 1 (with candidates).
455 "m=video 3457 RTP/SAVPF 120\r\n"
456 "c=IN IP4 74.125.224.39\r\n"
457 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
458 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
459 "generation 2\r\n"
460 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
461 "generation 2\r\n"
462 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
463 "generation 2\r\n"
464 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
465 "generation 2\r\n"
466 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
467 "generation 2\r\n"
468 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
469 "generation 2\r\n"
470 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
471 "a=mid:video_content_name\r\n"
472 "a=msid:local_stream_1 video_track_id_1\r\n"
473 "a=sendrecv\r\n"
474 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
475 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
476 "a=rtpmap:120 VP8/90000\r\n"
477 "a=ssrc-group:FEC 2 3\r\n"
478 "a=ssrc:2 cname:stream_1_cname\r\n"
479 "a=ssrc:3 cname:stream_1_cname\r\n"
480 // Audio track 2, stream 2.
481 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
482 "c=IN IP4 0.0.0.0\r\n"
483 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
484 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
485 "a=mid:audio_content_name_2\r\n"
486 "a=msid:local_stream_2 audio_track_id_2\r\n"
487 "a=sendrecv\r\n"
488 "a=rtcp-mux\r\n"
489 "a=rtcp-rsize\r\n"
490 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
491 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
492 "dummy_session_params\r\n"
493 "a=rtpmap:111 opus/48000/2\r\n"
494 "a=rtpmap:103 ISAC/16000\r\n"
495 "a=rtpmap:104 ISAC/32000\r\n"
496 "a=ssrc:4 cname:stream_2_cname\r\n"
497 // Video track 2, stream 2.
498 "m=video 9 RTP/SAVPF 120\r\n"
499 "c=IN IP4 0.0.0.0\r\n"
500 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
501 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
502 "a=mid:video_content_name_2\r\n"
503 "a=msid:local_stream_2 video_track_id_2\r\n"
504 "a=sendrecv\r\n"
505 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
506 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
507 "a=rtpmap:120 VP8/90000\r\n"
508 "a=ssrc:5 cname:stream_2_cname\r\n"
509 // Video track 3, stream 2.
510 "m=video 9 RTP/SAVPF 120\r\n"
511 "c=IN IP4 0.0.0.0\r\n"
512 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
513 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
514 "a=mid:video_content_name_3\r\n"
515 "a=msid:local_stream_2 video_track_id_3\r\n"
516 "a=sendrecv\r\n"
517 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
518 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
519 "a=rtpmap:120 VP8/90000\r\n"
520 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521
522// One candidate reference string as per W3c spec.
523// candidate:<blah> not a=candidate:<blah>CRLF
524static const char kRawCandidate[] =
525 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
526// One candidate reference string.
527static const char kSdpOneCandidate[] =
528 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
529 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000530
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000531static const char kSdpTcpActiveCandidate[] =
532 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
533 "tcptype active generation 2";
534static const char kSdpTcpPassiveCandidate[] =
535 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
536 "tcptype passive generation 2";
537static const char kSdpTcpSOCandidate[] =
538 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
539 "tcptype so generation 2";
540static const char kSdpTcpInvalidCandidate[] =
541 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
542 "tcptype invalid generation 2";
543
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000544// One candidate reference string with IPV6 address.
545static const char kRawIPV6Candidate[] =
546 "candidate:a0+B/1 1 udp 2130706432 "
547 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548
549// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800550static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800552 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553
554// Session id and version
555static const char kSessionId[] = "18446744069414584320";
556static const char kSessionVersion[] = "18446462598732840960";
557
deadbeef9d3584c2016-02-16 17:54:10 -0800558// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559static const char kIceOption1[] = "iceoption1";
560static const char kIceOption2[] = "iceoption2";
561static const char kIceOption3[] = "iceoption3";
562
deadbeef9d3584c2016-02-16 17:54:10 -0800563// ICE ufrags/passwords.
564static const char kUfragVoice[] = "ufrag_voice";
565static const char kPwdVoice[] = "pwd_voice";
566static const char kUfragVideo[] = "ufrag_video";
567static const char kPwdVideo[] = "pwd_video";
568static const char kUfragData[] = "ufrag_data";
569static const char kPwdData[] = "pwd_data";
570
571// Extra ufrags/passwords for extra unified plan m= sections.
572static const char kUfragVoice2[] = "ufrag_voice_2";
573static const char kPwdVoice2[] = "pwd_voice_2";
574static const char kUfragVideo2[] = "ufrag_video_2";
575static const char kPwdVideo2[] = "pwd_video_2";
576static const char kUfragVideo3[] = "ufrag_video_3";
577static const char kPwdVideo3[] = "pwd_video_3";
578
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579// Content name
580static const char kAudioContentName[] = "audio_content_name";
581static const char kVideoContentName[] = "video_content_name";
582static const char kDataContentName[] = "data_content_name";
583
deadbeef9d3584c2016-02-16 17:54:10 -0800584// Extra content names for extra unified plan m= sections.
585static const char kAudioContentName2[] = "audio_content_name_2";
586static const char kVideoContentName2[] = "video_content_name_2";
587static const char kVideoContentName3[] = "video_content_name_3";
588
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589// MediaStream 1
590static const char kStreamLabel1[] = "local_stream_1";
591static const char kStream1Cname[] = "stream_1_cname";
592static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200593static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800595static const uint32_t kVideoTrack1Ssrc1 = 2;
596static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597
598// MediaStream 2
599static const char kStreamLabel2[] = "local_stream_2";
600static const char kStream2Cname[] = "stream_2_cname";
601static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200602static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800603static const char kVideoTrackId2[] = "video_track_id_2";
604static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800606static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607
608// DataChannel
609static const char kDataChannelLabel[] = "data_channel";
610static const char kDataChannelMsid[] = "data_channeld0";
611static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200612static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613
614// Candidate
615static const char kDummyMid[] = "dummy_mid";
616static const int kDummyIndex = 123;
617
618// Misc
619static const char kDummyString[] = "dummy";
620
621// Helper functions
622
623static bool SdpDeserialize(const std::string& message,
624 JsepSessionDescription* jdesc) {
625 return webrtc::SdpDeserialize(message, jdesc, NULL);
626}
627
628static bool SdpDeserializeCandidate(const std::string& message,
629 JsepIceCandidate* candidate) {
630 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
631}
632
633// Add some extra |newlines| to the |message| after |line|.
634static void InjectAfter(const std::string& line,
635 const std::string& newlines,
636 std::string* message) {
637 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000638 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 tmp.c_str(), tmp.length(), message);
640}
641
642static void Replace(const std::string& line,
643 const std::string& newlines,
644 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000645 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 newlines.c_str(), newlines.length(), message);
647}
648
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000649// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
650// message.
651static void ExpectParseFailure(const std::string& bad_sdp,
652 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000655 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000657 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
658}
659
660// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
661static void ExpectParseFailure(const char* good_part, const char* bad_part) {
662 std::string bad_sdp = kSdpFullString;
663 Replace(good_part, bad_part, &bad_sdp);
664 ExpectParseFailure(bad_sdp, bad_part);
665}
666
667// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
668static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
669 const std::string& newlines,
670 const std::string& bad_part) {
671 std::string bad_sdp = kSdpFullString;
672 InjectAfter(injectpoint, newlines, &bad_sdp);
673 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674}
675
676static void ReplaceDirection(cricket::MediaContentDirection direction,
677 std::string* message) {
678 std::string new_direction;
679 switch (direction) {
680 case cricket::MD_INACTIVE:
681 new_direction = "a=inactive";
682 break;
683 case cricket::MD_SENDONLY:
684 new_direction = "a=sendonly";
685 break;
686 case cricket::MD_RECVONLY:
687 new_direction = "a=recvonly";
688 break;
689 case cricket::MD_SENDRECV:
690 default:
691 new_direction = "a=sendrecv";
692 break;
693 }
694 Replace("a=sendrecv", new_direction, message);
695}
696
697static void ReplaceRejected(bool audio_rejected, bool video_rejected,
698 std::string* message) {
699 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800700 Replace("m=audio 9", "m=audio 0", message);
701 Replace(kAttributeIceUfragVoice, "", message);
702 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 }
704 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800705 Replace("m=video 9", "m=video 0", message);
706 Replace(kAttributeIceUfragVideo, "", message);
707 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709}
710
711// WebRtcSdpTest
712
713class WebRtcSdpTest : public testing::Test {
714 public:
715 WebRtcSdpTest()
716 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800717#ifdef WEBRTC_ANDROID
718 webrtc::InitializeAndroidObjects();
719#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 // AudioContentDescription
721 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800722 StreamParams audio_stream;
723 audio_stream.id = kAudioTrackId1;
724 audio_stream.cname = kStream1Cname;
725 audio_stream.sync_label = kStreamLabel1;
726 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
727 audio_desc_->AddStream(audio_stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
729
730 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800731 video_desc_ = CreateVideoContentDescription();
732 StreamParams video_stream;
733 video_stream.id = kVideoTrackId1;
734 video_stream.cname = kStream1Cname;
735 video_stream.sync_label = kStreamLabel1;
736 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
737 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
738 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
739 video_stream.ssrc_groups.push_back(ssrc_group);
740 video_desc_->AddStream(video_stream);
741 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742
743 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800744 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
745 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
746 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
747 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748
749 // v4 host
750 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000751 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000752 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000753 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
754 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000756 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000757 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
758 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000760 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000761 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
762 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000764 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000765 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
766 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767
768 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000769 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000770 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
771 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000772 cricket::LOCAL_PORT_TYPE,
773 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000775 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
776 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000777 cricket::LOCAL_PORT_TYPE,
778 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000780 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
781 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000782 cricket::LOCAL_PORT_TYPE,
783 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000785 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
786 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000787 cricket::LOCAL_PORT_TYPE,
788 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789
790 // stun
791 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000792 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
793 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000794 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
795 address_stun, kCandidatePriority, "", "",
796 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000797 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 candidate9.set_related_address(rel_address_stun);
799
800 address_stun.SetPort(port_stun++);
801 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000802 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
803 address_stun, kCandidatePriority, "", "",
804 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000805 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 candidate10.set_related_address(rel_address_stun);
807
808 // relay
809 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000810 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000811 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
812 address_relay, kCandidatePriority, "", "",
813 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000814 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000816 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
817 address_relay, kCandidatePriority, "", "",
818 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000819 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820
821 // voice
822 candidates_.push_back(candidate1);
823 candidates_.push_back(candidate2);
824 candidates_.push_back(candidate5);
825 candidates_.push_back(candidate6);
826 candidates_.push_back(candidate9);
827 candidates_.push_back(candidate10);
828
829 // video
830 candidates_.push_back(candidate3);
831 candidates_.push_back(candidate4);
832 candidates_.push_back(candidate7);
833 candidates_.push_back(candidate8);
834 candidates_.push_back(candidate11);
835 candidates_.push_back(candidate12);
836
837 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
838 0, candidate1));
839
840 // Set up JsepSessionDescription.
841 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
842 std::string mline_id;
843 int mline_index = 0;
844 for (size_t i = 0; i< candidates_.size(); ++i) {
845 // In this test, the audio m line index will be 0, and the video m line
846 // will be 1.
847 bool is_video = (i > 5);
848 mline_id = is_video ? "video_content_name" : "audio_content_name";
849 mline_index = is_video ? 1 : 0;
850 JsepIceCandidate jice(mline_id,
851 mline_index,
852 candidates_.at(i));
853 jdesc_.AddCandidate(&jice);
854 }
855 }
856
deadbeef9d3584c2016-02-16 17:54:10 -0800857 // Turns the existing reference description into a plan B description,
858 // with 2 audio tracks and 3 video tracks.
859 void MakePlanBDescription() {
860 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
861 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
862
863 StreamParams audio_track_2;
864 audio_track_2.id = kAudioTrackId2;
865 audio_track_2.cname = kStream2Cname;
866 audio_track_2.sync_label = kStreamLabel2;
867 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
868 audio_desc_->AddStream(audio_track_2);
869
870 StreamParams video_track_2;
871 video_track_2.id = kVideoTrackId2;
872 video_track_2.cname = kStream2Cname;
873 video_track_2.sync_label = kStreamLabel2;
874 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
875 video_desc_->AddStream(video_track_2);
876
877 StreamParams video_track_3;
878 video_track_3.id = kVideoTrackId3;
879 video_track_3.cname = kStream2Cname;
880 video_track_3.sync_label = kStreamLabel2;
881 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
882 video_desc_->AddStream(video_track_3);
883
884 desc_.RemoveContentByName(kAudioContentName);
885 desc_.RemoveContentByName(kVideoContentName);
886 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
887 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
888
889 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
890 jdesc_.session_version()));
891 }
892
893 // Turns the existing reference description into a unified plan description,
894 // with 2 audio tracks and 3 video tracks.
895 void MakeUnifiedPlanDescription() {
896 // Audio track 2.
897 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
898 StreamParams audio_track_2;
899 audio_track_2.id = kAudioTrackId2;
900 audio_track_2.cname = kStream2Cname;
901 audio_track_2.sync_label = kStreamLabel2;
902 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
903 audio_desc_2->AddStream(audio_track_2);
904 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
905 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
906 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
907
908 // Video track 2, in stream 2.
909 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
910 StreamParams video_track_2;
911 video_track_2.id = kVideoTrackId2;
912 video_track_2.cname = kStream2Cname;
913 video_track_2.sync_label = kStreamLabel2;
914 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
915 video_desc_2->AddStream(video_track_2);
916 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
917 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
918 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
919
920 // Video track 3, in stream 2.
921 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
922 StreamParams video_track_3;
923 video_track_3.id = kVideoTrackId3;
924 video_track_3.cname = kStream2Cname;
925 video_track_3.sync_label = kStreamLabel2;
926 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
927 video_desc_3->AddStream(video_track_3);
928 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
929 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
930 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
931
932 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
933 jdesc_.session_version()));
934 }
935
936 // Creates an audio content description with no streams, and some default
937 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 AudioContentDescription* CreateAudioContentDescription() {
939 AudioContentDescription* audio = new AudioContentDescription();
940 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -0800941 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
943 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
944 "dummy_session_params"));
945 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef9d3584c2016-02-16 17:54:10 -0800946 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
947 audio->AddCodec(opus);
948 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
949 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 return audio;
951 }
952
deadbeef9d3584c2016-02-16 17:54:10 -0800953 // Creates a video content description with no streams, and some default
954 // configuration.
955 VideoContentDescription* CreateVideoContentDescription() {
956 VideoContentDescription* video = new VideoContentDescription();
957 video->AddCrypto(CryptoParams(
958 1, "AES_CM_128_HMAC_SHA1_80",
959 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
960 video->set_protocol(cricket::kMediaProtocolSavpf);
961 video->AddCodec(
962 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName,
963 JsepSessionDescription::kMaxVideoCodecWidth,
964 JsepSessionDescription::kMaxVideoCodecHeight,
965 JsepSessionDescription::kDefaultVideoCodecFramerate,
966 JsepSessionDescription::kDefaultVideoCodecPreference));
967 return video;
968 }
969
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 template <class MCD>
971 void CompareMediaContentDescription(const MCD* cd1,
972 const MCD* cd2) {
973 // type
974 EXPECT_EQ(cd1->type(), cd1->type());
975
976 // content direction
977 EXPECT_EQ(cd1->direction(), cd2->direction());
978
979 // rtcp_mux
980 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
981
deadbeef13871492015-12-09 12:37:51 -0800982 // rtcp_reduced_size
983 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
984
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 // cryptos
986 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
987 if (cd1->cryptos().size() != cd2->cryptos().size()) {
988 ADD_FAILURE();
989 return;
990 }
991 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
992 const CryptoParams c1 = cd1->cryptos().at(i);
993 const CryptoParams c2 = cd2->cryptos().at(i);
994 EXPECT_TRUE(c1.Matches(c2));
995 EXPECT_EQ(c1.key_params, c2.key_params);
996 EXPECT_EQ(c1.session_params, c2.session_params);
997 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000998
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001000 // Use an equivalence class here, for old and new versions of the
1001 // protocol description.
1002 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001003 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1004 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1005 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001006 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001007 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1008 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1009 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001010 } else {
1011 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1012 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013
1014 // codecs
1015 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1016
1017 // bandwidth
1018 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1019
1020 // streams
1021 EXPECT_EQ(cd1->streams(), cd2->streams());
1022
1023 // extmap
1024 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1025 cd2->rtp_header_extensions().size());
1026 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1027 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
1028 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
1029 EXPECT_EQ(ext1.uri, ext2.uri);
1030 EXPECT_EQ(ext1.id, ext2.id);
1031 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 }
1033
1034
1035 void CompareSessionDescription(const SessionDescription& desc1,
1036 const SessionDescription& desc2) {
1037 // Compare content descriptions.
1038 if (desc1.contents().size() != desc2.contents().size()) {
1039 ADD_FAILURE();
1040 return;
1041 }
1042 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1043 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1044 const cricket::ContentInfo& c2 = desc2.contents().at(i);
1045 // content name
1046 EXPECT_EQ(c1.name, c2.name);
1047 // content type
1048 // Note, ASSERT will return from the function, but will not stop the test.
1049 ASSERT_EQ(c1.type, c2.type);
1050
1051 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1052 if (IsAudioContent(&c1)) {
1053 const AudioContentDescription* acd1 =
1054 static_cast<const AudioContentDescription*>(c1.description);
1055 const AudioContentDescription* acd2 =
1056 static_cast<const AudioContentDescription*>(c2.description);
1057 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1058 }
1059
1060 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1061 if (IsVideoContent(&c1)) {
1062 const VideoContentDescription* vcd1 =
1063 static_cast<const VideoContentDescription*>(c1.description);
1064 const VideoContentDescription* vcd2 =
1065 static_cast<const VideoContentDescription*>(c2.description);
1066 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1067 }
1068
1069 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1070 if (IsDataContent(&c1)) {
1071 const DataContentDescription* dcd1 =
1072 static_cast<const DataContentDescription*>(c1.description);
1073 const DataContentDescription* dcd2 =
1074 static_cast<const DataContentDescription*>(c2.description);
1075 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1076 }
1077 }
1078
1079 // group
1080 const cricket::ContentGroups groups1 = desc1.groups();
1081 const cricket::ContentGroups groups2 = desc2.groups();
1082 EXPECT_EQ(groups1.size(), groups1.size());
1083 if (groups1.size() != groups2.size()) {
1084 ADD_FAILURE();
1085 return;
1086 }
1087 for (size_t i = 0; i < groups1.size(); ++i) {
1088 const cricket::ContentGroup group1 = groups1.at(i);
1089 const cricket::ContentGroup group2 = groups2.at(i);
1090 EXPECT_EQ(group1.semantics(), group2.semantics());
1091 const cricket::ContentNames names1 = group1.content_names();
1092 const cricket::ContentNames names2 = group2.content_names();
1093 EXPECT_EQ(names1.size(), names2.size());
1094 if (names1.size() != names2.size()) {
1095 ADD_FAILURE();
1096 return;
1097 }
1098 cricket::ContentNames::const_iterator iter1 = names1.begin();
1099 cricket::ContentNames::const_iterator iter2 = names2.begin();
1100 while (iter1 != names1.end()) {
1101 EXPECT_EQ(*iter1++, *iter2++);
1102 }
1103 }
1104
1105 // transport info
1106 const cricket::TransportInfos transports1 = desc1.transport_infos();
1107 const cricket::TransportInfos transports2 = desc2.transport_infos();
1108 EXPECT_EQ(transports1.size(), transports2.size());
1109 if (transports1.size() != transports2.size()) {
1110 ADD_FAILURE();
1111 return;
1112 }
1113 for (size_t i = 0; i < transports1.size(); ++i) {
1114 const cricket::TransportInfo transport1 = transports1.at(i);
1115 const cricket::TransportInfo transport2 = transports2.at(i);
1116 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 EXPECT_EQ(transport1.description.ice_ufrag,
1118 transport2.description.ice_ufrag);
1119 EXPECT_EQ(transport1.description.ice_pwd,
1120 transport2.description.ice_pwd);
1121 if (transport1.description.identity_fingerprint) {
1122 EXPECT_EQ(*transport1.description.identity_fingerprint,
1123 *transport2.description.identity_fingerprint);
1124 } else {
1125 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1126 transport2.description.identity_fingerprint.get());
1127 }
1128 EXPECT_EQ(transport1.description.transport_options,
1129 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 }
deadbeefc80741f2015-10-22 13:14:45 -07001131
1132 // global attributes
1133 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 }
1135
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 bool CompareSessionDescription(
1137 const JsepSessionDescription& desc1,
1138 const JsepSessionDescription& desc2) {
1139 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1140 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1141 CompareSessionDescription(*desc1.description(), *desc2.description());
1142 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1143 return false;
1144 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1145 const IceCandidateCollection* cc1 = desc1.candidates(i);
1146 const IceCandidateCollection* cc2 = desc2.candidates(i);
1147 if (cc1->count() != cc2->count())
1148 return false;
1149 for (size_t j = 0; j < cc1->count(); ++j) {
1150 const IceCandidateInterface* c1 = cc1->at(j);
1151 const IceCandidateInterface* c2 = cc2->at(j);
1152 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1153 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1154 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1155 }
1156 }
1157 return true;
1158 }
1159
1160 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1161 // them with invalid keywords so that the parser will just ignore them.
1162 bool RemoveCandidateUfragPwd(std::string* sdp) {
1163 const char ice_ufrag[] = "a=ice-ufrag";
1164 const char ice_ufragx[] = "a=xice-ufrag";
1165 const char ice_pwd[] = "a=ice-pwd";
1166 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001167 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001169 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 ice_pwdx, strlen(ice_pwdx), sdp);
1171 return true;
1172 }
1173
1174 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1175 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1176 const std::string& ufrag, const std::string& pwd) {
1177 std::string content_name;
1178 if (mline_index == 0) {
1179 content_name = kAudioContentName;
1180 } else if (mline_index == 1) {
1181 content_name = kVideoContentName;
1182 } else {
1183 ASSERT(false);
1184 }
1185 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001186 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 SessionDescription* desc =
1188 const_cast<SessionDescription*>(jdesc->description());
1189 desc->RemoveTransportInfoByName(content_name);
1190 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1191 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1192 const IceCandidateCollection* cc = jdesc_.candidates(i);
1193 for (size_t j = 0; j < cc->count(); ++j) {
1194 if (cc->at(j)->sdp_mline_index() == mline_index) {
1195 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1196 ufrag);
1197 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1198 pwd);
1199 }
1200 }
1201 }
1202 return true;
1203 }
1204
1205 void AddIceOptions(const std::string& content_name,
1206 const std::vector<std::string>& transport_options) {
1207 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1208 cricket::TransportInfo transport_info =
1209 *(desc_.GetTransportInfoByName(content_name));
1210 desc_.RemoveTransportInfoByName(content_name);
1211 transport_info.description.transport_options = transport_options;
1212 desc_.AddTransportInfo(transport_info);
1213 }
1214
deadbeef3f7219b2015-12-28 15:17:14 -08001215 void SetIceUfragPwd(const std::string& content_name,
1216 const std::string& ice_ufrag,
1217 const std::string& ice_pwd) {
1218 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1219 cricket::TransportInfo transport_info =
1220 *(desc_.GetTransportInfoByName(content_name));
1221 desc_.RemoveTransportInfoByName(content_name);
1222 transport_info.description.ice_ufrag = ice_ufrag;
1223 transport_info.description.ice_pwd = ice_pwd;
1224 desc_.AddTransportInfo(transport_info);
1225 }
1226
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227 void AddFingerprint() {
1228 desc_.RemoveTransportInfoByName(kAudioContentName);
1229 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001230 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231 kIdentityDigest,
1232 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001233 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1234 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001235 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1236 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001237 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1238 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1239 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001240 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1241 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001242 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 }
1244
1245 void AddExtmap() {
1246 audio_desc_ = static_cast<AudioContentDescription*>(
1247 audio_desc_->Copy());
1248 video_desc_ = static_cast<VideoContentDescription*>(
1249 video_desc_->Copy());
1250 audio_desc_->AddRtpHeaderExtension(
1251 RtpHeaderExtension(kExtmapUri, kExtmapId));
1252 video_desc_->AddRtpHeaderExtension(
1253 RtpHeaderExtension(kExtmapUri, kExtmapId));
1254 desc_.RemoveContentByName(kAudioContentName);
1255 desc_.RemoveContentByName(kVideoContentName);
1256 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1257 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1258 }
1259
1260 void RemoveCryptos() {
1261 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1262 video_desc_->set_cryptos(std::vector<CryptoParams>());
1263 }
1264
1265 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1266 audio_desc_->set_direction(direction);
1267 video_desc_->set_direction(direction);
1268 std::string new_sdp = kSdpFullString;
1269 ReplaceDirection(direction, &new_sdp);
1270
1271 if (!jdesc_.Initialize(desc_.Copy(),
1272 jdesc_.session_id(),
1273 jdesc_.session_version())) {
1274 return false;
1275 }
deadbeef9d3584c2016-02-16 17:54:10 -08001276 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 EXPECT_EQ(new_sdp, message);
1278 return true;
1279 }
1280
1281 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1282 audio_desc_ = static_cast<AudioContentDescription*>(
1283 audio_desc_->Copy());
1284 video_desc_ = static_cast<VideoContentDescription*>(
1285 video_desc_->Copy());
1286 desc_.RemoveContentByName(kAudioContentName);
1287 desc_.RemoveContentByName(kVideoContentName);
1288 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1289 audio_desc_);
1290 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1291 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001292 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1293 audio_rejected ? "" : kPwdVoice);
1294 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1295 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001296
1297 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1299
deadbeef3f7219b2015-12-28 15:17:14 -08001300 JsepSessionDescription jdesc_no_candidates(kDummyString);
1301 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1302 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 return false;
1304 }
deadbeef9d3584c2016-02-16 17:54:10 -08001305 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 EXPECT_EQ(new_sdp, message);
1307 return true;
1308 }
1309
1310 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001311 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 new DataContentDescription());
1313 data_desc_ = data.get();
1314 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001315 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1316 cricket::kGoogleSctpDataCodecName, 0);
1317 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1318 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001320 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1321 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 }
1323
1324 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001325 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 new DataContentDescription());
1327 data_desc_ = data.get();
1328
1329 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1330 StreamParams data_stream;
1331 data_stream.id = kDataChannelMsid;
1332 data_stream.cname = kDataChannelCname;
1333 data_stream.sync_label = kDataChannelLabel;
1334 data_stream.ssrcs.push_back(kDataChannelSsrc);
1335 data_desc_->AddStream(data_stream);
1336 data_desc_->AddCrypto(CryptoParams(
1337 1, "AES_CM_128_HMAC_SHA1_80",
1338 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1339 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1340 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001341 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1342 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 }
1344
1345 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1346 std::string new_sdp = kSdpFullString;
1347 ReplaceDirection(direction, &new_sdp);
1348 JsepSessionDescription new_jdesc(kDummyString);
1349
1350 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1351
1352 audio_desc_->set_direction(direction);
1353 video_desc_->set_direction(direction);
1354 if (!jdesc_.Initialize(desc_.Copy(),
1355 jdesc_.session_id(),
1356 jdesc_.session_version())) {
1357 return false;
1358 }
1359 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1360 return true;
1361 }
1362
1363 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001364 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1366 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001368
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 audio_desc_ = static_cast<AudioContentDescription*>(
1370 audio_desc_->Copy());
1371 video_desc_ = static_cast<VideoContentDescription*>(
1372 video_desc_->Copy());
1373 desc_.RemoveContentByName(kAudioContentName);
1374 desc_.RemoveContentByName(kVideoContentName);
1375 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1376 audio_desc_);
1377 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1378 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001379 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1380 audio_rejected ? "" : kPwdVoice);
1381 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1382 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001383 JsepSessionDescription jdesc_no_candidates(kDummyString);
1384 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1385 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 return false;
1387 }
deadbeef3f7219b2015-12-28 15:17:14 -08001388 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 return true;
1390 }
1391
1392 void TestDeserializeExtmap(bool session_level, bool media_level) {
1393 AddExtmap();
1394 JsepSessionDescription new_jdesc("dummy");
1395 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1396 jdesc_.session_id(),
1397 jdesc_.session_version()));
1398 JsepSessionDescription jdesc_with_extmap("dummy");
1399 std::string sdp_with_extmap = kSdpString;
1400 if (session_level) {
1401 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1402 &sdp_with_extmap);
1403 }
1404 if (media_level) {
1405 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1406 &sdp_with_extmap);
1407 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1408 &sdp_with_extmap);
1409 }
1410 // The extmap can't be present at the same time in both session level and
1411 // media level.
1412 if (session_level && media_level) {
1413 SdpParseError error;
1414 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1415 &jdesc_with_extmap, &error));
1416 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1417 } else {
1418 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1419 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1420 }
1421 }
1422
1423 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1424 const std::string& name, int expected_value) {
1425 cricket::CodecParameterMap::const_iterator found = params.find(name);
1426 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001427 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 }
1429
1430 void TestDeserializeCodecParams(const CodecParams& params,
1431 JsepSessionDescription* jdesc_output) {
1432 std::string sdp =
1433 "v=0\r\n"
1434 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1435 "s=-\r\n"
1436 "t=0 0\r\n"
1437 // Include semantics for WebRTC Media Streams since it is supported by
1438 // this parser, and will be added to the SDP when serializing a session
1439 // description.
1440 "a=msid-semantic: WMS\r\n"
1441 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001442 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 // Pltype 111 listed before 103 and 104 in the map.
1444 "a=rtpmap:111 opus/48000/2\r\n"
1445 // Pltype 103 listed before 104.
1446 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001447 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001448 "a=fmtp:111 0-15,66,70\r\n"
1449 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001451 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001452 << "; sprop-stereo=" << params.sprop_stereo
1453 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001454 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 << "a=ptime:" << params.ptime << "\r\n"
1456 << "a=maxptime:" << params.max_ptime << "\r\n";
1457 sdp += os.str();
1458
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001459 os.clear();
1460 os.str("");
1461 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001462 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001463 << "a=rtpmap:99 VP8/90000\r\n"
1464 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001465 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001466 sdp += os.str();
1467
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 // Deserialize
1469 SdpParseError error;
1470 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1471
1472 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1473 ASSERT_TRUE(ac != NULL);
1474 const AudioContentDescription* acd =
1475 static_cast<const AudioContentDescription*>(ac->description);
1476 ASSERT_FALSE(acd->codecs().empty());
1477 cricket::AudioCodec opus = acd->codecs()[0];
1478 EXPECT_EQ("opus", opus.name);
1479 EXPECT_EQ(111, opus.id);
1480 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1481 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1482 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1483 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001484 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1485 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1487 cricket::AudioCodec codec = acd->codecs()[i];
1488 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1489 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1490 if (codec.name == "ISAC") {
1491 if (codec.clockrate == 16000) {
1492 EXPECT_EQ(32000, codec.bitrate);
1493 } else {
1494 EXPECT_EQ(56000, codec.bitrate);
1495 }
1496 }
1497 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001498
1499 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1500 ASSERT_TRUE(vc != NULL);
1501 const VideoContentDescription* vcd =
1502 static_cast<const VideoContentDescription*>(vc->description);
1503 ASSERT_FALSE(vcd->codecs().empty());
1504 cricket::VideoCodec vp8 = vcd->codecs()[0];
1505 EXPECT_EQ("VP8", vp8.name);
1506 EXPECT_EQ(99, vp8.id);
1507 cricket::VideoCodec rtx = vcd->codecs()[1];
1508 EXPECT_EQ("RTX", rtx.name);
1509 EXPECT_EQ(95, rtx.id);
1510 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 }
1512
1513 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1514 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001515 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 "v=0\r\n"
1517 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1518 "s=-\r\n"
1519 "t=0 0\r\n"
1520 // Include semantics for WebRTC Media Streams since it is supported by
1521 // this parser, and will be added to the SDP when serializing a session
1522 // description.
1523 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001524 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001525 "a=rtpmap:111 opus/48000/2\r\n";
1526 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 "m=video 3457 RTP/SAVPF 101\r\n"
1528 "a=rtpmap:101 VP8/90000\r\n"
1529 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001530 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001531 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001533 os << sdp_session_and_audio;
1534 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1535 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001537 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 // Deserialize
1539 SdpParseError error;
1540 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1541 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1542 ASSERT_TRUE(ac != NULL);
1543 const AudioContentDescription* acd =
1544 static_cast<const AudioContentDescription*>(ac->description);
1545 ASSERT_FALSE(acd->codecs().empty());
1546 cricket::AudioCodec opus = acd->codecs()[0];
1547 EXPECT_EQ(111, opus.id);
1548 EXPECT_TRUE(opus.HasFeedbackParam(
1549 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1550 cricket::kParamValueEmpty)));
1551
1552 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1553 ASSERT_TRUE(vc != NULL);
1554 const VideoContentDescription* vcd =
1555 static_cast<const VideoContentDescription*>(vc->description);
1556 ASSERT_FALSE(vcd->codecs().empty());
1557 cricket::VideoCodec vp8 = vcd->codecs()[0];
1558 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1559 vp8.name.c_str());
1560 EXPECT_EQ(101, vp8.id);
1561 EXPECT_TRUE(vp8.HasFeedbackParam(
1562 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1563 cricket::kParamValueEmpty)));
1564 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001565 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1566 cricket::kRtcpFbNackParamPli)));
1567 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1569 cricket::kParamValueEmpty)));
1570 EXPECT_TRUE(vp8.HasFeedbackParam(
1571 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1572 cricket::kRtcpFbCcmParamFir)));
1573 }
1574
1575 // Two SDP messages can mean the same thing but be different strings, e.g.
1576 // some of the lines can be serialized in different order.
1577 // However, a deserialized description can be compared field by field and has
1578 // no order. If deserializer has already been tested, serializing then
1579 // deserializing and comparing JsepSessionDescription will test
1580 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001581 void TestSerialize(const JsepSessionDescription& jdesc,
1582 bool unified_plan_sdp) {
1583 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 JsepSessionDescription jdesc_output_des(kDummyString);
1585 SdpParseError error;
1586 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1587 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1588 }
1589
1590 protected:
1591 SessionDescription desc_;
1592 AudioContentDescription* audio_desc_;
1593 VideoContentDescription* video_desc_;
1594 DataContentDescription* data_desc_;
1595 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001596 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 JsepSessionDescription jdesc_;
1598};
1599
1600void TestMismatch(const std::string& string1, const std::string& string2) {
1601 int position = 0;
1602 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1603 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001604 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 break;
1606 }
1607 }
1608 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1609 << " character\n"
1610 << " 1: " << string1.substr(position, 20) << "\n"
1611 << " 2: " << string2.substr(position, 20) << "\n";
1612}
1613
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1615 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001616 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 TestMismatch(std::string(kSdpFullString), message);
1618}
1619
1620TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1621 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001622 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623}
1624
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001625// This tests serialization of SDP with only IPv6 candidates and verifies that
1626// IPv6 is used as default address in c line according to preference.
1627TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1628 // Only test 1 m line.
1629 desc_.RemoveContentByName("video_content_name");
1630 // Stun has a high preference than local host.
1631 cricket::Candidate candidate1(
1632 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1633 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1634 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1635 cricket::Candidate candidate2(
1636 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1637 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1638 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1639 JsepSessionDescription jdesc(kDummyString);
1640 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1641
1642 // Only add the candidates to audio m line.
1643 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1644 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1645 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1646 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001647 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001648
1649 // Audio line should have a c line like this one.
1650 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1651 // Shouldn't have a IP4 c line.
1652 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1653}
1654
1655// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1656// verifies that IPv4 is used as default address in c line even if the
1657// preference of IPv4 is lower.
1658TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1659 // Only test 1 m line.
1660 desc_.RemoveContentByName("video_content_name");
1661 cricket::Candidate candidate_v4(
1662 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1663 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1664 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1665 cricket::Candidate candidate_v6(
1666 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1667 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1668 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1669 JsepSessionDescription jdesc(kDummyString);
1670 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1671
1672 // Only add the candidates to audio m line.
1673 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1674 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1675 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1676 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
deadbeef9d3584c2016-02-16 17:54:10 -08001677 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001678
1679 // Audio line should have a c line like this one.
1680 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1681 // Shouldn't have a IP6 c line.
1682 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1683}
1684
1685// This tests serialization of SDP with both UDP and TCP candidates and
1686// verifies that UDP is used as default address in c line even if the
1687// preference of UDP is lower.
1688TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1689 // Only test 1 m line.
1690 desc_.RemoveContentByName("video_content_name");
1691 // Stun has a high preference than local host.
1692 cricket::Candidate candidate1(
1693 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1694 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1695 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1696 cricket::Candidate candidate2(
1697 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1698 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1699 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1700 kCandidateFoundation1);
1701 JsepSessionDescription jdesc(kDummyString);
1702 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1703
1704 // Only add the candidates to audio m line.
1705 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1706 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1707 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1708 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001709 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001710
1711 // Audio line should have a c line like this one.
1712 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1713 std::string::npos);
1714 // Shouldn't have a IP4 c line.
1715 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1716}
1717
1718// This tests serialization of SDP with only TCP candidates and verifies that
1719// null IPv4 is used as default address in c line.
1720TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1721 // Only test 1 m line.
1722 desc_.RemoveContentByName("video_content_name");
1723 // Stun has a high preference than local host.
1724 cricket::Candidate candidate1(
1725 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1726 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1727 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1728 cricket::Candidate candidate2(
1729 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1730 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1731 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1732 JsepSessionDescription jdesc(kDummyString);
1733 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1734
1735 // Only add the candidates to audio m line.
1736 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1737 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1738 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1739 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001740 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001741
1742 // Audio line should have a c line like this one when no any default exists.
1743 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1744}
1745
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1747// the case in a DTLS offer.
1748TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1749 AddFingerprint();
1750 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1751 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1752 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001753 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
1755 std::string sdp_with_fingerprint = kSdpString;
1756 InjectAfter(kAttributeIcePwdVoice,
1757 kFingerprint, &sdp_with_fingerprint);
1758 InjectAfter(kAttributeIcePwdVideo,
1759 kFingerprint, &sdp_with_fingerprint);
1760
1761 EXPECT_EQ(sdp_with_fingerprint, message);
1762}
1763
1764// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1765// be the case in a DTLS answer.
1766TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1767 AddFingerprint();
1768 RemoveCryptos();
1769 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1770 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1771 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001772 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773
1774 std::string sdp_with_fingerprint = kSdpString;
1775 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1776 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1777 InjectAfter(kAttributeIcePwdVoice,
1778 kFingerprint, &sdp_with_fingerprint);
1779 InjectAfter(kAttributeIcePwdVideo,
1780 kFingerprint, &sdp_with_fingerprint);
1781
1782 EXPECT_EQ(sdp_with_fingerprint, message);
1783}
1784
1785TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1786 // JsepSessionDescription with desc but without candidates.
1787 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001788 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1789 kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001790 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 EXPECT_EQ(std::string(kSdpString), message);
1792}
1793
1794TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1795 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1796 group.AddContentName(kAudioContentName);
1797 group.AddContentName(kVideoContentName);
1798 desc_.AddGroup(group);
1799 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1800 jdesc_.session_id(),
1801 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001802 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 std::string sdp_with_bundle = kSdpFullString;
1804 InjectAfter(kSessionTime,
1805 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1806 &sdp_with_bundle);
1807 EXPECT_EQ(sdp_with_bundle, message);
1808}
1809
1810TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1811 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1812 GetFirstVideoContent(&desc_)->description);
1813 vcd->set_bandwidth(100 * 1000);
1814 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1815 GetFirstAudioContent(&desc_)->description);
1816 acd->set_bandwidth(50 * 1000);
1817 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1818 jdesc_.session_id(),
1819 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001820 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001822 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 "b=AS:100\r\n",
1824 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001825 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 "b=AS:50\r\n",
1827 &sdp_with_bandwidth);
1828 EXPECT_EQ(sdp_with_bandwidth, message);
1829}
1830
1831TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1832 std::vector<std::string> transport_options;
1833 transport_options.push_back(kIceOption1);
1834 transport_options.push_back(kIceOption3);
1835 AddIceOptions(kAudioContentName, transport_options);
1836 transport_options.clear();
1837 transport_options.push_back(kIceOption2);
1838 transport_options.push_back(kIceOption3);
1839 AddIceOptions(kVideoContentName, transport_options);
1840 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1841 jdesc_.session_id(),
1842 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001843 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 std::string sdp_with_ice_options = kSdpFullString;
1845 InjectAfter(kAttributeIcePwdVoice,
1846 "a=ice-options:iceoption1 iceoption3\r\n",
1847 &sdp_with_ice_options);
1848 InjectAfter(kAttributeIcePwdVideo,
1849 "a=ice-options:iceoption2 iceoption3\r\n",
1850 &sdp_with_ice_options);
1851 EXPECT_EQ(sdp_with_ice_options, message);
1852}
1853
1854TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1855 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1856}
1857
1858TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1859 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1860}
1861
1862TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1863 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1864}
1865
1866TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1867 EXPECT_TRUE(TestSerializeRejected(true, false));
1868}
1869
1870TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1871 EXPECT_TRUE(TestSerializeRejected(false, true));
1872}
1873
1874TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1875 EXPECT_TRUE(TestSerializeRejected(true, true));
1876}
1877
1878TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1879 AddRtpDataChannel();
1880 JsepSessionDescription jsep_desc(kDummyString);
1881
1882 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001883 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884
1885 std::string expected_sdp = kSdpString;
1886 expected_sdp.append(kSdpRtpDataChannelString);
1887 EXPECT_EQ(expected_sdp, message);
1888}
1889
1890TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1891 AddSctpDataChannel();
1892 JsepSessionDescription jsep_desc(kDummyString);
1893
1894 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001895 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896
1897 std::string expected_sdp = kSdpString;
1898 expected_sdp.append(kSdpSctpDataChannelString);
1899 EXPECT_EQ(message, expected_sdp);
1900}
1901
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001902TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1903 AddSctpDataChannel();
1904 JsepSessionDescription jsep_desc(kDummyString);
1905
1906 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1907 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1908 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1909
1910 const int kNewPort = 1234;
1911 cricket::DataCodec codec(
1912 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1913 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1914 dcdesc->AddOrReplaceCodec(codec);
1915
deadbeef9d3584c2016-02-16 17:54:10 -08001916 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001917
1918 std::string expected_sdp = kSdpString;
1919 expected_sdp.append(kSdpSctpDataChannelString);
1920
1921 char default_portstr[16];
1922 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001923 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001924 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001925 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1926 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001927 new_portstr, strlen(new_portstr),
1928 &expected_sdp);
1929
1930 EXPECT_EQ(expected_sdp, message);
1931}
1932
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1934 AddRtpDataChannel();
1935 data_desc_->set_bandwidth(100*1000);
1936 JsepSessionDescription jsep_desc(kDummyString);
1937
1938 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001939 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001940
1941 std::string expected_sdp = kSdpString;
1942 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07001943 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001944 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 +00001945 "b=AS:100\r\n",
1946 &expected_sdp);
1947 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001948}
1949
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1951 AddExtmap();
1952 JsepSessionDescription desc_with_extmap("dummy");
1953 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1954 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001955 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956
1957 std::string sdp_with_extmap = kSdpString;
1958 InjectAfter("a=mid:audio_content_name\r\n",
1959 kExtmap, &sdp_with_extmap);
1960 InjectAfter("a=mid:video_content_name\r\n",
1961 kExtmap, &sdp_with_extmap);
1962
1963 EXPECT_EQ(sdp_with_extmap, message);
1964}
1965
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966TEST_F(WebRtcSdpTest, SerializeCandidates) {
1967 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001968 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08001969
1970 Candidate candidate_with_ufrag(candidates_.front());
1971 candidate_with_ufrag.set_username("ABC");
1972 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
1973 candidate_with_ufrag));
1974 message = webrtc::SdpSerializeCandidate(*jcandidate_);
1975 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976}
1977
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001978// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1979// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001980TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001981 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001982 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1983 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1984 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001985 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1986 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1987 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1988
1989 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1990 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1991}
1992
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1994 JsepSessionDescription jdesc(kDummyString);
1995 // Deserialize
1996 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1997 // Verify
1998 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1999}
2000
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002001TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2002 JsepSessionDescription jdesc(kDummyString);
2003 const char kSdpWithoutMline[] =
2004 "v=0\r\n"
2005 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2006 "s=-\r\n"
2007 "t=0 0\r\n"
2008 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2009 // Deserialize
2010 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2011 EXPECT_EQ(0u, jdesc.description()->contents().size());
2012}
2013
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2015 JsepSessionDescription jdesc(kDummyString);
2016 std::string sdp_without_carriage_return = kSdpFullString;
2017 Replace("\r\n", "\n", &sdp_without_carriage_return);
2018 // Deserialize
2019 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2020 // Verify
2021 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2022}
2023
2024TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2025 // SessionDescription with desc but without candidates.
2026 JsepSessionDescription jdesc_no_candidates(kDummyString);
2027 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2028 kSessionId, kSessionVersion));
2029 JsepSessionDescription new_jdesc(kDummyString);
2030 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2031 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2032}
2033
2034TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2035 static const char kSdpNoRtpmapString[] =
2036 "v=0\r\n"
2037 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2038 "s=-\r\n"
2039 "t=0 0\r\n"
2040 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2041 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002042 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 // The rtpmap line for static payload codec is optional.
2044 "a=rtpmap:18 G729/16000\r\n"
2045 "a=rtpmap:103 ISAC/16000\r\n";
2046
2047 JsepSessionDescription jdesc(kDummyString);
2048 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2049 cricket::AudioContentDescription* audio =
2050 static_cast<AudioContentDescription*>(
2051 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2052 AudioCodecs ref_codecs;
2053 // The codecs in the AudioContentDescription will be sorted by preference.
2054 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
2055 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
2056 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
2057 EXPECT_EQ(ref_codecs, audio->codecs());
2058}
2059
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002060TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2061 static const char kSdpNoRtpmapString[] =
2062 "v=0\r\n"
2063 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2064 "s=-\r\n"
2065 "t=0 0\r\n"
2066 "m=audio 49232 RTP/AVP 18 103\r\n"
2067 "a=fmtp:18 annexb=yes\r\n"
2068 "a=rtpmap:103 ISAC/16000\r\n";
2069
2070 JsepSessionDescription jdesc(kDummyString);
2071 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2072 cricket::AudioContentDescription* audio =
2073 static_cast<AudioContentDescription*>(
2074 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2075
2076 cricket::AudioCodec g729 = audio->codecs()[0];
2077 EXPECT_EQ("G729", g729.name);
2078 EXPECT_EQ(8000, g729.clockrate);
2079 EXPECT_EQ(18, g729.id);
2080 cricket::CodecParameterMap::iterator found =
2081 g729.params.find("annexb");
2082 ASSERT_TRUE(found != g729.params.end());
2083 EXPECT_EQ(found->second, "yes");
2084
2085 cricket::AudioCodec isac = audio->codecs()[1];
2086 EXPECT_EQ("ISAC", isac.name);
2087 EXPECT_EQ(103, isac.id);
2088 EXPECT_EQ(16000, isac.clockrate);
2089}
2090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091// Ensure that we can deserialize SDP with a=fingerprint properly.
2092TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2093 // Add a DTLS a=fingerprint attribute to our session description.
2094 AddFingerprint();
2095 JsepSessionDescription new_jdesc(kDummyString);
2096 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2097 jdesc_.session_id(),
2098 jdesc_.session_version()));
2099
2100 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2101 std::string sdp_with_fingerprint = kSdpString;
2102 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2103 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2104 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2105 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2106}
2107
2108TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2109 JsepSessionDescription jdesc_with_bundle(kDummyString);
2110 std::string sdp_with_bundle = kSdpFullString;
2111 InjectAfter(kSessionTime,
2112 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2113 &sdp_with_bundle);
2114 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2115 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2116 group.AddContentName(kAudioContentName);
2117 group.AddContentName(kVideoContentName);
2118 desc_.AddGroup(group);
2119 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2120 jdesc_.session_id(),
2121 jdesc_.session_version()));
2122 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2123}
2124
2125TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2126 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2127 std::string sdp_with_bandwidth = kSdpFullString;
2128 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2129 "b=AS:100\r\n",
2130 &sdp_with_bandwidth);
2131 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2132 "b=AS:50\r\n",
2133 &sdp_with_bandwidth);
2134 EXPECT_TRUE(
2135 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2136 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2137 GetFirstVideoContent(&desc_)->description);
2138 vcd->set_bandwidth(100 * 1000);
2139 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2140 GetFirstAudioContent(&desc_)->description);
2141 acd->set_bandwidth(50 * 1000);
2142 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2143 jdesc_.session_id(),
2144 jdesc_.session_version()));
2145 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2146}
2147
2148TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2149 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2150 std::string sdp_with_ice_options = kSdpFullString;
2151 InjectAfter(kSessionTime,
2152 "a=ice-options:iceoption3\r\n",
2153 &sdp_with_ice_options);
2154 InjectAfter(kAttributeIcePwdVoice,
2155 "a=ice-options:iceoption1\r\n",
2156 &sdp_with_ice_options);
2157 InjectAfter(kAttributeIcePwdVideo,
2158 "a=ice-options:iceoption2\r\n",
2159 &sdp_with_ice_options);
2160 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2161 std::vector<std::string> transport_options;
2162 transport_options.push_back(kIceOption3);
2163 transport_options.push_back(kIceOption1);
2164 AddIceOptions(kAudioContentName, transport_options);
2165 transport_options.clear();
2166 transport_options.push_back(kIceOption3);
2167 transport_options.push_back(kIceOption2);
2168 AddIceOptions(kVideoContentName, transport_options);
2169 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2170 jdesc_.session_id(),
2171 jdesc_.session_version()));
2172 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2173}
2174
2175TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2176 // Remove the original ice-ufrag and ice-pwd
2177 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2178 std::string sdp_with_ufrag_pwd = kSdpFullString;
2179 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2180 // Add session level ufrag and pwd
2181 InjectAfter(kSessionTime,
2182 "a=ice-pwd:session+level+icepwd\r\n"
2183 "a=ice-ufrag:session+level+iceufrag\r\n",
2184 &sdp_with_ufrag_pwd);
2185 // Add media level ufrag and pwd for audio
2186 InjectAfter("a=mid:audio_content_name\r\n",
2187 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2188 &sdp_with_ufrag_pwd);
2189 // Update the candidate ufrag and pwd to the expected ones.
2190 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2191 "media+level+iceufrag", "media+level+icepwd"));
2192 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2193 "session+level+iceufrag", "session+level+icepwd"));
2194 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2195 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2196}
2197
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2199 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2200}
2201
2202TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2203 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2204}
2205
2206TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2207 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2208}
2209
2210TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2211 EXPECT_TRUE(TestDeserializeRejected(true, false));
2212}
2213
2214TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2215 EXPECT_TRUE(TestDeserializeRejected(false, true));
2216}
2217
2218TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2219 EXPECT_TRUE(TestDeserializeRejected(true, true));
2220}
2221
2222// Tests that we can still handle the sdp uses mslabel and label instead of
2223// msid for backward compatibility.
2224TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002225 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 JsepSessionDescription jdesc(kDummyString);
2227 std::string sdp_without_msid = kSdpFullString;
2228 Replace("msid", "xmsid", &sdp_without_msid);
2229 // Deserialize
2230 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2231 // Verify
2232 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2233}
2234
2235TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2236 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2237
2238 std::string sdp = kSdpOneCandidate;
2239 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2240 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2241 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2242 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2243
2244 // Candidate line without generation extension.
2245 sdp = kSdpOneCandidate;
2246 Replace(" generation 2", "", &sdp);
2247 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2248 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2249 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2250 Candidate expected = jcandidate_->candidate();
2251 expected.set_generation(0);
2252 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2253
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002254 sdp = kSdpTcpActiveCandidate;
2255 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2256 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002257 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002258 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2259 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2260 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002261 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2262 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2263 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2264 jcandidate_template->candidate()));
2265 sdp = kSdpTcpPassiveCandidate;
2266 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2267 sdp = kSdpTcpSOCandidate;
2268 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269}
2270
2271// This test verifies the deserialization of candidate-attribute
2272// as per RFC 5245. Candiate-attribute will be of the format
2273// candidate:<blah>. This format will be used when candidates
2274// are trickled.
2275TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2276 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2277
2278 std::string candidate_attribute = kRawCandidate;
2279 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2280 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2281 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2282 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2283 EXPECT_EQ(2u, jcandidate.candidate().generation());
2284
2285 // Candidate line without generation extension.
2286 candidate_attribute = kRawCandidate;
2287 Replace(" generation 2", "", &candidate_attribute);
2288 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2289 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2290 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2291 Candidate expected = jcandidate_->candidate();
2292 expected.set_generation(0);
2293 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2294
2295 // Candidate line without candidate:
2296 candidate_attribute = kRawCandidate;
2297 Replace("candidate:", "", &candidate_attribute);
2298 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2299
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002300 // Candidate line with IPV6 address.
2301 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2302}
2303
2304// This test verifies that the deserialization of an invalid candidate string
2305// fails.
2306TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2307 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2308
2309 std::string candidate_attribute = kRawCandidate;
2310 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002312
2313 candidate_attribute = kSdpOneCandidate;
2314 candidate_attribute.replace(0, 1, "x");
2315 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2316
2317 candidate_attribute = kRawCandidate;
2318 candidate_attribute.append("\r\n");
2319 candidate_attribute.append(kRawCandidate);
2320 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2321
2322 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323}
2324
2325TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2326 AddRtpDataChannel();
2327 JsepSessionDescription jdesc(kDummyString);
2328 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2329
2330 std::string sdp_with_data = kSdpString;
2331 sdp_with_data.append(kSdpRtpDataChannelString);
2332 JsepSessionDescription jdesc_output(kDummyString);
2333
2334 // Deserialize
2335 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2336 // Verify
2337 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2338}
2339
2340TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2341 AddSctpDataChannel();
2342 JsepSessionDescription jdesc(kDummyString);
2343 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2344
2345 std::string sdp_with_data = kSdpString;
2346 sdp_with_data.append(kSdpSctpDataChannelString);
2347 JsepSessionDescription jdesc_output(kDummyString);
2348
lally@webrtc.org36300852015-02-24 20:19:35 +00002349 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2350 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2351 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2352
2353 // Verify with UDP/DTLS/SCTP.
2354 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2355 strlen(kDtlsSctp), kUdpDtlsSctp);
2356 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2357 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2358
2359 // Verify with TCP/DTLS/SCTP.
2360 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2361 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2363 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2364}
2365
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002366TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2367 AddSctpDataChannel();
2368 JsepSessionDescription jdesc(kDummyString);
2369 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2370
2371 std::string sdp_with_data = kSdpString;
2372 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2373 JsepSessionDescription jdesc_output(kDummyString);
2374
lally@webrtc.org36300852015-02-24 20:19:35 +00002375 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002376 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2377 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002378
lally@webrtc.org36300852015-02-24 20:19:35 +00002379 // Verify with UDP/DTLS/SCTP.
2380 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2381 strlen(kDtlsSctp), kUdpDtlsSctp);
2382 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2383 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002384
lally@webrtc.org36300852015-02-24 20:19:35 +00002385 // Verify with TCP/DTLS/SCTP.
2386 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2387 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002388 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2389 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2390}
2391
lally69f57602015-10-08 10:15:04 -07002392TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2393 AddSctpDataChannel();
2394 JsepSessionDescription jdesc(kDummyString);
2395 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2396
2397 std::string sdp_with_data = kSdpString;
2398 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2399 JsepSessionDescription jdesc_output(kDummyString);
2400
2401 // Verify with DTLS/SCTP.
2402 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2403 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2404
2405 // Verify with UDP/DTLS/SCTP.
2406 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2407 strlen(kDtlsSctp), kUdpDtlsSctp);
2408 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2409 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2410
2411 // Verify with TCP/DTLS/SCTP.
2412 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2413 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2414 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2415 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2416}
2417
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002418// Test to check the behaviour if sctp-port is specified
2419// on the m= line and in a=sctp-port.
2420TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2421 AddSctpDataChannel();
2422 JsepSessionDescription jdesc(kDummyString);
2423 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2424
2425 std::string sdp_with_data = kSdpString;
2426 // Append m= attributes
2427 sdp_with_data.append(kSdpSctpDataChannelString);
2428 // Append a=sctp-port attribute
2429 sdp_with_data.append("a=sctp-port 5000\r\n");
2430 JsepSessionDescription jdesc_output(kDummyString);
2431
2432 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2433}
2434
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002435// For crbug/344475.
2436TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2437 std::string sdp_with_data = kSdpString;
2438 sdp_with_data.append(kSdpSctpDataChannelString);
2439 // Remove the "\n" at the end.
2440 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2441 JsepSessionDescription jdesc_output(kDummyString);
2442
2443 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2444 // No crash is a pass.
2445}
2446
wu@webrtc.org78187522013-10-07 23:32:02 +00002447TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2448 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002449 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002450 char default_portstr[16];
2451 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002452 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002453 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002454 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002455 kUnusualSctpPort);
2456
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002457 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002458 JsepSessionDescription jdesc(kDummyString);
2459 // take our pre-built session description and change the SCTP port.
2460 cricket::SessionDescription* mutant = desc_.Copy();
2461 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2462 mutant->GetContentDescriptionByName(kDataContentName));
2463 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002464 EXPECT_EQ(1U, codecs.size());
2465 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002466 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002467 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002468
2469 // note: mutant's owned by jdesc now.
2470 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2471 mutant = NULL;
2472
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002473 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002474 std::string sdp_with_data = kSdpString;
2475 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002476 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002477 unusual_portstr, strlen(unusual_portstr),
2478 &sdp_with_data);
2479 JsepSessionDescription jdesc_output(kDummyString);
2480
2481 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2482 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002483
2484 // We need to test the deserialized JsepSessionDescription from
2485 // kSdpSctpDataChannelStringWithSctpPort for
2486 // draft-ietf-mmusic-sctp-sdp-07
2487 // a=sctp-port
2488 sdp_with_data = kSdpString;
2489 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2490 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2491 unusual_portstr, strlen(unusual_portstr),
2492 &sdp_with_data);
2493
2494 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2495 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002496}
2497
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002498TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002499 // We want to test that deserializing data content limits bandwidth
2500 // settings (it should never be greater than the default).
2501 // This should prevent someone from using unlimited data bandwidth through
2502 // JS and "breaking the Internet".
2503 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002504 std::string sdp_with_bandwidth = kSdpString;
2505 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2506 InjectAfter("a=mid:data_content_name\r\n",
2507 "b=AS:100\r\n",
2508 &sdp_with_bandwidth);
2509 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2510
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002511 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2512}
2513
2514TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2515 AddSctpDataChannel();
2516 JsepSessionDescription jdesc(kDummyString);
2517 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2518 GetFirstDataContent(&desc_)->description);
2519 dcd->set_bandwidth(100 * 1000);
2520 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2521
2522 std::string sdp_with_bandwidth = kSdpString;
2523 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2524 InjectAfter("a=mid:data_content_name\r\n",
2525 "b=AS:100\r\n",
2526 &sdp_with_bandwidth);
2527 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2528
2529 // SCTP has congestion control, so we shouldn't limit the bandwidth
2530 // as we do for RTP.
2531 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002532 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2533}
2534
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2536 TestDeserializeExtmap(true, false);
2537}
2538
2539TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2540 TestDeserializeExtmap(false, true);
2541}
2542
2543TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2544 TestDeserializeExtmap(true, true);
2545}
2546
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002547TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2548 JsepSessionDescription jdesc(kDummyString);
2549 std::string sdp = kSdpFullString;
2550 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2551 // Deserialize
2552 SdpParseError error;
2553 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002554 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002555 EXPECT_EQ(lastline, error.line);
2556 EXPECT_EQ("Invalid SDP line.", error.description);
2557}
2558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2560 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2561 std::string new_sdp = kSdpOneCandidate;
2562 Replace("udp", "unsupported_transport", &new_sdp);
2563 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2564 new_sdp = kSdpOneCandidate;
2565 Replace("udp", "uDP", &new_sdp);
2566 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2567 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2568 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2569 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2570}
2571
honghaiza54a0802015-12-16 18:37:23 -08002572TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002574 EXPECT_TRUE(
2575 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2577 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2578 Candidate ref_candidate = jcandidate_->candidate();
2579 ref_candidate.set_username("user_rtp");
2580 ref_candidate.set_password("password_rtp");
2581 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2582}
2583
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002584TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2585 JsepSessionDescription jdesc(kDummyString);
2586
2587 // Deserialize
2588 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2589
2590 // Verify
2591 cricket::AudioContentDescription* audio =
2592 static_cast<AudioContentDescription*>(
2593 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2594 EXPECT_TRUE(audio->conference_mode());
2595
2596 cricket::VideoContentDescription* video =
2597 static_cast<VideoContentDescription*>(
2598 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2599 EXPECT_TRUE(video->conference_mode());
2600}
2601
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2603 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002604 const char kSdpEmptyType[] = " =candidate";
2605 const char kSdpEqualAsPlus[] = "a+candidate";
2606 const char kSdpSpaceAfterEqual[] = "a= candidate";
2607 const char kSdpUpperType[] = "A=candidate";
2608 const char kSdpEmptyLine[] = "";
2609 const char kSdpMissingValue[] = "a=";
2610
2611 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 "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 +00002613 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 "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 +00002615 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 "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 +00002617 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002618 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002619 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620
2621 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002622 ExpectParseFailure("v=", kSdpDestroyer);
2623 ExpectParseFailure("o=", kSdpDestroyer);
2624 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002626 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627
2628 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002629 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2630 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631
2632 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002633 ExpectParseFailure("a=candidate", kSdpEmptyType);
2634 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2635 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2636 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637
2638 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2639 // because it's orthogonal to what we are replacing and hence
2640 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002641 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2642 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2643 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2644 ExpectParseFailure("a=sendrecv", kSdpMd5);
2645
2646 // Empty Line
2647 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2648 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002649}
2650
2651TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2652 // ssrc
2653 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002654 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002655 // crypto
2656 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2657 // rtpmap
2658 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2659 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2660 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2661 // candidate
2662 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2663 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2664 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2665 ExpectParseFailure("rport 2346", "rport badvalue");
2666 ExpectParseFailure("rport 2346 generation 2",
2667 "rport 2346 generation badvalue");
2668 // m line
2669 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2670 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2671
2672 // bandwidth
2673 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2674 "b=AS:badvalue\r\n",
2675 "b=AS:badvalue");
2676 // rtcp-fb
2677 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2678 "a=rtcp-fb:badvalue nack\r\n",
2679 "a=rtcp-fb:badvalue nack");
2680 // extmap
2681 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2682 "a=extmap:badvalue http://example.com\r\n",
2683 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684}
2685
2686TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2687 JsepSessionDescription jdesc_output(kDummyString);
2688
2689 const char kSdpWithReorderedPlTypesString[] =
2690 "v=0\r\n"
2691 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2692 "s=-\r\n"
2693 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002694 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2696 // in the map.
2697 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002698 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699
2700 // Deserialize
2701 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2702
2703 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2704 ASSERT_TRUE(ac != NULL);
2705 const AudioContentDescription* acd =
2706 static_cast<const AudioContentDescription*>(ac->description);
2707 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002708 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2709 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_EQ(104, acd->codecs()[0].id);
2711}
2712
2713TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2714 JsepSessionDescription jdesc_output(kDummyString);
2715 CodecParams params;
2716 params.max_ptime = 40;
2717 params.ptime = 30;
2718 params.min_ptime = 10;
2719 params.sprop_stereo = 1;
2720 params.stereo = 1;
2721 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002722 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002724 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725}
2726
2727TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2728 const bool kUseWildcard = false;
2729 JsepSessionDescription jdesc_output(kDummyString);
2730 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002731 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732}
2733
2734TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2735 const bool kUseWildcard = true;
2736 JsepSessionDescription jdesc_output(kDummyString);
2737 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002738 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739}
2740
2741TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2742 JsepSessionDescription jdesc_output(kDummyString);
2743
2744 const char kSdpWithFmtpString[] =
2745 "v=0\r\n"
2746 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2747 "s=-\r\n"
2748 "t=0 0\r\n"
2749 "m=video 3457 RTP/SAVPF 120\r\n"
2750 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002751 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2752
2753 // Deserialize
2754 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002755 EXPECT_TRUE(
2756 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002757
2758 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2759 ASSERT_TRUE(vc != NULL);
2760 const VideoContentDescription* vcd =
2761 static_cast<const VideoContentDescription*>(vc->description);
2762 ASSERT_FALSE(vcd->codecs().empty());
2763 cricket::VideoCodec vp8 = vcd->codecs()[0];
2764 EXPECT_EQ("VP8", vp8.name);
2765 EXPECT_EQ(120, vp8.id);
2766 cricket::CodecParameterMap::iterator found =
2767 vp8.params.find("x-google-min-bitrate");
2768 ASSERT_TRUE(found != vp8.params.end());
2769 EXPECT_EQ(found->second, "10");
2770 found = vp8.params.find("x-google-max-quantization");
2771 ASSERT_TRUE(found != vp8.params.end());
2772 EXPECT_EQ(found->second, "40");
2773}
2774
2775TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2776 JsepSessionDescription jdesc_output(kDummyString);
2777
2778 const char kSdpWithFmtpString[] =
2779 "v=0\r\n"
2780 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2781 "s=-\r\n"
2782 "t=0 0\r\n"
2783 "m=video 3457 RTP/SAVPF 120\r\n"
2784 "a=rtpmap:120 VP8/90000\r\n"
2785 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786
2787 // Deserialize
2788 SdpParseError error;
2789 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2790 &error));
2791
2792 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2793 ASSERT_TRUE(vc != NULL);
2794 const VideoContentDescription* vcd =
2795 static_cast<const VideoContentDescription*>(vc->description);
2796 ASSERT_FALSE(vcd->codecs().empty());
2797 cricket::VideoCodec vp8 = vcd->codecs()[0];
2798 EXPECT_EQ("VP8", vp8.name);
2799 EXPECT_EQ(120, vp8.id);
2800 cricket::CodecParameterMap::iterator found =
2801 vp8.params.find("x-google-min-bitrate");
2802 ASSERT_TRUE(found != vp8.params.end());
2803 EXPECT_EQ(found->second, "10");
2804 found = vp8.params.find("x-google-max-quantization");
2805 ASSERT_TRUE(found != vp8.params.end());
2806 EXPECT_EQ(found->second, "40");
2807}
2808
2809TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2810 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2811 GetFirstVideoContent(&desc_)->description);
2812
2813 cricket::VideoCodecs codecs = vcd->codecs();
2814 codecs[0].params["x-google-min-bitrate"] = "10";
2815 vcd->set_codecs(codecs);
2816
2817 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2818 jdesc_.session_id(),
2819 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08002820 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 std::string sdp_with_fmtp = kSdpFullString;
2822 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2823 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2824 &sdp_with_fmtp);
2825 EXPECT_EQ(sdp_with_fmtp, message);
2826}
2827
2828TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2829 JsepSessionDescription jdesc_with_icelite(kDummyString);
2830 std::string sdp_with_icelite = kSdpFullString;
2831 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2832 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2833 const cricket::TransportInfo* tinfo1 =
2834 desc->GetTransportInfoByName("audio_content_name");
2835 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2836 const cricket::TransportInfo* tinfo2 =
2837 desc->GetTransportInfoByName("video_content_name");
2838 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2839 InjectAfter(kSessionTime,
2840 "a=ice-lite\r\n",
2841 &sdp_with_icelite);
2842 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2843 desc = jdesc_with_icelite.description();
2844 const cricket::TransportInfo* atinfo =
2845 desc->GetTransportInfoByName("audio_content_name");
2846 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2847 const cricket::TransportInfo* vtinfo =
2848 desc->GetTransportInfoByName("video_content_name");
2849 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2850}
2851
2852// Verifies that the candidates in the input SDP are parsed and serialized
2853// correctly in the output SDP.
2854TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2855 std::string sdp_with_data = kSdpString;
2856 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2857 JsepSessionDescription jdesc_output(kDummyString);
2858
2859 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08002860 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002862
2863TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2864 AddFingerprint();
2865 TransportInfo audio_transport_info =
2866 *(desc_.GetTransportInfoByName(kAudioContentName));
2867 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2868 audio_transport_info.description.connection_role);
2869 audio_transport_info.description.connection_role =
2870 cricket::CONNECTIONROLE_ACTIVE;
2871
2872 TransportInfo video_transport_info =
2873 *(desc_.GetTransportInfoByName(kVideoContentName));
2874 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2875 video_transport_info.description.connection_role);
2876 video_transport_info.description.connection_role =
2877 cricket::CONNECTIONROLE_ACTIVE;
2878
2879 desc_.RemoveTransportInfoByName(kAudioContentName);
2880 desc_.RemoveTransportInfoByName(kVideoContentName);
2881
2882 desc_.AddTransportInfo(audio_transport_info);
2883 desc_.AddTransportInfo(video_transport_info);
2884
2885 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2886 jdesc_.session_id(),
2887 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08002888 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002889 std::string sdp_with_dtlssetup = kSdpFullString;
2890
2891 // Fingerprint attribute is necessary to add DTLS setup attribute.
2892 InjectAfter(kAttributeIcePwdVoice,
2893 kFingerprint, &sdp_with_dtlssetup);
2894 InjectAfter(kAttributeIcePwdVideo,
2895 kFingerprint, &sdp_with_dtlssetup);
2896 // Now adding |setup| attribute.
2897 InjectAfter(kFingerprint,
2898 "a=setup:active\r\n", &sdp_with_dtlssetup);
2899 EXPECT_EQ(sdp_with_dtlssetup, message);
2900}
2901
2902TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2903 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2904 std::string sdp_with_dtlssetup = kSdpFullString;
2905 InjectAfter(kSessionTime,
2906 "a=setup:actpass\r\n",
2907 &sdp_with_dtlssetup);
2908 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2909 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2910 const cricket::TransportInfo* atinfo =
2911 desc->GetTransportInfoByName("audio_content_name");
2912 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2913 atinfo->description.connection_role);
2914 const cricket::TransportInfo* vtinfo =
2915 desc->GetTransportInfoByName("video_content_name");
2916 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2917 vtinfo->description.connection_role);
2918}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002919
2920// Verifies that the order of the serialized m-lines follows the order of the
2921// ContentInfo in SessionDescription, and vise versa for deserialization.
2922TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2923 JsepSessionDescription jdesc(kDummyString);
2924 const std::string media_content_sdps[3] = {
2925 kSdpAudioString,
2926 kSdpVideoString,
2927 kSdpSctpDataChannelString
2928 };
2929 const cricket::MediaType media_types[3] = {
2930 cricket::MEDIA_TYPE_AUDIO,
2931 cricket::MEDIA_TYPE_VIDEO,
2932 cricket::MEDIA_TYPE_DATA
2933 };
2934
2935 // Verifies all 6 permutations.
2936 for (size_t i = 0; i < 6; ++i) {
2937 size_t media_content_in_sdp[3];
2938 // The index of the first media content.
2939 media_content_in_sdp[0] = i / 2;
2940 // The index of the second media content.
2941 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2942 // The index of the third media content.
2943 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2944
2945 std::string sdp_string = kSdpSessionString;
2946 for (size_t i = 0; i < 3; ++i)
2947 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2948
2949 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2950 cricket::SessionDescription* desc = jdesc.description();
2951 EXPECT_EQ(3u, desc->contents().size());
2952
2953 for (size_t i = 0; i < 3; ++i) {
2954 const cricket::MediaContentDescription* mdesc =
2955 static_cast<const cricket::MediaContentDescription*>(
2956 desc->contents()[i].description);
2957 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2958 }
2959
deadbeef9d3584c2016-02-16 17:54:10 -08002960 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002961 EXPECT_EQ(sdp_string, serialized_sdp);
2962 }
2963}
deadbeef9d3584c2016-02-16 17:54:10 -08002964
2965TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
2966 MakePlanBDescription();
2967
2968 JsepSessionDescription deserialized_description(kDummyString);
2969 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
2970
2971 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
2972}
2973
2974TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
2975 MakePlanBDescription();
2976 TestSerialize(jdesc_, false);
2977}
2978
2979TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
2980 MakeUnifiedPlanDescription();
2981
2982 JsepSessionDescription deserialized_description(kDummyString);
2983 EXPECT_TRUE(
2984 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
2985
2986 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
2987}
2988
2989TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
2990 MakeUnifiedPlanDescription();
2991 TestSerialize(jdesc_, true);
2992}