blob: 31dcf6ecefdf2f1d311372e363b2438d524da4f0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2011 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
117struct CodecParams {
118 int max_ptime;
119 int ptime;
120 int min_ptime;
121 int sprop_stereo;
122 int stereo;
123 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000124 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125};
126
127// Reference sdp string
128static const char kSdpFullString[] =
129 "v=0\r\n"
130 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
134 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
135 "c=IN IP4 74.125.127.126\r\n"
136 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
137 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
146 "raddr 192.168.1.5 rport 2346 "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
149 "raddr 192.168.1.5 rport 2348 "
150 "generation 2\r\n"
151 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
152 "a=mid:audio_content_name\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
165 "a=ssrc:4 cname:stream_2_cname\r\n"
166 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
167 "a=ssrc:4 mslabel:local_stream_2\r\n"
168 "a=ssrc:4 label:audio_track_id_2\r\n"
169 "m=video 3457 RTP/SAVPF 120\r\n"
170 "c=IN IP4 74.125.224.39\r\n"
171 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
172 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
183 "generation 2\r\n"
184 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
185 "a=mid:video_content_name\r\n"
186 "a=sendrecv\r\n"
187 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
188 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
189 "a=rtpmap:120 VP8/90000\r\n"
190 "a=ssrc:2 cname:stream_1_cname\r\n"
191 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
192 "a=ssrc:2 mslabel:local_stream_1\r\n"
193 "a=ssrc:2 label:video_track_id_1\r\n"
194 "a=ssrc:3 cname:stream_1_cname\r\n"
195 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
196 "a=ssrc:3 mslabel:local_stream_1\r\n"
197 "a=ssrc:3 label:video_track_id_2\r\n"
198 "a=ssrc-group:FEC 5 6\r\n"
199 "a=ssrc:5 cname:stream_2_cname\r\n"
200 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
201 "a=ssrc:5 mslabel:local_stream_2\r\n"
202 "a=ssrc:5 label:video_track_id_3\r\n"
203 "a=ssrc:6 cname:stream_2_cname\r\n"
204 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:6 mslabel:local_stream_2\r\n"
206 "a=ssrc:6 label:video_track_id_3\r\n";
207
208// SDP reference string without the candidates.
209static const char kSdpString[] =
210 "v=0\r\n"
211 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
214 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000215 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
219 "a=mid:audio_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
223 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
224 "dummy_session_params\r\n"
225 "a=rtpmap:111 opus/48000/2\r\n"
226 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000227 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 "a=ssrc:1 cname:stream_1_cname\r\n"
229 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
230 "a=ssrc:1 mslabel:local_stream_1\r\n"
231 "a=ssrc:1 label:audio_track_id_1\r\n"
232 "a=ssrc:4 cname:stream_2_cname\r\n"
233 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
234 "a=ssrc:4 mslabel:local_stream_2\r\n"
235 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000236 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
240 "a=mid:video_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
244 "a=rtpmap:120 VP8/90000\r\n"
245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
250 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
251 "a=ssrc:3 mslabel:local_stream_1\r\n"
252 "a=ssrc:3 label:video_track_id_2\r\n"
253 "a=ssrc-group:FEC 5 6\r\n"
254 "a=ssrc:5 cname:stream_2_cname\r\n"
255 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
256 "a=ssrc:5 mslabel:local_stream_2\r\n"
257 "a=ssrc:5 label:video_track_id_3\r\n"
258 "a=ssrc:6 cname:stream_2_cname\r\n"
259 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:6 mslabel:local_stream_2\r\n"
261 "a=ssrc:6 label:video_track_id_3\r\n";
262
263static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000264 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
279static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000280 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000281 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000287// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000288static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000289 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
290 "a=max-message-size=100000\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000291 "a=sctp-port 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000292 "c=IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n";
296
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000297static const char kSdpSctpDataChannelStringWithOldProtocol[] =
298 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
299 "a=max-message-size=100000\r\n"
300 "a=sctp-port 5000\r\n"
301 "c=IN IP4 0.0.0.0\r\n"
302 "a=ice-ufrag:ufrag_data\r\n"
303 "a=ice-pwd:pwd_data\r\n"
304 "a=mid:data_content_name\r\n";
305
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306static const char kSdpSctpDataChannelWithCandidatesString[] =
307 "m=application 2345 DTLS/SCTP 5000\r\n"
308 "c=IN IP4 74.125.127.126\r\n"
309 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
310 "generation 2\r\n"
311 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
312 "generation 2\r\n"
313 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
314 "raddr 192.168.1.5 rport 2346 "
315 "generation 2\r\n"
316 "a=ice-ufrag:ufrag_data\r\n"
317 "a=ice-pwd:pwd_data\r\n"
318 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000319 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000321static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000322 "v=0\r\n"
323 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
324 "s=-\r\n"
325 "t=0 0\r\n"
326 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000327 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000328 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000329 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000330 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000331 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 "a=x-google-flag:conference\r\n";
333
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000334static const char kSdpSessionString[] =
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\r\n";
340
341static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000342 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000343 "c=IN IP4 0.0.0.0\r\n"
344 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000345 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
346 "a=mid:audio_content_name\r\n"
347 "a=sendrecv\r\n"
348 "a=rtpmap:111 opus/48000/2\r\n"
349 "a=ssrc:1 cname:stream_1_cname\r\n"
350 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
351 "a=ssrc:1 mslabel:local_stream\r\n"
352 "a=ssrc:1 label:audio_track_id_1\r\n";
353
354static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000355 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000356 "c=IN IP4 0.0.0.0\r\n"
357 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000358 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
359 "a=mid:video_content_name\r\n"
360 "a=sendrecv\r\n"
361 "a=rtpmap:120 VP8/90000\r\n"
362 "a=ssrc:2 cname:stream_1_cname\r\n"
363 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
364 "a=ssrc:2 mslabel:local_stream\r\n"
365 "a=ssrc:2 label:video_track_id_1\r\n";
366
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367
368// One candidate reference string as per W3c spec.
369// candidate:<blah> not a=candidate:<blah>CRLF
370static const char kRawCandidate[] =
371 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
372// One candidate reference string.
373static const char kSdpOneCandidate[] =
374 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
375 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000376
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000377static const char kSdpTcpActiveCandidate[] =
378 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
379 "tcptype active generation 2";
380static const char kSdpTcpPassiveCandidate[] =
381 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
382 "tcptype passive generation 2";
383static const char kSdpTcpSOCandidate[] =
384 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
385 "tcptype so generation 2";
386static const char kSdpTcpInvalidCandidate[] =
387 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
388 "tcptype invalid generation 2";
389
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000390// One candidate reference string with IPV6 address.
391static const char kRawIPV6Candidate[] =
392 "candidate:a0+B/1 1 udp 2130706432 "
393 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
395// One candidate reference string.
396static const char kSdpOneCandidateOldFormat[] =
397 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
398 " eth0 username user_rtp password password_rtp generation 2\r\n";
399
400// Session id and version
401static const char kSessionId[] = "18446744069414584320";
402static const char kSessionVersion[] = "18446462598732840960";
403
404// Ice options
405static const char kIceOption1[] = "iceoption1";
406static const char kIceOption2[] = "iceoption2";
407static const char kIceOption3[] = "iceoption3";
408
409// Content name
410static const char kAudioContentName[] = "audio_content_name";
411static const char kVideoContentName[] = "video_content_name";
412static const char kDataContentName[] = "data_content_name";
413
414// MediaStream 1
415static const char kStreamLabel1[] = "local_stream_1";
416static const char kStream1Cname[] = "stream_1_cname";
417static const char kAudioTrackId1[] = "audio_track_id_1";
418static const uint32 kAudioTrack1Ssrc = 1;
419static const char kVideoTrackId1[] = "video_track_id_1";
420static const uint32 kVideoTrack1Ssrc = 2;
421static const char kVideoTrackId2[] = "video_track_id_2";
422static const uint32 kVideoTrack2Ssrc = 3;
423
424// MediaStream 2
425static const char kStreamLabel2[] = "local_stream_2";
426static const char kStream2Cname[] = "stream_2_cname";
427static const char kAudioTrackId2[] = "audio_track_id_2";
428static const uint32 kAudioTrack2Ssrc = 4;
429static const char kVideoTrackId3[] = "video_track_id_3";
430static const uint32 kVideoTrack3Ssrc = 5;
431static const uint32 kVideoTrack4Ssrc = 6;
432
433// DataChannel
434static const char kDataChannelLabel[] = "data_channel";
435static const char kDataChannelMsid[] = "data_channeld0";
436static const char kDataChannelCname[] = "data_channel_cname";
437static const uint32 kDataChannelSsrc = 10;
438
439// Candidate
440static const char kDummyMid[] = "dummy_mid";
441static const int kDummyIndex = 123;
442
443// Misc
444static const char kDummyString[] = "dummy";
445
446// Helper functions
447
448static bool SdpDeserialize(const std::string& message,
449 JsepSessionDescription* jdesc) {
450 return webrtc::SdpDeserialize(message, jdesc, NULL);
451}
452
453static bool SdpDeserializeCandidate(const std::string& message,
454 JsepIceCandidate* candidate) {
455 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
456}
457
458// Add some extra |newlines| to the |message| after |line|.
459static void InjectAfter(const std::string& line,
460 const std::string& newlines,
461 std::string* message) {
462 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000463 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 tmp.c_str(), tmp.length(), message);
465}
466
467static void Replace(const std::string& line,
468 const std::string& newlines,
469 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000470 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 newlines.c_str(), newlines.length(), message);
472}
473
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000474// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
475// message.
476static void ExpectParseFailure(const std::string& bad_sdp,
477 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000480 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000482 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
483}
484
485// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
486static void ExpectParseFailure(const char* good_part, const char* bad_part) {
487 std::string bad_sdp = kSdpFullString;
488 Replace(good_part, bad_part, &bad_sdp);
489 ExpectParseFailure(bad_sdp, bad_part);
490}
491
492// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
493static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
494 const std::string& newlines,
495 const std::string& bad_part) {
496 std::string bad_sdp = kSdpFullString;
497 InjectAfter(injectpoint, newlines, &bad_sdp);
498 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499}
500
501static void ReplaceDirection(cricket::MediaContentDirection direction,
502 std::string* message) {
503 std::string new_direction;
504 switch (direction) {
505 case cricket::MD_INACTIVE:
506 new_direction = "a=inactive";
507 break;
508 case cricket::MD_SENDONLY:
509 new_direction = "a=sendonly";
510 break;
511 case cricket::MD_RECVONLY:
512 new_direction = "a=recvonly";
513 break;
514 case cricket::MD_SENDRECV:
515 default:
516 new_direction = "a=sendrecv";
517 break;
518 }
519 Replace("a=sendrecv", new_direction, message);
520}
521
522static void ReplaceRejected(bool audio_rejected, bool video_rejected,
523 std::string* message) {
524 if (audio_rejected) {
525 Replace("m=audio 2345", "m=audio 0", message);
526 }
527 if (video_rejected) {
528 Replace("m=video 3457", "m=video 0", message);
529 }
530}
531
532// WebRtcSdpTest
533
534class WebRtcSdpTest : public testing::Test {
535 public:
536 WebRtcSdpTest()
537 : jdesc_(kDummyString) {
538 // AudioContentDescription
539 audio_desc_ = CreateAudioContentDescription();
540 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
541 audio_desc_->AddCodec(opus);
542 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000543 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
545
546 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000547 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 new VideoContentDescription());
549 video_desc_ = video.get();
550 StreamParams video_stream1;
551 video_stream1.id = kVideoTrackId1;
552 video_stream1.cname = kStream1Cname;
553 video_stream1.sync_label = kStreamLabel1;
554 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
555 video->AddStream(video_stream1);
556 StreamParams video_stream2;
557 video_stream2.id = kVideoTrackId2;
558 video_stream2.cname = kStream1Cname;
559 video_stream2.sync_label = kStreamLabel1;
560 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
561 video->AddStream(video_stream2);
562 StreamParams video_stream3;
563 video_stream3.id = kVideoTrackId3;
564 video_stream3.cname = kStream2Cname;
565 video_stream3.sync_label = kStreamLabel2;
566 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
567 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
568 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
569 video_stream3.ssrc_groups.push_back(ssrc_group);
570 video->AddStream(video_stream3);
571 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
572 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
573 video->set_protocol(cricket::kMediaProtocolSavpf);
574 video->AddCodec(VideoCodec(
575 120,
576 JsepSessionDescription::kDefaultVideoCodecName,
577 JsepSessionDescription::kMaxVideoCodecWidth,
578 JsepSessionDescription::kMaxVideoCodecHeight,
579 JsepSessionDescription::kDefaultVideoCodecFramerate,
580 JsepSessionDescription::kDefaultVideoCodecPreference));
581
582 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
583 video.release());
584
585 // TransportInfo
586 EXPECT_TRUE(desc_.AddTransportInfo(
587 TransportInfo(kAudioContentName,
588 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000590 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 EXPECT_TRUE(desc_.AddTransportInfo(
592 TransportInfo(kVideoContentName,
593 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000595 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596
597 // v4 host
598 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000599 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000600 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000601 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
602 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000604 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000605 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
606 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000608 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000609 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
610 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000612 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000613 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
614 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615
616 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000617 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000618 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
619 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000620 cricket::LOCAL_PORT_TYPE,
621 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000623 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
624 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000625 cricket::LOCAL_PORT_TYPE,
626 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000628 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
629 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000630 cricket::LOCAL_PORT_TYPE,
631 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000633 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
634 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000635 cricket::LOCAL_PORT_TYPE,
636 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637
638 // stun
639 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000640 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
641 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000642 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
643 address_stun, kCandidatePriority, "", "",
644 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000645 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 candidate9.set_related_address(rel_address_stun);
647
648 address_stun.SetPort(port_stun++);
649 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000650 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
651 address_stun, kCandidatePriority, "", "",
652 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000653 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 candidate10.set_related_address(rel_address_stun);
655
656 // relay
657 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000658 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000659 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
660 address_relay, kCandidatePriority, "", "",
661 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000662 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000664 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
665 address_relay, kCandidatePriority, "", "",
666 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000667 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668
669 // voice
670 candidates_.push_back(candidate1);
671 candidates_.push_back(candidate2);
672 candidates_.push_back(candidate5);
673 candidates_.push_back(candidate6);
674 candidates_.push_back(candidate9);
675 candidates_.push_back(candidate10);
676
677 // video
678 candidates_.push_back(candidate3);
679 candidates_.push_back(candidate4);
680 candidates_.push_back(candidate7);
681 candidates_.push_back(candidate8);
682 candidates_.push_back(candidate11);
683 candidates_.push_back(candidate12);
684
685 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
686 0, candidate1));
687
688 // Set up JsepSessionDescription.
689 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
690 std::string mline_id;
691 int mline_index = 0;
692 for (size_t i = 0; i< candidates_.size(); ++i) {
693 // In this test, the audio m line index will be 0, and the video m line
694 // will be 1.
695 bool is_video = (i > 5);
696 mline_id = is_video ? "video_content_name" : "audio_content_name";
697 mline_index = is_video ? 1 : 0;
698 JsepIceCandidate jice(mline_id,
699 mline_index,
700 candidates_.at(i));
701 jdesc_.AddCandidate(&jice);
702 }
703 }
704
705 AudioContentDescription* CreateAudioContentDescription() {
706 AudioContentDescription* audio = new AudioContentDescription();
707 audio->set_rtcp_mux(true);
708 StreamParams audio_stream1;
709 audio_stream1.id = kAudioTrackId1;
710 audio_stream1.cname = kStream1Cname;
711 audio_stream1.sync_label = kStreamLabel1;
712 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
713 audio->AddStream(audio_stream1);
714 StreamParams audio_stream2;
715 audio_stream2.id = kAudioTrackId2;
716 audio_stream2.cname = kStream2Cname;
717 audio_stream2.sync_label = kStreamLabel2;
718 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
719 audio->AddStream(audio_stream2);
720 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
721 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
722 "dummy_session_params"));
723 audio->set_protocol(cricket::kMediaProtocolSavpf);
724 return audio;
725 }
726
727 template <class MCD>
728 void CompareMediaContentDescription(const MCD* cd1,
729 const MCD* cd2) {
730 // type
731 EXPECT_EQ(cd1->type(), cd1->type());
732
733 // content direction
734 EXPECT_EQ(cd1->direction(), cd2->direction());
735
736 // rtcp_mux
737 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
738
739 // cryptos
740 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
741 if (cd1->cryptos().size() != cd2->cryptos().size()) {
742 ADD_FAILURE();
743 return;
744 }
745 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
746 const CryptoParams c1 = cd1->cryptos().at(i);
747 const CryptoParams c2 = cd2->cryptos().at(i);
748 EXPECT_TRUE(c1.Matches(c2));
749 EXPECT_EQ(c1.key_params, c2.key_params);
750 EXPECT_EQ(c1.session_params, c2.session_params);
751 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000752
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000754 // Use an equivalence class here, for old and new versions of the
755 // protocol description.
756 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
757 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp) {
758 const bool cd2_is_also_udp_dtls_sctp =
759 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
760 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp;
761 EXPECT_TRUE(cd2_is_also_udp_dtls_sctp);
762 } else {
763 EXPECT_EQ(cd1->protocol(), cd2->protocol());
764 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765
766 // codecs
767 EXPECT_EQ(cd1->codecs(), cd2->codecs());
768
769 // bandwidth
770 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
771
772 // streams
773 EXPECT_EQ(cd1->streams(), cd2->streams());
774
775 // extmap
776 ASSERT_EQ(cd1->rtp_header_extensions().size(),
777 cd2->rtp_header_extensions().size());
778 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
779 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
780 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
781 EXPECT_EQ(ext1.uri, ext2.uri);
782 EXPECT_EQ(ext1.id, ext2.id);
783 }
784
785 // buffered mode latency
786 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
787 }
788
789
790 void CompareSessionDescription(const SessionDescription& desc1,
791 const SessionDescription& desc2) {
792 // Compare content descriptions.
793 if (desc1.contents().size() != desc2.contents().size()) {
794 ADD_FAILURE();
795 return;
796 }
797 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
798 const cricket::ContentInfo& c1 = desc1.contents().at(i);
799 const cricket::ContentInfo& c2 = desc2.contents().at(i);
800 // content name
801 EXPECT_EQ(c1.name, c2.name);
802 // content type
803 // Note, ASSERT will return from the function, but will not stop the test.
804 ASSERT_EQ(c1.type, c2.type);
805
806 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
807 if (IsAudioContent(&c1)) {
808 const AudioContentDescription* acd1 =
809 static_cast<const AudioContentDescription*>(c1.description);
810 const AudioContentDescription* acd2 =
811 static_cast<const AudioContentDescription*>(c2.description);
812 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
813 }
814
815 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
816 if (IsVideoContent(&c1)) {
817 const VideoContentDescription* vcd1 =
818 static_cast<const VideoContentDescription*>(c1.description);
819 const VideoContentDescription* vcd2 =
820 static_cast<const VideoContentDescription*>(c2.description);
821 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
822 }
823
824 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
825 if (IsDataContent(&c1)) {
826 const DataContentDescription* dcd1 =
827 static_cast<const DataContentDescription*>(c1.description);
828 const DataContentDescription* dcd2 =
829 static_cast<const DataContentDescription*>(c2.description);
830 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
831 }
832 }
833
834 // group
835 const cricket::ContentGroups groups1 = desc1.groups();
836 const cricket::ContentGroups groups2 = desc2.groups();
837 EXPECT_EQ(groups1.size(), groups1.size());
838 if (groups1.size() != groups2.size()) {
839 ADD_FAILURE();
840 return;
841 }
842 for (size_t i = 0; i < groups1.size(); ++i) {
843 const cricket::ContentGroup group1 = groups1.at(i);
844 const cricket::ContentGroup group2 = groups2.at(i);
845 EXPECT_EQ(group1.semantics(), group2.semantics());
846 const cricket::ContentNames names1 = group1.content_names();
847 const cricket::ContentNames names2 = group2.content_names();
848 EXPECT_EQ(names1.size(), names2.size());
849 if (names1.size() != names2.size()) {
850 ADD_FAILURE();
851 return;
852 }
853 cricket::ContentNames::const_iterator iter1 = names1.begin();
854 cricket::ContentNames::const_iterator iter2 = names2.begin();
855 while (iter1 != names1.end()) {
856 EXPECT_EQ(*iter1++, *iter2++);
857 }
858 }
859
860 // transport info
861 const cricket::TransportInfos transports1 = desc1.transport_infos();
862 const cricket::TransportInfos transports2 = desc2.transport_infos();
863 EXPECT_EQ(transports1.size(), transports2.size());
864 if (transports1.size() != transports2.size()) {
865 ADD_FAILURE();
866 return;
867 }
868 for (size_t i = 0; i < transports1.size(); ++i) {
869 const cricket::TransportInfo transport1 = transports1.at(i);
870 const cricket::TransportInfo transport2 = transports2.at(i);
871 EXPECT_EQ(transport1.content_name, transport2.content_name);
872 EXPECT_EQ(transport1.description.transport_type,
873 transport2.description.transport_type);
874 EXPECT_EQ(transport1.description.ice_ufrag,
875 transport2.description.ice_ufrag);
876 EXPECT_EQ(transport1.description.ice_pwd,
877 transport2.description.ice_pwd);
878 if (transport1.description.identity_fingerprint) {
879 EXPECT_EQ(*transport1.description.identity_fingerprint,
880 *transport2.description.identity_fingerprint);
881 } else {
882 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
883 transport2.description.identity_fingerprint.get());
884 }
885 EXPECT_EQ(transport1.description.transport_options,
886 transport2.description.transport_options);
887 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
888 transport2.description.candidates));
889 }
890 }
891
892 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
893 EXPECT_EQ(cs1.size(), cs2.size());
894 if (cs1.size() != cs2.size())
895 return false;
896 for (size_t i = 0; i< cs1.size(); ++i) {
897 const Candidate c1 = cs1.at(i);
898 const Candidate c2 = cs2.at(i);
899 EXPECT_TRUE(c1.IsEquivalent(c2));
900 }
901 return true;
902 }
903
904 bool CompareSessionDescription(
905 const JsepSessionDescription& desc1,
906 const JsepSessionDescription& desc2) {
907 EXPECT_EQ(desc1.session_id(), desc2.session_id());
908 EXPECT_EQ(desc1.session_version(), desc2.session_version());
909 CompareSessionDescription(*desc1.description(), *desc2.description());
910 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
911 return false;
912 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
913 const IceCandidateCollection* cc1 = desc1.candidates(i);
914 const IceCandidateCollection* cc2 = desc2.candidates(i);
915 if (cc1->count() != cc2->count())
916 return false;
917 for (size_t j = 0; j < cc1->count(); ++j) {
918 const IceCandidateInterface* c1 = cc1->at(j);
919 const IceCandidateInterface* c2 = cc2->at(j);
920 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
921 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
922 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
923 }
924 }
925 return true;
926 }
927
928 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
929 // them with invalid keywords so that the parser will just ignore them.
930 bool RemoveCandidateUfragPwd(std::string* sdp) {
931 const char ice_ufrag[] = "a=ice-ufrag";
932 const char ice_ufragx[] = "a=xice-ufrag";
933 const char ice_pwd[] = "a=ice-pwd";
934 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000935 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000937 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 ice_pwdx, strlen(ice_pwdx), sdp);
939 return true;
940 }
941
942 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
943 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
944 const std::string& ufrag, const std::string& pwd) {
945 std::string content_name;
946 if (mline_index == 0) {
947 content_name = kAudioContentName;
948 } else if (mline_index == 1) {
949 content_name = kVideoContentName;
950 } else {
951 ASSERT(false);
952 }
953 TransportInfo transport_info(
954 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000955 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 SessionDescription* desc =
957 const_cast<SessionDescription*>(jdesc->description());
958 desc->RemoveTransportInfoByName(content_name);
959 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
960 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
961 const IceCandidateCollection* cc = jdesc_.candidates(i);
962 for (size_t j = 0; j < cc->count(); ++j) {
963 if (cc->at(j)->sdp_mline_index() == mline_index) {
964 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
965 ufrag);
966 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
967 pwd);
968 }
969 }
970 }
971 return true;
972 }
973
974 void AddIceOptions(const std::string& content_name,
975 const std::vector<std::string>& transport_options) {
976 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
977 cricket::TransportInfo transport_info =
978 *(desc_.GetTransportInfoByName(content_name));
979 desc_.RemoveTransportInfoByName(content_name);
980 transport_info.description.transport_options = transport_options;
981 desc_.AddTransportInfo(transport_info);
982 }
983
984 void AddFingerprint() {
985 desc_.RemoveTransportInfoByName(kAudioContentName);
986 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000987 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 kIdentityDigest,
989 sizeof(kIdentityDigest));
990 EXPECT_TRUE(desc_.AddTransportInfo(
991 TransportInfo(kAudioContentName,
992 TransportDescription(NS_JINGLE_ICE_UDP,
993 std::vector<std::string>(),
994 kCandidateUfragVoice,
995 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000996 cricket::ICEMODE_FULL,
997 cricket::CONNECTIONROLE_NONE,
998 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 EXPECT_TRUE(desc_.AddTransportInfo(
1000 TransportInfo(kVideoContentName,
1001 TransportDescription(NS_JINGLE_ICE_UDP,
1002 std::vector<std::string>(),
1003 kCandidateUfragVideo,
1004 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001005 cricket::ICEMODE_FULL,
1006 cricket::CONNECTIONROLE_NONE,
1007 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 }
1009
1010 void AddExtmap() {
1011 audio_desc_ = static_cast<AudioContentDescription*>(
1012 audio_desc_->Copy());
1013 video_desc_ = static_cast<VideoContentDescription*>(
1014 video_desc_->Copy());
1015 audio_desc_->AddRtpHeaderExtension(
1016 RtpHeaderExtension(kExtmapUri, kExtmapId));
1017 video_desc_->AddRtpHeaderExtension(
1018 RtpHeaderExtension(kExtmapUri, kExtmapId));
1019 desc_.RemoveContentByName(kAudioContentName);
1020 desc_.RemoveContentByName(kVideoContentName);
1021 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1022 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1023 }
1024
1025 void RemoveCryptos() {
1026 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1027 video_desc_->set_cryptos(std::vector<CryptoParams>());
1028 }
1029
1030 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1031 audio_desc_->set_direction(direction);
1032 video_desc_->set_direction(direction);
1033 std::string new_sdp = kSdpFullString;
1034 ReplaceDirection(direction, &new_sdp);
1035
1036 if (!jdesc_.Initialize(desc_.Copy(),
1037 jdesc_.session_id(),
1038 jdesc_.session_version())) {
1039 return false;
1040 }
1041 std::string message = webrtc::SdpSerialize(jdesc_);
1042 EXPECT_EQ(new_sdp, message);
1043 return true;
1044 }
1045
1046 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1047 audio_desc_ = static_cast<AudioContentDescription*>(
1048 audio_desc_->Copy());
1049 video_desc_ = static_cast<VideoContentDescription*>(
1050 video_desc_->Copy());
1051 desc_.RemoveContentByName(kAudioContentName);
1052 desc_.RemoveContentByName(kVideoContentName);
1053 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1054 audio_desc_);
1055 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1056 video_desc_);
1057 std::string new_sdp = kSdpFullString;
1058 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1059
1060 if (!jdesc_.Initialize(desc_.Copy(),
1061 jdesc_.session_id(),
1062 jdesc_.session_version())) {
1063 return false;
1064 }
1065 std::string message = webrtc::SdpSerialize(jdesc_);
1066 EXPECT_EQ(new_sdp, message);
1067 return true;
1068 }
1069
1070 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001071 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 new DataContentDescription());
1073 data_desc_ = data.get();
1074 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001075 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1076 cricket::kGoogleSctpDataCodecName, 0);
1077 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1078 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1080 EXPECT_TRUE(desc_.AddTransportInfo(
1081 TransportInfo(kDataContentName,
1082 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001084 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 }
1086
1087 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001088 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 new DataContentDescription());
1090 data_desc_ = data.get();
1091
1092 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1093 StreamParams data_stream;
1094 data_stream.id = kDataChannelMsid;
1095 data_stream.cname = kDataChannelCname;
1096 data_stream.sync_label = kDataChannelLabel;
1097 data_stream.ssrcs.push_back(kDataChannelSsrc);
1098 data_desc_->AddStream(data_stream);
1099 data_desc_->AddCrypto(CryptoParams(
1100 1, "AES_CM_128_HMAC_SHA1_80",
1101 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1102 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1103 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1104 EXPECT_TRUE(desc_.AddTransportInfo(
1105 TransportInfo(kDataContentName,
1106 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001108 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 }
1110
1111 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1112 std::string new_sdp = kSdpFullString;
1113 ReplaceDirection(direction, &new_sdp);
1114 JsepSessionDescription new_jdesc(kDummyString);
1115
1116 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1117
1118 audio_desc_->set_direction(direction);
1119 video_desc_->set_direction(direction);
1120 if (!jdesc_.Initialize(desc_.Copy(),
1121 jdesc_.session_id(),
1122 jdesc_.session_version())) {
1123 return false;
1124 }
1125 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1126 return true;
1127 }
1128
1129 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1130 std::string new_sdp = kSdpFullString;
1131 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1132 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1133
1134 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1135 audio_desc_ = static_cast<AudioContentDescription*>(
1136 audio_desc_->Copy());
1137 video_desc_ = static_cast<VideoContentDescription*>(
1138 video_desc_->Copy());
1139 desc_.RemoveContentByName(kAudioContentName);
1140 desc_.RemoveContentByName(kVideoContentName);
1141 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1142 audio_desc_);
1143 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1144 video_desc_);
1145 if (!jdesc_.Initialize(desc_.Copy(),
1146 jdesc_.session_id(),
1147 jdesc_.session_version())) {
1148 return false;
1149 }
1150 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1151 return true;
1152 }
1153
1154 void TestDeserializeExtmap(bool session_level, bool media_level) {
1155 AddExtmap();
1156 JsepSessionDescription new_jdesc("dummy");
1157 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1158 jdesc_.session_id(),
1159 jdesc_.session_version()));
1160 JsepSessionDescription jdesc_with_extmap("dummy");
1161 std::string sdp_with_extmap = kSdpString;
1162 if (session_level) {
1163 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1164 &sdp_with_extmap);
1165 }
1166 if (media_level) {
1167 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1168 &sdp_with_extmap);
1169 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1170 &sdp_with_extmap);
1171 }
1172 // The extmap can't be present at the same time in both session level and
1173 // media level.
1174 if (session_level && media_level) {
1175 SdpParseError error;
1176 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1177 &jdesc_with_extmap, &error));
1178 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1179 } else {
1180 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1181 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1182 }
1183 }
1184
1185 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1186 const std::string& name, int expected_value) {
1187 cricket::CodecParameterMap::const_iterator found = params.find(name);
1188 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001189 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 }
1191
1192 void TestDeserializeCodecParams(const CodecParams& params,
1193 JsepSessionDescription* jdesc_output) {
1194 std::string sdp =
1195 "v=0\r\n"
1196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1197 "s=-\r\n"
1198 "t=0 0\r\n"
1199 // Include semantics for WebRTC Media Streams since it is supported by
1200 // this parser, and will be added to the SDP when serializing a session
1201 // description.
1202 "a=msid-semantic: WMS\r\n"
1203 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001204 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // Pltype 111 listed before 103 and 104 in the map.
1206 "a=rtpmap:111 opus/48000/2\r\n"
1207 // Pltype 103 listed before 104.
1208 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001209 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001210 "a=fmtp:111 0-15,66,70\r\n"
1211 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001213 os << "minptime=" << params.min_ptime
1214 << "; stereo=" << params.stereo
1215 << "; sprop-stereo=" << params.sprop_stereo
1216 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001217 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218 << "a=ptime:" << params.ptime << "\r\n"
1219 << "a=maxptime:" << params.max_ptime << "\r\n";
1220 sdp += os.str();
1221
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001222 os.clear();
1223 os.str("");
1224 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001225 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001226 << "a=rtpmap:99 VP8/90000\r\n"
1227 << "a=rtpmap:95 RTX/90000\r\n"
1228 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1229 sdp += os.str();
1230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231 // Deserialize
1232 SdpParseError error;
1233 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1234
1235 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1236 ASSERT_TRUE(ac != NULL);
1237 const AudioContentDescription* acd =
1238 static_cast<const AudioContentDescription*>(ac->description);
1239 ASSERT_FALSE(acd->codecs().empty());
1240 cricket::AudioCodec opus = acd->codecs()[0];
1241 EXPECT_EQ("opus", opus.name);
1242 EXPECT_EQ(111, opus.id);
1243 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1244 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1245 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1246 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001247 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1248 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1250 cricket::AudioCodec codec = acd->codecs()[i];
1251 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1252 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1253 if (codec.name == "ISAC") {
1254 if (codec.clockrate == 16000) {
1255 EXPECT_EQ(32000, codec.bitrate);
1256 } else {
1257 EXPECT_EQ(56000, codec.bitrate);
1258 }
1259 }
1260 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001261
1262 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1263 ASSERT_TRUE(vc != NULL);
1264 const VideoContentDescription* vcd =
1265 static_cast<const VideoContentDescription*>(vc->description);
1266 ASSERT_FALSE(vcd->codecs().empty());
1267 cricket::VideoCodec vp8 = vcd->codecs()[0];
1268 EXPECT_EQ("VP8", vp8.name);
1269 EXPECT_EQ(99, vp8.id);
1270 cricket::VideoCodec rtx = vcd->codecs()[1];
1271 EXPECT_EQ("RTX", rtx.name);
1272 EXPECT_EQ(95, rtx.id);
1273 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 }
1275
1276 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1277 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001278 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 "v=0\r\n"
1280 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1281 "s=-\r\n"
1282 "t=0 0\r\n"
1283 // Include semantics for WebRTC Media Streams since it is supported by
1284 // this parser, and will be added to the SDP when serializing a session
1285 // description.
1286 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001287 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001288 "a=rtpmap:111 opus/48000/2\r\n";
1289 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 "m=video 3457 RTP/SAVPF 101\r\n"
1291 "a=rtpmap:101 VP8/90000\r\n"
1292 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001293 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001294 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001296 os << sdp_session_and_audio;
1297 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1298 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001300 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 // Deserialize
1302 SdpParseError error;
1303 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1304 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1305 ASSERT_TRUE(ac != NULL);
1306 const AudioContentDescription* acd =
1307 static_cast<const AudioContentDescription*>(ac->description);
1308 ASSERT_FALSE(acd->codecs().empty());
1309 cricket::AudioCodec opus = acd->codecs()[0];
1310 EXPECT_EQ(111, opus.id);
1311 EXPECT_TRUE(opus.HasFeedbackParam(
1312 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1313 cricket::kParamValueEmpty)));
1314
1315 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1316 ASSERT_TRUE(vc != NULL);
1317 const VideoContentDescription* vcd =
1318 static_cast<const VideoContentDescription*>(vc->description);
1319 ASSERT_FALSE(vcd->codecs().empty());
1320 cricket::VideoCodec vp8 = vcd->codecs()[0];
1321 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1322 vp8.name.c_str());
1323 EXPECT_EQ(101, vp8.id);
1324 EXPECT_TRUE(vp8.HasFeedbackParam(
1325 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1326 cricket::kParamValueEmpty)));
1327 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001328 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1329 cricket::kRtcpFbNackParamPli)));
1330 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1332 cricket::kParamValueEmpty)));
1333 EXPECT_TRUE(vp8.HasFeedbackParam(
1334 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1335 cricket::kRtcpFbCcmParamFir)));
1336 }
1337
1338 // Two SDP messages can mean the same thing but be different strings, e.g.
1339 // some of the lines can be serialized in different order.
1340 // However, a deserialized description can be compared field by field and has
1341 // no order. If deserializer has already been tested, serializing then
1342 // deserializing and comparing JsepSessionDescription will test
1343 // the serializer sufficiently.
1344 void TestSerialize(const JsepSessionDescription& jdesc) {
1345 std::string message = webrtc::SdpSerialize(jdesc);
1346 JsepSessionDescription jdesc_output_des(kDummyString);
1347 SdpParseError error;
1348 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1349 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1350 }
1351
1352 protected:
1353 SessionDescription desc_;
1354 AudioContentDescription* audio_desc_;
1355 VideoContentDescription* video_desc_;
1356 DataContentDescription* data_desc_;
1357 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001358 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 JsepSessionDescription jdesc_;
1360};
1361
1362void TestMismatch(const std::string& string1, const std::string& string2) {
1363 int position = 0;
1364 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1365 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001366 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 break;
1368 }
1369 }
1370 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1371 << " character\n"
1372 << " 1: " << string1.substr(position, 20) << "\n"
1373 << " 2: " << string2.substr(position, 20) << "\n";
1374}
1375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1377 // SessionDescription with desc and candidates.
1378 std::string message = webrtc::SdpSerialize(jdesc_);
1379 TestMismatch(std::string(kSdpFullString), message);
1380}
1381
1382TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1383 JsepSessionDescription jdesc_empty(kDummyString);
1384 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1385}
1386
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001387// This tests serialization of SDP with only IPv6 candidates and verifies that
1388// IPv6 is used as default address in c line according to preference.
1389TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1390 // Only test 1 m line.
1391 desc_.RemoveContentByName("video_content_name");
1392 // Stun has a high preference than local host.
1393 cricket::Candidate candidate1(
1394 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1395 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1396 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1397 cricket::Candidate candidate2(
1398 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1399 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1400 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1401 JsepSessionDescription jdesc(kDummyString);
1402 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1403
1404 // Only add the candidates to audio m line.
1405 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1406 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1407 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1408 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1409 std::string message = webrtc::SdpSerialize(jdesc);
1410
1411 // Audio line should have a c line like this one.
1412 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1413 // Shouldn't have a IP4 c line.
1414 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1415}
1416
1417// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1418// verifies that IPv4 is used as default address in c line even if the
1419// preference of IPv4 is lower.
1420TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1421 // Only test 1 m line.
1422 desc_.RemoveContentByName("video_content_name");
1423 cricket::Candidate candidate_v4(
1424 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1425 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1426 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1427 cricket::Candidate candidate_v6(
1428 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1429 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1430 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1431 JsepSessionDescription jdesc(kDummyString);
1432 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1433
1434 // Only add the candidates to audio m line.
1435 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1436 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1437 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1438 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1439 std::string message = webrtc::SdpSerialize(jdesc);
1440
1441 // Audio line should have a c line like this one.
1442 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1443 // Shouldn't have a IP6 c line.
1444 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1445}
1446
1447// This tests serialization of SDP with both UDP and TCP candidates and
1448// verifies that UDP is used as default address in c line even if the
1449// preference of UDP is lower.
1450TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1451 // Only test 1 m line.
1452 desc_.RemoveContentByName("video_content_name");
1453 // Stun has a high preference than local host.
1454 cricket::Candidate candidate1(
1455 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1456 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1457 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1458 cricket::Candidate candidate2(
1459 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1460 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1461 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1462 kCandidateFoundation1);
1463 JsepSessionDescription jdesc(kDummyString);
1464 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1465
1466 // Only add the candidates to audio m line.
1467 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1468 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1469 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1470 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1471 std::string message = webrtc::SdpSerialize(jdesc);
1472
1473 // Audio line should have a c line like this one.
1474 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1475 std::string::npos);
1476 // Shouldn't have a IP4 c line.
1477 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1478}
1479
1480// This tests serialization of SDP with only TCP candidates and verifies that
1481// null IPv4 is used as default address in c line.
1482TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1483 // Only test 1 m line.
1484 desc_.RemoveContentByName("video_content_name");
1485 // Stun has a high preference than local host.
1486 cricket::Candidate candidate1(
1487 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1488 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1489 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1490 cricket::Candidate candidate2(
1491 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1492 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1493 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1494 JsepSessionDescription jdesc(kDummyString);
1495 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1496
1497 // Only add the candidates to audio m line.
1498 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1499 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1500 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1501 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1502 std::string message = webrtc::SdpSerialize(jdesc);
1503
1504 // Audio line should have a c line like this one when no any default exists.
1505 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1506}
1507
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1509// the case in a DTLS offer.
1510TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1511 AddFingerprint();
1512 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1513 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1514 kSessionId, kSessionVersion));
1515 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1516
1517 std::string sdp_with_fingerprint = kSdpString;
1518 InjectAfter(kAttributeIcePwdVoice,
1519 kFingerprint, &sdp_with_fingerprint);
1520 InjectAfter(kAttributeIcePwdVideo,
1521 kFingerprint, &sdp_with_fingerprint);
1522
1523 EXPECT_EQ(sdp_with_fingerprint, message);
1524}
1525
1526// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1527// be the case in a DTLS answer.
1528TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1529 AddFingerprint();
1530 RemoveCryptos();
1531 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1532 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1533 kSessionId, kSessionVersion));
1534 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1535
1536 std::string sdp_with_fingerprint = kSdpString;
1537 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1538 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1539 InjectAfter(kAttributeIcePwdVoice,
1540 kFingerprint, &sdp_with_fingerprint);
1541 InjectAfter(kAttributeIcePwdVideo,
1542 kFingerprint, &sdp_with_fingerprint);
1543
1544 EXPECT_EQ(sdp_with_fingerprint, message);
1545}
1546
1547TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1548 // JsepSessionDescription with desc but without candidates.
1549 JsepSessionDescription jdesc_no_candidates(kDummyString);
1550 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1551 kSessionId, kSessionVersion));
1552 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1553 EXPECT_EQ(std::string(kSdpString), message);
1554}
1555
1556TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1557 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1558 group.AddContentName(kAudioContentName);
1559 group.AddContentName(kVideoContentName);
1560 desc_.AddGroup(group);
1561 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1562 jdesc_.session_id(),
1563 jdesc_.session_version()));
1564 std::string message = webrtc::SdpSerialize(jdesc_);
1565 std::string sdp_with_bundle = kSdpFullString;
1566 InjectAfter(kSessionTime,
1567 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1568 &sdp_with_bundle);
1569 EXPECT_EQ(sdp_with_bundle, message);
1570}
1571
1572TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1573 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1574 GetFirstVideoContent(&desc_)->description);
1575 vcd->set_bandwidth(100 * 1000);
1576 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1577 GetFirstAudioContent(&desc_)->description);
1578 acd->set_bandwidth(50 * 1000);
1579 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1580 jdesc_.session_id(),
1581 jdesc_.session_version()));
1582 std::string message = webrtc::SdpSerialize(jdesc_);
1583 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001584 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 "b=AS:100\r\n",
1586 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001587 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 "b=AS:50\r\n",
1589 &sdp_with_bandwidth);
1590 EXPECT_EQ(sdp_with_bandwidth, message);
1591}
1592
1593TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1594 std::vector<std::string> transport_options;
1595 transport_options.push_back(kIceOption1);
1596 transport_options.push_back(kIceOption3);
1597 AddIceOptions(kAudioContentName, transport_options);
1598 transport_options.clear();
1599 transport_options.push_back(kIceOption2);
1600 transport_options.push_back(kIceOption3);
1601 AddIceOptions(kVideoContentName, transport_options);
1602 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1603 jdesc_.session_id(),
1604 jdesc_.session_version()));
1605 std::string message = webrtc::SdpSerialize(jdesc_);
1606 std::string sdp_with_ice_options = kSdpFullString;
1607 InjectAfter(kAttributeIcePwdVoice,
1608 "a=ice-options:iceoption1 iceoption3\r\n",
1609 &sdp_with_ice_options);
1610 InjectAfter(kAttributeIcePwdVideo,
1611 "a=ice-options:iceoption2 iceoption3\r\n",
1612 &sdp_with_ice_options);
1613 EXPECT_EQ(sdp_with_ice_options, message);
1614}
1615
1616TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1617 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1618}
1619
1620TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1621 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1622}
1623
1624TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1625 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1626}
1627
1628TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1629 EXPECT_TRUE(TestSerializeRejected(true, false));
1630}
1631
1632TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1633 EXPECT_TRUE(TestSerializeRejected(false, true));
1634}
1635
1636TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1637 EXPECT_TRUE(TestSerializeRejected(true, true));
1638}
1639
1640TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1641 AddRtpDataChannel();
1642 JsepSessionDescription jsep_desc(kDummyString);
1643
1644 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1645 std::string message = webrtc::SdpSerialize(jsep_desc);
1646
1647 std::string expected_sdp = kSdpString;
1648 expected_sdp.append(kSdpRtpDataChannelString);
1649 EXPECT_EQ(expected_sdp, message);
1650}
1651
1652TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1653 AddSctpDataChannel();
1654 JsepSessionDescription jsep_desc(kDummyString);
1655
1656 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1657 std::string message = webrtc::SdpSerialize(jsep_desc);
1658
1659 std::string expected_sdp = kSdpString;
1660 expected_sdp.append(kSdpSctpDataChannelString);
1661 EXPECT_EQ(message, expected_sdp);
1662}
1663
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001664TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1665 AddSctpDataChannel();
1666 JsepSessionDescription jsep_desc(kDummyString);
1667
1668 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1669 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1670 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1671
1672 const int kNewPort = 1234;
1673 cricket::DataCodec codec(
1674 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1675 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1676 dcdesc->AddOrReplaceCodec(codec);
1677
1678 std::string message = webrtc::SdpSerialize(jsep_desc);
1679
1680 std::string expected_sdp = kSdpString;
1681 expected_sdp.append(kSdpSctpDataChannelString);
1682
1683 char default_portstr[16];
1684 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001685 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001686 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001687 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1688 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001689 new_portstr, strlen(new_portstr),
1690 &expected_sdp);
1691
1692 EXPECT_EQ(expected_sdp, message);
1693}
1694
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001695TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1696 AddRtpDataChannel();
1697 data_desc_->set_bandwidth(100*1000);
1698 JsepSessionDescription jsep_desc(kDummyString);
1699
1700 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1701 std::string message = webrtc::SdpSerialize(jsep_desc);
1702
1703 std::string expected_sdp = kSdpString;
1704 expected_sdp.append(kSdpRtpDataChannelString);
1705 // We want to test that serializing data content ignores bandwidth
1706 // settings (it should always be the default). Thus, we don't do
1707 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001708 // TODO(pthatcher): We need to temporarily allow the SDP to control
1709 // this for backwards-compatibility. Once we don't need that any
1710 // more, remove this.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001711 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 +00001712 "b=AS:100\r\n",
1713 &expected_sdp);
1714 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001715}
1716
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1718 AddExtmap();
1719 JsepSessionDescription desc_with_extmap("dummy");
1720 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1721 kSessionId, kSessionVersion));
1722 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1723
1724 std::string sdp_with_extmap = kSdpString;
1725 InjectAfter("a=mid:audio_content_name\r\n",
1726 kExtmap, &sdp_with_extmap);
1727 InjectAfter("a=mid:video_content_name\r\n",
1728 kExtmap, &sdp_with_extmap);
1729
1730 EXPECT_EQ(sdp_with_extmap, message);
1731}
1732
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001733TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1734 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1735 GetFirstVideoContent(&desc_)->description);
1736 vcd->set_buffered_mode_latency(128);
1737
1738 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1739 jdesc_.session_id(),
1740 jdesc_.session_version()));
1741 std::string message = webrtc::SdpSerialize(jdesc_);
1742 std::string sdp_with_buffer_latency = kSdpFullString;
1743 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1744 "a=x-google-buffer-latency:128\r\n",
1745 &sdp_with_buffer_latency);
1746 EXPECT_EQ(sdp_with_buffer_latency, message);
1747}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
1749TEST_F(WebRtcSdpTest, SerializeCandidates) {
1750 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001751 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752}
1753
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001754// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1755// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001756TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001757 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001758 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1759 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1760 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001761 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1762 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1763 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1764
1765 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1766 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1767}
1768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1770 JsepSessionDescription jdesc(kDummyString);
1771 // Deserialize
1772 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1773 // Verify
1774 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1775}
1776
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001777TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1778 JsepSessionDescription jdesc(kDummyString);
1779 const char kSdpWithoutMline[] =
1780 "v=0\r\n"
1781 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1782 "s=-\r\n"
1783 "t=0 0\r\n"
1784 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1785 // Deserialize
1786 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1787 EXPECT_EQ(0u, jdesc.description()->contents().size());
1788}
1789
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1791 JsepSessionDescription jdesc(kDummyString);
1792 std::string sdp_without_carriage_return = kSdpFullString;
1793 Replace("\r\n", "\n", &sdp_without_carriage_return);
1794 // Deserialize
1795 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1796 // Verify
1797 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1798}
1799
1800TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1801 // SessionDescription with desc but without candidates.
1802 JsepSessionDescription jdesc_no_candidates(kDummyString);
1803 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1804 kSessionId, kSessionVersion));
1805 JsepSessionDescription new_jdesc(kDummyString);
1806 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1807 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1808}
1809
1810TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1811 static const char kSdpNoRtpmapString[] =
1812 "v=0\r\n"
1813 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1814 "s=-\r\n"
1815 "t=0 0\r\n"
1816 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1817 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001818 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 // The rtpmap line for static payload codec is optional.
1820 "a=rtpmap:18 G729/16000\r\n"
1821 "a=rtpmap:103 ISAC/16000\r\n";
1822
1823 JsepSessionDescription jdesc(kDummyString);
1824 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1825 cricket::AudioContentDescription* audio =
1826 static_cast<AudioContentDescription*>(
1827 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1828 AudioCodecs ref_codecs;
1829 // The codecs in the AudioContentDescription will be sorted by preference.
1830 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1831 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1832 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1833 EXPECT_EQ(ref_codecs, audio->codecs());
1834}
1835
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001836TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1837 static const char kSdpNoRtpmapString[] =
1838 "v=0\r\n"
1839 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1840 "s=-\r\n"
1841 "t=0 0\r\n"
1842 "m=audio 49232 RTP/AVP 18 103\r\n"
1843 "a=fmtp:18 annexb=yes\r\n"
1844 "a=rtpmap:103 ISAC/16000\r\n";
1845
1846 JsepSessionDescription jdesc(kDummyString);
1847 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1848 cricket::AudioContentDescription* audio =
1849 static_cast<AudioContentDescription*>(
1850 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1851
1852 cricket::AudioCodec g729 = audio->codecs()[0];
1853 EXPECT_EQ("G729", g729.name);
1854 EXPECT_EQ(8000, g729.clockrate);
1855 EXPECT_EQ(18, g729.id);
1856 cricket::CodecParameterMap::iterator found =
1857 g729.params.find("annexb");
1858 ASSERT_TRUE(found != g729.params.end());
1859 EXPECT_EQ(found->second, "yes");
1860
1861 cricket::AudioCodec isac = audio->codecs()[1];
1862 EXPECT_EQ("ISAC", isac.name);
1863 EXPECT_EQ(103, isac.id);
1864 EXPECT_EQ(16000, isac.clockrate);
1865}
1866
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867// Ensure that we can deserialize SDP with a=fingerprint properly.
1868TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1869 // Add a DTLS a=fingerprint attribute to our session description.
1870 AddFingerprint();
1871 JsepSessionDescription new_jdesc(kDummyString);
1872 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1873 jdesc_.session_id(),
1874 jdesc_.session_version()));
1875
1876 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1877 std::string sdp_with_fingerprint = kSdpString;
1878 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1879 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1880 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1881 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1882}
1883
1884TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1885 JsepSessionDescription jdesc_with_bundle(kDummyString);
1886 std::string sdp_with_bundle = kSdpFullString;
1887 InjectAfter(kSessionTime,
1888 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1889 &sdp_with_bundle);
1890 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1891 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1892 group.AddContentName(kAudioContentName);
1893 group.AddContentName(kVideoContentName);
1894 desc_.AddGroup(group);
1895 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1896 jdesc_.session_id(),
1897 jdesc_.session_version()));
1898 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1899}
1900
1901TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1902 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1903 std::string sdp_with_bandwidth = kSdpFullString;
1904 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1905 "b=AS:100\r\n",
1906 &sdp_with_bandwidth);
1907 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1908 "b=AS:50\r\n",
1909 &sdp_with_bandwidth);
1910 EXPECT_TRUE(
1911 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1912 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1913 GetFirstVideoContent(&desc_)->description);
1914 vcd->set_bandwidth(100 * 1000);
1915 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1916 GetFirstAudioContent(&desc_)->description);
1917 acd->set_bandwidth(50 * 1000);
1918 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1919 jdesc_.session_id(),
1920 jdesc_.session_version()));
1921 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1922}
1923
1924TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1925 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1926 std::string sdp_with_ice_options = kSdpFullString;
1927 InjectAfter(kSessionTime,
1928 "a=ice-options:iceoption3\r\n",
1929 &sdp_with_ice_options);
1930 InjectAfter(kAttributeIcePwdVoice,
1931 "a=ice-options:iceoption1\r\n",
1932 &sdp_with_ice_options);
1933 InjectAfter(kAttributeIcePwdVideo,
1934 "a=ice-options:iceoption2\r\n",
1935 &sdp_with_ice_options);
1936 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1937 std::vector<std::string> transport_options;
1938 transport_options.push_back(kIceOption3);
1939 transport_options.push_back(kIceOption1);
1940 AddIceOptions(kAudioContentName, transport_options);
1941 transport_options.clear();
1942 transport_options.push_back(kIceOption3);
1943 transport_options.push_back(kIceOption2);
1944 AddIceOptions(kVideoContentName, transport_options);
1945 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1946 jdesc_.session_id(),
1947 jdesc_.session_version()));
1948 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1949}
1950
1951TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1952 // Remove the original ice-ufrag and ice-pwd
1953 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1954 std::string sdp_with_ufrag_pwd = kSdpFullString;
1955 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1956 // Add session level ufrag and pwd
1957 InjectAfter(kSessionTime,
1958 "a=ice-pwd:session+level+icepwd\r\n"
1959 "a=ice-ufrag:session+level+iceufrag\r\n",
1960 &sdp_with_ufrag_pwd);
1961 // Add media level ufrag and pwd for audio
1962 InjectAfter("a=mid:audio_content_name\r\n",
1963 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1964 &sdp_with_ufrag_pwd);
1965 // Update the candidate ufrag and pwd to the expected ones.
1966 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1967 "media+level+iceufrag", "media+level+icepwd"));
1968 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1969 "session+level+iceufrag", "session+level+icepwd"));
1970 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1971 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1972}
1973
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001974TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1975 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1976 std::string sdp_with_buffer_latency = kSdpFullString;
1977 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1978 "a=x-google-buffer-latency:128\r\n",
1979 &sdp_with_buffer_latency);
1980
1981 EXPECT_TRUE(
1982 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1983 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1984 GetFirstVideoContent(&desc_)->description);
1985 vcd->set_buffered_mode_latency(128);
1986 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1987 jdesc_.session_id(),
1988 jdesc_.session_version()));
1989 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1990}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991
1992TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1993 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1994}
1995
1996TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1997 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1998}
1999
2000TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2001 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2002}
2003
2004TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2005 EXPECT_TRUE(TestDeserializeRejected(true, false));
2006}
2007
2008TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2009 EXPECT_TRUE(TestDeserializeRejected(false, true));
2010}
2011
2012TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2013 EXPECT_TRUE(TestDeserializeRejected(true, true));
2014}
2015
2016// Tests that we can still handle the sdp uses mslabel and label instead of
2017// msid for backward compatibility.
2018TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2019 JsepSessionDescription jdesc(kDummyString);
2020 std::string sdp_without_msid = kSdpFullString;
2021 Replace("msid", "xmsid", &sdp_without_msid);
2022 // Deserialize
2023 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2024 // Verify
2025 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2026}
2027
2028TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2029 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2030
2031 std::string sdp = kSdpOneCandidate;
2032 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2033 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2034 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2035 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2036
2037 // Candidate line without generation extension.
2038 sdp = kSdpOneCandidate;
2039 Replace(" generation 2", "", &sdp);
2040 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2041 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2042 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2043 Candidate expected = jcandidate_->candidate();
2044 expected.set_generation(0);
2045 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2046
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002047 sdp = kSdpTcpActiveCandidate;
2048 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2049 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002050 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002051 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2052 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2053 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002054 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2055 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2056 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2057 jcandidate_template->candidate()));
2058 sdp = kSdpTcpPassiveCandidate;
2059 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2060 sdp = kSdpTcpSOCandidate;
2061 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062}
2063
2064// This test verifies the deserialization of candidate-attribute
2065// as per RFC 5245. Candiate-attribute will be of the format
2066// candidate:<blah>. This format will be used when candidates
2067// are trickled.
2068TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2069 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2070
2071 std::string candidate_attribute = kRawCandidate;
2072 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2073 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2074 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2075 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2076 EXPECT_EQ(2u, jcandidate.candidate().generation());
2077
2078 // Candidate line without generation extension.
2079 candidate_attribute = kRawCandidate;
2080 Replace(" generation 2", "", &candidate_attribute);
2081 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2082 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2083 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2084 Candidate expected = jcandidate_->candidate();
2085 expected.set_generation(0);
2086 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2087
2088 // Candidate line without candidate:
2089 candidate_attribute = kRawCandidate;
2090 Replace("candidate:", "", &candidate_attribute);
2091 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2092
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002093 // Candidate line with IPV6 address.
2094 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2095}
2096
2097// This test verifies that the deserialization of an invalid candidate string
2098// fails.
2099TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2100 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2101
2102 std::string candidate_attribute = kRawCandidate;
2103 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002105
2106 candidate_attribute = kSdpOneCandidate;
2107 candidate_attribute.replace(0, 1, "x");
2108 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2109
2110 candidate_attribute = kRawCandidate;
2111 candidate_attribute.append("\r\n");
2112 candidate_attribute.append(kRawCandidate);
2113 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2114
2115 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116}
2117
2118TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2119 AddRtpDataChannel();
2120 JsepSessionDescription jdesc(kDummyString);
2121 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2122
2123 std::string sdp_with_data = kSdpString;
2124 sdp_with_data.append(kSdpRtpDataChannelString);
2125 JsepSessionDescription jdesc_output(kDummyString);
2126
2127 // Deserialize
2128 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2129 // Verify
2130 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2131}
2132
2133TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2134 AddSctpDataChannel();
2135 JsepSessionDescription jdesc(kDummyString);
2136 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2137
2138 std::string sdp_with_data = kSdpString;
2139 sdp_with_data.append(kSdpSctpDataChannelString);
2140 JsepSessionDescription jdesc_output(kDummyString);
2141
2142 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2143 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2144}
2145
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002146TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2147 AddSctpDataChannel();
2148 JsepSessionDescription jdesc(kDummyString);
2149 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2150
2151 std::string sdp_with_data = kSdpString;
2152 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2153 JsepSessionDescription jdesc_output(kDummyString);
2154
2155 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2156 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2157}
2158
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002159TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithOldProtocol) {
2160 AddSctpDataChannel();
2161 JsepSessionDescription jdesc(kDummyString);
2162 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2163
2164 std::string sdp_with_data = kSdpString;
2165 sdp_with_data.append(kSdpSctpDataChannelStringWithOldProtocol);
2166 JsepSessionDescription jdesc_output(kDummyString);
2167
2168 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2169 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2170}
2171
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002172// Test to check the behaviour if sctp-port is specified
2173// on the m= line and in a=sctp-port.
2174TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2175 AddSctpDataChannel();
2176 JsepSessionDescription jdesc(kDummyString);
2177 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2178
2179 std::string sdp_with_data = kSdpString;
2180 // Append m= attributes
2181 sdp_with_data.append(kSdpSctpDataChannelString);
2182 // Append a=sctp-port attribute
2183 sdp_with_data.append("a=sctp-port 5000\r\n");
2184 JsepSessionDescription jdesc_output(kDummyString);
2185
2186 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2187}
2188
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002189// For crbug/344475.
2190TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2191 std::string sdp_with_data = kSdpString;
2192 sdp_with_data.append(kSdpSctpDataChannelString);
2193 // Remove the "\n" at the end.
2194 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2195 JsepSessionDescription jdesc_output(kDummyString);
2196
2197 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2198 // No crash is a pass.
2199}
2200
wu@webrtc.org78187522013-10-07 23:32:02 +00002201TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2202 AddSctpDataChannel();
2203 const uint16 kUnusualSctpPort = 9556;
2204 char default_portstr[16];
2205 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002206 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002207 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002208 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002209 kUnusualSctpPort);
2210
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002211 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002212 JsepSessionDescription jdesc(kDummyString);
2213 // take our pre-built session description and change the SCTP port.
2214 cricket::SessionDescription* mutant = desc_.Copy();
2215 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2216 mutant->GetContentDescriptionByName(kDataContentName));
2217 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002218 EXPECT_EQ(1U, codecs.size());
2219 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002220 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002221 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002222
2223 // note: mutant's owned by jdesc now.
2224 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2225 mutant = NULL;
2226
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002227 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002228 std::string sdp_with_data = kSdpString;
2229 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002230 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002231 unusual_portstr, strlen(unusual_portstr),
2232 &sdp_with_data);
2233 JsepSessionDescription jdesc_output(kDummyString);
2234
2235 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2236 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002237
2238 // We need to test the deserialized JsepSessionDescription from
2239 // kSdpSctpDataChannelStringWithSctpPort for
2240 // draft-ietf-mmusic-sctp-sdp-07
2241 // a=sctp-port
2242 sdp_with_data = kSdpString;
2243 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2244 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2245 unusual_portstr, strlen(unusual_portstr),
2246 &sdp_with_data);
2247
2248 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2249 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002250}
2251
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002252TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2253 AddRtpDataChannel();
2254 JsepSessionDescription jdesc(kDummyString);
2255 // We want to test that deserializing data content ignores bandwidth
2256 // settings (it should always be the default). Thus, we don't do
2257 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002258 // TODO(pthatcher): We need to temporarily allow the SDP to control
2259 // this for backwards-compatibility. Once we don't need that any
2260 // more, remove this.
2261 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2262 GetFirstDataContent(&desc_)->description);
2263 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002264 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2265
2266 std::string sdp_with_bandwidth = kSdpString;
2267 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2268 InjectAfter("a=mid:data_content_name\r\n",
2269 "b=AS:100\r\n",
2270 &sdp_with_bandwidth);
2271 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2272
2273 EXPECT_TRUE(
2274 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2275 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2276}
2277
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2279 TestDeserializeExtmap(true, false);
2280}
2281
2282TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2283 TestDeserializeExtmap(false, true);
2284}
2285
2286TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2287 TestDeserializeExtmap(true, true);
2288}
2289
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002290TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2291 JsepSessionDescription jdesc(kDummyString);
2292 std::string sdp = kSdpFullString;
2293 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2294 // Deserialize
2295 SdpParseError error;
2296 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2297 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2298 EXPECT_EQ(lastline, error.line);
2299 EXPECT_EQ("Invalid SDP line.", error.description);
2300}
2301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2303 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2304 std::string new_sdp = kSdpOneCandidate;
2305 Replace("udp", "unsupported_transport", &new_sdp);
2306 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2307 new_sdp = kSdpOneCandidate;
2308 Replace("udp", "uDP", &new_sdp);
2309 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2310 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2311 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2312 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2313}
2314
2315TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2316 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2317 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2318 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2319 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2320 Candidate ref_candidate = jcandidate_->candidate();
2321 ref_candidate.set_username("user_rtp");
2322 ref_candidate.set_password("password_rtp");
2323 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2324}
2325
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002326TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2327 JsepSessionDescription jdesc(kDummyString);
2328
2329 // Deserialize
2330 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2331
2332 // Verify
2333 cricket::AudioContentDescription* audio =
2334 static_cast<AudioContentDescription*>(
2335 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2336 EXPECT_TRUE(audio->conference_mode());
2337
2338 cricket::VideoContentDescription* video =
2339 static_cast<VideoContentDescription*>(
2340 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2341 EXPECT_TRUE(video->conference_mode());
2342}
2343
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2345 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002346 const char kSdpEmptyType[] = " =candidate";
2347 const char kSdpEqualAsPlus[] = "a+candidate";
2348 const char kSdpSpaceAfterEqual[] = "a= candidate";
2349 const char kSdpUpperType[] = "A=candidate";
2350 const char kSdpEmptyLine[] = "";
2351 const char kSdpMissingValue[] = "a=";
2352
2353 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 "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 +00002355 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 "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 +00002357 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 "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 +00002359 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002360 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002361 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362
2363 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002364 ExpectParseFailure("v=", kSdpDestroyer);
2365 ExpectParseFailure("o=", kSdpDestroyer);
2366 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002368 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
2370 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002371 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2372 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
2374 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002375 ExpectParseFailure("a=candidate", kSdpEmptyType);
2376 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2377 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2378 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2381 // because it's orthogonal to what we are replacing and hence
2382 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002383 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2384 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2385 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2386 ExpectParseFailure("a=sendrecv", kSdpMd5);
2387
2388 // Empty Line
2389 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2390 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002391}
2392
2393TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2394 // ssrc
2395 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2396 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2397 // crypto
2398 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2399 // rtpmap
2400 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2401 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2402 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2403 // candidate
2404 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2405 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2406 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2407 ExpectParseFailure("rport 2346", "rport badvalue");
2408 ExpectParseFailure("rport 2346 generation 2",
2409 "rport 2346 generation badvalue");
2410 // m line
2411 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2412 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2413
2414 // bandwidth
2415 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2416 "b=AS:badvalue\r\n",
2417 "b=AS:badvalue");
2418 // rtcp-fb
2419 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2420 "a=rtcp-fb:badvalue nack\r\n",
2421 "a=rtcp-fb:badvalue nack");
2422 // extmap
2423 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2424 "a=extmap:badvalue http://example.com\r\n",
2425 "a=extmap:badvalue http://example.com");
2426 // x-google-buffer-latency
2427 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2428 "a=x-google-buffer-latency:badvalue\r\n",
2429 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430}
2431
2432TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2433 JsepSessionDescription jdesc_output(kDummyString);
2434
2435 const char kSdpWithReorderedPlTypesString[] =
2436 "v=0\r\n"
2437 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2438 "s=-\r\n"
2439 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002440 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2442 // in the map.
2443 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002444 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445
2446 // Deserialize
2447 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2448
2449 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2450 ASSERT_TRUE(ac != NULL);
2451 const AudioContentDescription* acd =
2452 static_cast<const AudioContentDescription*>(ac->description);
2453 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002454 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2455 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 EXPECT_EQ(104, acd->codecs()[0].id);
2457}
2458
2459TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2460 JsepSessionDescription jdesc_output(kDummyString);
2461 CodecParams params;
2462 params.max_ptime = 40;
2463 params.ptime = 30;
2464 params.min_ptime = 10;
2465 params.sprop_stereo = 1;
2466 params.stereo = 1;
2467 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002468 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 TestDeserializeCodecParams(params, &jdesc_output);
2470 TestSerialize(jdesc_output);
2471}
2472
2473TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2474 const bool kUseWildcard = false;
2475 JsepSessionDescription jdesc_output(kDummyString);
2476 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2477 TestSerialize(jdesc_output);
2478}
2479
2480TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2481 const bool kUseWildcard = true;
2482 JsepSessionDescription jdesc_output(kDummyString);
2483 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2484 TestSerialize(jdesc_output);
2485}
2486
2487TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2488 JsepSessionDescription jdesc_output(kDummyString);
2489
2490 const char kSdpWithFmtpString[] =
2491 "v=0\r\n"
2492 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2493 "s=-\r\n"
2494 "t=0 0\r\n"
2495 "m=video 3457 RTP/SAVPF 120\r\n"
2496 "a=rtpmap:120 VP8/90000\r\n"
2497 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2498
2499 // Deserialize
2500 SdpParseError error;
2501 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2502 &error));
2503
2504 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2505 ASSERT_TRUE(vc != NULL);
2506 const VideoContentDescription* vcd =
2507 static_cast<const VideoContentDescription*>(vc->description);
2508 ASSERT_FALSE(vcd->codecs().empty());
2509 cricket::VideoCodec vp8 = vcd->codecs()[0];
2510 EXPECT_EQ("VP8", vp8.name);
2511 EXPECT_EQ(120, vp8.id);
2512 cricket::CodecParameterMap::iterator found =
2513 vp8.params.find("x-google-min-bitrate");
2514 ASSERT_TRUE(found != vp8.params.end());
2515 EXPECT_EQ(found->second, "10");
2516 found = vp8.params.find("x-google-max-quantization");
2517 ASSERT_TRUE(found != vp8.params.end());
2518 EXPECT_EQ(found->second, "40");
2519}
2520
2521TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2522 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2523 GetFirstVideoContent(&desc_)->description);
2524
2525 cricket::VideoCodecs codecs = vcd->codecs();
2526 codecs[0].params["x-google-min-bitrate"] = "10";
2527 vcd->set_codecs(codecs);
2528
2529 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2530 jdesc_.session_id(),
2531 jdesc_.session_version()));
2532 std::string message = webrtc::SdpSerialize(jdesc_);
2533 std::string sdp_with_fmtp = kSdpFullString;
2534 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2535 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2536 &sdp_with_fmtp);
2537 EXPECT_EQ(sdp_with_fmtp, message);
2538}
2539
2540TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2541 JsepSessionDescription jdesc_with_icelite(kDummyString);
2542 std::string sdp_with_icelite = kSdpFullString;
2543 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2544 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2545 const cricket::TransportInfo* tinfo1 =
2546 desc->GetTransportInfoByName("audio_content_name");
2547 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2548 const cricket::TransportInfo* tinfo2 =
2549 desc->GetTransportInfoByName("video_content_name");
2550 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2551 InjectAfter(kSessionTime,
2552 "a=ice-lite\r\n",
2553 &sdp_with_icelite);
2554 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2555 desc = jdesc_with_icelite.description();
2556 const cricket::TransportInfo* atinfo =
2557 desc->GetTransportInfoByName("audio_content_name");
2558 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2559 const cricket::TransportInfo* vtinfo =
2560 desc->GetTransportInfoByName("video_content_name");
2561 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2562}
2563
2564// Verifies that the candidates in the input SDP are parsed and serialized
2565// correctly in the output SDP.
2566TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2567 std::string sdp_with_data = kSdpString;
2568 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2569 JsepSessionDescription jdesc_output(kDummyString);
2570
2571 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2572 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2573}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002574
2575TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2576 AddFingerprint();
2577 TransportInfo audio_transport_info =
2578 *(desc_.GetTransportInfoByName(kAudioContentName));
2579 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2580 audio_transport_info.description.connection_role);
2581 audio_transport_info.description.connection_role =
2582 cricket::CONNECTIONROLE_ACTIVE;
2583
2584 TransportInfo video_transport_info =
2585 *(desc_.GetTransportInfoByName(kVideoContentName));
2586 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2587 video_transport_info.description.connection_role);
2588 video_transport_info.description.connection_role =
2589 cricket::CONNECTIONROLE_ACTIVE;
2590
2591 desc_.RemoveTransportInfoByName(kAudioContentName);
2592 desc_.RemoveTransportInfoByName(kVideoContentName);
2593
2594 desc_.AddTransportInfo(audio_transport_info);
2595 desc_.AddTransportInfo(video_transport_info);
2596
2597 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2598 jdesc_.session_id(),
2599 jdesc_.session_version()));
2600 std::string message = webrtc::SdpSerialize(jdesc_);
2601 std::string sdp_with_dtlssetup = kSdpFullString;
2602
2603 // Fingerprint attribute is necessary to add DTLS setup attribute.
2604 InjectAfter(kAttributeIcePwdVoice,
2605 kFingerprint, &sdp_with_dtlssetup);
2606 InjectAfter(kAttributeIcePwdVideo,
2607 kFingerprint, &sdp_with_dtlssetup);
2608 // Now adding |setup| attribute.
2609 InjectAfter(kFingerprint,
2610 "a=setup:active\r\n", &sdp_with_dtlssetup);
2611 EXPECT_EQ(sdp_with_dtlssetup, message);
2612}
2613
2614TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2615 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2616 std::string sdp_with_dtlssetup = kSdpFullString;
2617 InjectAfter(kSessionTime,
2618 "a=setup:actpass\r\n",
2619 &sdp_with_dtlssetup);
2620 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2621 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2622 const cricket::TransportInfo* atinfo =
2623 desc->GetTransportInfoByName("audio_content_name");
2624 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2625 atinfo->description.connection_role);
2626 const cricket::TransportInfo* vtinfo =
2627 desc->GetTransportInfoByName("video_content_name");
2628 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2629 vtinfo->description.connection_role);
2630}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002631
2632// Verifies that the order of the serialized m-lines follows the order of the
2633// ContentInfo in SessionDescription, and vise versa for deserialization.
2634TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2635 JsepSessionDescription jdesc(kDummyString);
2636 const std::string media_content_sdps[3] = {
2637 kSdpAudioString,
2638 kSdpVideoString,
2639 kSdpSctpDataChannelString
2640 };
2641 const cricket::MediaType media_types[3] = {
2642 cricket::MEDIA_TYPE_AUDIO,
2643 cricket::MEDIA_TYPE_VIDEO,
2644 cricket::MEDIA_TYPE_DATA
2645 };
2646
2647 // Verifies all 6 permutations.
2648 for (size_t i = 0; i < 6; ++i) {
2649 size_t media_content_in_sdp[3];
2650 // The index of the first media content.
2651 media_content_in_sdp[0] = i / 2;
2652 // The index of the second media content.
2653 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2654 // The index of the third media content.
2655 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2656
2657 std::string sdp_string = kSdpSessionString;
2658 for (size_t i = 0; i < 3; ++i)
2659 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2660
2661 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2662 cricket::SessionDescription* desc = jdesc.description();
2663 EXPECT_EQ(3u, desc->contents().size());
2664
2665 for (size_t i = 0; i < 3; ++i) {
2666 const cricket::MediaContentDescription* mdesc =
2667 static_cast<const cricket::MediaContentDescription*>(
2668 desc->contents()[i].description);
2669 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2670 }
2671
2672 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2673 EXPECT_EQ(sdp_string, serialized_sdp);
2674 }
2675}