blob: e62294416a8014bb12cb29de9c5203ffc9fd1d3e [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"
160 "a=rtpmap:104 CELT/32000/2\r\n"
161 "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"
227 "a=rtpmap:104 CELT/32000/2\r\n"
228 "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
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000287// draft-ietf-mmusic-sctp-sdp-07
288static const char kSdpSctpDataChannelStringWithSctpPort[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000289 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000290 "a=fmtp:webrtc-datachannel max-message-size=100000\r\n"
291 "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
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297static const char kSdpSctpDataChannelWithCandidatesString[] =
298 "m=application 2345 DTLS/SCTP 5000\r\n"
299 "c=IN IP4 74.125.127.126\r\n"
300 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
301 "generation 2\r\n"
302 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
303 "generation 2\r\n"
304 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
305 "raddr 192.168.1.5 rport 2346 "
306 "generation 2\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000310 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000312static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000313 "v=0\r\n"
314 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
315 "s=-\r\n"
316 "t=0 0\r\n"
317 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000318 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000319 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000321 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000322 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "a=x-google-flag:conference\r\n";
324
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325static const char kSdpSessionString[] =
326 "v=0\r\n"
327 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
328 "s=-\r\n"
329 "t=0 0\r\n"
330 "a=msid-semantic: WMS local_stream\r\n";
331
332static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
335 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
337 "a=mid:audio_content_name\r\n"
338 "a=sendrecv\r\n"
339 "a=rtpmap:111 opus/48000/2\r\n"
340 "a=ssrc:1 cname:stream_1_cname\r\n"
341 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
342 "a=ssrc:1 mslabel:local_stream\r\n"
343 "a=ssrc:1 label:audio_track_id_1\r\n";
344
345static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000346 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000347 "c=IN IP4 0.0.0.0\r\n"
348 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000349 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
350 "a=mid:video_content_name\r\n"
351 "a=sendrecv\r\n"
352 "a=rtpmap:120 VP8/90000\r\n"
353 "a=ssrc:2 cname:stream_1_cname\r\n"
354 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
355 "a=ssrc:2 mslabel:local_stream\r\n"
356 "a=ssrc:2 label:video_track_id_1\r\n";
357
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358
359// One candidate reference string as per W3c spec.
360// candidate:<blah> not a=candidate:<blah>CRLF
361static const char kRawCandidate[] =
362 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
363// One candidate reference string.
364static const char kSdpOneCandidate[] =
365 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
366 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000367
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000368static const char kSdpTcpActiveCandidate[] =
369 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
370 "tcptype active generation 2";
371static const char kSdpTcpPassiveCandidate[] =
372 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
373 "tcptype passive generation 2";
374static const char kSdpTcpSOCandidate[] =
375 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
376 "tcptype so generation 2";
377static const char kSdpTcpInvalidCandidate[] =
378 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
379 "tcptype invalid generation 2";
380
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000381// One candidate reference string with IPV6 address.
382static const char kRawIPV6Candidate[] =
383 "candidate:a0+B/1 1 udp 2130706432 "
384 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385
386// One candidate reference string.
387static const char kSdpOneCandidateOldFormat[] =
388 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
389 " eth0 username user_rtp password password_rtp generation 2\r\n";
390
391// Session id and version
392static const char kSessionId[] = "18446744069414584320";
393static const char kSessionVersion[] = "18446462598732840960";
394
395// Ice options
396static const char kIceOption1[] = "iceoption1";
397static const char kIceOption2[] = "iceoption2";
398static const char kIceOption3[] = "iceoption3";
399
400// Content name
401static const char kAudioContentName[] = "audio_content_name";
402static const char kVideoContentName[] = "video_content_name";
403static const char kDataContentName[] = "data_content_name";
404
405// MediaStream 1
406static const char kStreamLabel1[] = "local_stream_1";
407static const char kStream1Cname[] = "stream_1_cname";
408static const char kAudioTrackId1[] = "audio_track_id_1";
409static const uint32 kAudioTrack1Ssrc = 1;
410static const char kVideoTrackId1[] = "video_track_id_1";
411static const uint32 kVideoTrack1Ssrc = 2;
412static const char kVideoTrackId2[] = "video_track_id_2";
413static const uint32 kVideoTrack2Ssrc = 3;
414
415// MediaStream 2
416static const char kStreamLabel2[] = "local_stream_2";
417static const char kStream2Cname[] = "stream_2_cname";
418static const char kAudioTrackId2[] = "audio_track_id_2";
419static const uint32 kAudioTrack2Ssrc = 4;
420static const char kVideoTrackId3[] = "video_track_id_3";
421static const uint32 kVideoTrack3Ssrc = 5;
422static const uint32 kVideoTrack4Ssrc = 6;
423
424// DataChannel
425static const char kDataChannelLabel[] = "data_channel";
426static const char kDataChannelMsid[] = "data_channeld0";
427static const char kDataChannelCname[] = "data_channel_cname";
428static const uint32 kDataChannelSsrc = 10;
429
430// Candidate
431static const char kDummyMid[] = "dummy_mid";
432static const int kDummyIndex = 123;
433
434// Misc
435static const char kDummyString[] = "dummy";
436
437// Helper functions
438
439static bool SdpDeserialize(const std::string& message,
440 JsepSessionDescription* jdesc) {
441 return webrtc::SdpDeserialize(message, jdesc, NULL);
442}
443
444static bool SdpDeserializeCandidate(const std::string& message,
445 JsepIceCandidate* candidate) {
446 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
447}
448
449// Add some extra |newlines| to the |message| after |line|.
450static void InjectAfter(const std::string& line,
451 const std::string& newlines,
452 std::string* message) {
453 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 tmp.c_str(), tmp.length(), message);
456}
457
458static void Replace(const std::string& line,
459 const std::string& newlines,
460 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 newlines.c_str(), newlines.length(), message);
463}
464
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000465// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
466// message.
467static void ExpectParseFailure(const std::string& bad_sdp,
468 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000471 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000473 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
474}
475
476// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
477static void ExpectParseFailure(const char* good_part, const char* bad_part) {
478 std::string bad_sdp = kSdpFullString;
479 Replace(good_part, bad_part, &bad_sdp);
480 ExpectParseFailure(bad_sdp, bad_part);
481}
482
483// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
484static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
485 const std::string& newlines,
486 const std::string& bad_part) {
487 std::string bad_sdp = kSdpFullString;
488 InjectAfter(injectpoint, newlines, &bad_sdp);
489 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490}
491
492static void ReplaceDirection(cricket::MediaContentDirection direction,
493 std::string* message) {
494 std::string new_direction;
495 switch (direction) {
496 case cricket::MD_INACTIVE:
497 new_direction = "a=inactive";
498 break;
499 case cricket::MD_SENDONLY:
500 new_direction = "a=sendonly";
501 break;
502 case cricket::MD_RECVONLY:
503 new_direction = "a=recvonly";
504 break;
505 case cricket::MD_SENDRECV:
506 default:
507 new_direction = "a=sendrecv";
508 break;
509 }
510 Replace("a=sendrecv", new_direction, message);
511}
512
513static void ReplaceRejected(bool audio_rejected, bool video_rejected,
514 std::string* message) {
515 if (audio_rejected) {
516 Replace("m=audio 2345", "m=audio 0", message);
517 }
518 if (video_rejected) {
519 Replace("m=video 3457", "m=video 0", message);
520 }
521}
522
523// WebRtcSdpTest
524
525class WebRtcSdpTest : public testing::Test {
526 public:
527 WebRtcSdpTest()
528 : jdesc_(kDummyString) {
529 // AudioContentDescription
530 audio_desc_ = CreateAudioContentDescription();
531 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
532 audio_desc_->AddCodec(opus);
533 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
534 audio_desc_->AddCodec(AudioCodec(104, "CELT", 32000, 0, 2, 1));
535 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
536
537 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 new VideoContentDescription());
540 video_desc_ = video.get();
541 StreamParams video_stream1;
542 video_stream1.id = kVideoTrackId1;
543 video_stream1.cname = kStream1Cname;
544 video_stream1.sync_label = kStreamLabel1;
545 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
546 video->AddStream(video_stream1);
547 StreamParams video_stream2;
548 video_stream2.id = kVideoTrackId2;
549 video_stream2.cname = kStream1Cname;
550 video_stream2.sync_label = kStreamLabel1;
551 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
552 video->AddStream(video_stream2);
553 StreamParams video_stream3;
554 video_stream3.id = kVideoTrackId3;
555 video_stream3.cname = kStream2Cname;
556 video_stream3.sync_label = kStreamLabel2;
557 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
558 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
559 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
560 video_stream3.ssrc_groups.push_back(ssrc_group);
561 video->AddStream(video_stream3);
562 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
563 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
564 video->set_protocol(cricket::kMediaProtocolSavpf);
565 video->AddCodec(VideoCodec(
566 120,
567 JsepSessionDescription::kDefaultVideoCodecName,
568 JsepSessionDescription::kMaxVideoCodecWidth,
569 JsepSessionDescription::kMaxVideoCodecHeight,
570 JsepSessionDescription::kDefaultVideoCodecFramerate,
571 JsepSessionDescription::kDefaultVideoCodecPreference));
572
573 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
574 video.release());
575
576 // TransportInfo
577 EXPECT_TRUE(desc_.AddTransportInfo(
578 TransportInfo(kAudioContentName,
579 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000581 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 EXPECT_TRUE(desc_.AddTransportInfo(
583 TransportInfo(kVideoContentName,
584 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000586 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587
588 // v4 host
589 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000591 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000592 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
593 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000595 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000596 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
597 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000599 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000600 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
601 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000603 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000604 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
605 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
607 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000608 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000609 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
610 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000611 cricket::LOCAL_PORT_TYPE,
612 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000614 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
615 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000616 cricket::LOCAL_PORT_TYPE,
617 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000619 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
620 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000621 cricket::LOCAL_PORT_TYPE,
622 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000624 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
625 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000626 cricket::LOCAL_PORT_TYPE,
627 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628
629 // stun
630 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000631 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
632 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000633 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
634 address_stun, kCandidatePriority, "", "",
635 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000636 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 candidate9.set_related_address(rel_address_stun);
638
639 address_stun.SetPort(port_stun++);
640 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000641 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
642 address_stun, kCandidatePriority, "", "",
643 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000644 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 candidate10.set_related_address(rel_address_stun);
646
647 // relay
648 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000650 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
651 address_relay, kCandidatePriority, "", "",
652 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000653 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000655 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
656 address_relay, kCandidatePriority, "", "",
657 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000658 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659
660 // voice
661 candidates_.push_back(candidate1);
662 candidates_.push_back(candidate2);
663 candidates_.push_back(candidate5);
664 candidates_.push_back(candidate6);
665 candidates_.push_back(candidate9);
666 candidates_.push_back(candidate10);
667
668 // video
669 candidates_.push_back(candidate3);
670 candidates_.push_back(candidate4);
671 candidates_.push_back(candidate7);
672 candidates_.push_back(candidate8);
673 candidates_.push_back(candidate11);
674 candidates_.push_back(candidate12);
675
676 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
677 0, candidate1));
678
679 // Set up JsepSessionDescription.
680 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
681 std::string mline_id;
682 int mline_index = 0;
683 for (size_t i = 0; i< candidates_.size(); ++i) {
684 // In this test, the audio m line index will be 0, and the video m line
685 // will be 1.
686 bool is_video = (i > 5);
687 mline_id = is_video ? "video_content_name" : "audio_content_name";
688 mline_index = is_video ? 1 : 0;
689 JsepIceCandidate jice(mline_id,
690 mline_index,
691 candidates_.at(i));
692 jdesc_.AddCandidate(&jice);
693 }
694 }
695
696 AudioContentDescription* CreateAudioContentDescription() {
697 AudioContentDescription* audio = new AudioContentDescription();
698 audio->set_rtcp_mux(true);
699 StreamParams audio_stream1;
700 audio_stream1.id = kAudioTrackId1;
701 audio_stream1.cname = kStream1Cname;
702 audio_stream1.sync_label = kStreamLabel1;
703 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
704 audio->AddStream(audio_stream1);
705 StreamParams audio_stream2;
706 audio_stream2.id = kAudioTrackId2;
707 audio_stream2.cname = kStream2Cname;
708 audio_stream2.sync_label = kStreamLabel2;
709 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
710 audio->AddStream(audio_stream2);
711 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
712 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
713 "dummy_session_params"));
714 audio->set_protocol(cricket::kMediaProtocolSavpf);
715 return audio;
716 }
717
718 template <class MCD>
719 void CompareMediaContentDescription(const MCD* cd1,
720 const MCD* cd2) {
721 // type
722 EXPECT_EQ(cd1->type(), cd1->type());
723
724 // content direction
725 EXPECT_EQ(cd1->direction(), cd2->direction());
726
727 // rtcp_mux
728 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
729
730 // cryptos
731 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
732 if (cd1->cryptos().size() != cd2->cryptos().size()) {
733 ADD_FAILURE();
734 return;
735 }
736 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
737 const CryptoParams c1 = cd1->cryptos().at(i);
738 const CryptoParams c2 = cd2->cryptos().at(i);
739 EXPECT_TRUE(c1.Matches(c2));
740 EXPECT_EQ(c1.key_params, c2.key_params);
741 EXPECT_EQ(c1.session_params, c2.session_params);
742 }
743 // protocol
744 EXPECT_EQ(cd1->protocol(), cd2->protocol());
745
746 // codecs
747 EXPECT_EQ(cd1->codecs(), cd2->codecs());
748
749 // bandwidth
750 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
751
752 // streams
753 EXPECT_EQ(cd1->streams(), cd2->streams());
754
755 // extmap
756 ASSERT_EQ(cd1->rtp_header_extensions().size(),
757 cd2->rtp_header_extensions().size());
758 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
759 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
760 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
761 EXPECT_EQ(ext1.uri, ext2.uri);
762 EXPECT_EQ(ext1.id, ext2.id);
763 }
764
765 // buffered mode latency
766 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
767 }
768
769
770 void CompareSessionDescription(const SessionDescription& desc1,
771 const SessionDescription& desc2) {
772 // Compare content descriptions.
773 if (desc1.contents().size() != desc2.contents().size()) {
774 ADD_FAILURE();
775 return;
776 }
777 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
778 const cricket::ContentInfo& c1 = desc1.contents().at(i);
779 const cricket::ContentInfo& c2 = desc2.contents().at(i);
780 // content name
781 EXPECT_EQ(c1.name, c2.name);
782 // content type
783 // Note, ASSERT will return from the function, but will not stop the test.
784 ASSERT_EQ(c1.type, c2.type);
785
786 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
787 if (IsAudioContent(&c1)) {
788 const AudioContentDescription* acd1 =
789 static_cast<const AudioContentDescription*>(c1.description);
790 const AudioContentDescription* acd2 =
791 static_cast<const AudioContentDescription*>(c2.description);
792 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
793 }
794
795 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
796 if (IsVideoContent(&c1)) {
797 const VideoContentDescription* vcd1 =
798 static_cast<const VideoContentDescription*>(c1.description);
799 const VideoContentDescription* vcd2 =
800 static_cast<const VideoContentDescription*>(c2.description);
801 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
802 }
803
804 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
805 if (IsDataContent(&c1)) {
806 const DataContentDescription* dcd1 =
807 static_cast<const DataContentDescription*>(c1.description);
808 const DataContentDescription* dcd2 =
809 static_cast<const DataContentDescription*>(c2.description);
810 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
811 }
812 }
813
814 // group
815 const cricket::ContentGroups groups1 = desc1.groups();
816 const cricket::ContentGroups groups2 = desc2.groups();
817 EXPECT_EQ(groups1.size(), groups1.size());
818 if (groups1.size() != groups2.size()) {
819 ADD_FAILURE();
820 return;
821 }
822 for (size_t i = 0; i < groups1.size(); ++i) {
823 const cricket::ContentGroup group1 = groups1.at(i);
824 const cricket::ContentGroup group2 = groups2.at(i);
825 EXPECT_EQ(group1.semantics(), group2.semantics());
826 const cricket::ContentNames names1 = group1.content_names();
827 const cricket::ContentNames names2 = group2.content_names();
828 EXPECT_EQ(names1.size(), names2.size());
829 if (names1.size() != names2.size()) {
830 ADD_FAILURE();
831 return;
832 }
833 cricket::ContentNames::const_iterator iter1 = names1.begin();
834 cricket::ContentNames::const_iterator iter2 = names2.begin();
835 while (iter1 != names1.end()) {
836 EXPECT_EQ(*iter1++, *iter2++);
837 }
838 }
839
840 // transport info
841 const cricket::TransportInfos transports1 = desc1.transport_infos();
842 const cricket::TransportInfos transports2 = desc2.transport_infos();
843 EXPECT_EQ(transports1.size(), transports2.size());
844 if (transports1.size() != transports2.size()) {
845 ADD_FAILURE();
846 return;
847 }
848 for (size_t i = 0; i < transports1.size(); ++i) {
849 const cricket::TransportInfo transport1 = transports1.at(i);
850 const cricket::TransportInfo transport2 = transports2.at(i);
851 EXPECT_EQ(transport1.content_name, transport2.content_name);
852 EXPECT_EQ(transport1.description.transport_type,
853 transport2.description.transport_type);
854 EXPECT_EQ(transport1.description.ice_ufrag,
855 transport2.description.ice_ufrag);
856 EXPECT_EQ(transport1.description.ice_pwd,
857 transport2.description.ice_pwd);
858 if (transport1.description.identity_fingerprint) {
859 EXPECT_EQ(*transport1.description.identity_fingerprint,
860 *transport2.description.identity_fingerprint);
861 } else {
862 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
863 transport2.description.identity_fingerprint.get());
864 }
865 EXPECT_EQ(transport1.description.transport_options,
866 transport2.description.transport_options);
867 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
868 transport2.description.candidates));
869 }
870 }
871
872 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
873 EXPECT_EQ(cs1.size(), cs2.size());
874 if (cs1.size() != cs2.size())
875 return false;
876 for (size_t i = 0; i< cs1.size(); ++i) {
877 const Candidate c1 = cs1.at(i);
878 const Candidate c2 = cs2.at(i);
879 EXPECT_TRUE(c1.IsEquivalent(c2));
880 }
881 return true;
882 }
883
884 bool CompareSessionDescription(
885 const JsepSessionDescription& desc1,
886 const JsepSessionDescription& desc2) {
887 EXPECT_EQ(desc1.session_id(), desc2.session_id());
888 EXPECT_EQ(desc1.session_version(), desc2.session_version());
889 CompareSessionDescription(*desc1.description(), *desc2.description());
890 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
891 return false;
892 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
893 const IceCandidateCollection* cc1 = desc1.candidates(i);
894 const IceCandidateCollection* cc2 = desc2.candidates(i);
895 if (cc1->count() != cc2->count())
896 return false;
897 for (size_t j = 0; j < cc1->count(); ++j) {
898 const IceCandidateInterface* c1 = cc1->at(j);
899 const IceCandidateInterface* c2 = cc2->at(j);
900 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
901 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
902 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
903 }
904 }
905 return true;
906 }
907
908 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
909 // them with invalid keywords so that the parser will just ignore them.
910 bool RemoveCandidateUfragPwd(std::string* sdp) {
911 const char ice_ufrag[] = "a=ice-ufrag";
912 const char ice_ufragx[] = "a=xice-ufrag";
913 const char ice_pwd[] = "a=ice-pwd";
914 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000915 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 ice_pwdx, strlen(ice_pwdx), sdp);
919 return true;
920 }
921
922 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
923 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
924 const std::string& ufrag, const std::string& pwd) {
925 std::string content_name;
926 if (mline_index == 0) {
927 content_name = kAudioContentName;
928 } else if (mline_index == 1) {
929 content_name = kVideoContentName;
930 } else {
931 ASSERT(false);
932 }
933 TransportInfo transport_info(
934 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000935 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 SessionDescription* desc =
937 const_cast<SessionDescription*>(jdesc->description());
938 desc->RemoveTransportInfoByName(content_name);
939 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
940 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
941 const IceCandidateCollection* cc = jdesc_.candidates(i);
942 for (size_t j = 0; j < cc->count(); ++j) {
943 if (cc->at(j)->sdp_mline_index() == mline_index) {
944 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
945 ufrag);
946 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
947 pwd);
948 }
949 }
950 }
951 return true;
952 }
953
954 void AddIceOptions(const std::string& content_name,
955 const std::vector<std::string>& transport_options) {
956 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
957 cricket::TransportInfo transport_info =
958 *(desc_.GetTransportInfoByName(content_name));
959 desc_.RemoveTransportInfoByName(content_name);
960 transport_info.description.transport_options = transport_options;
961 desc_.AddTransportInfo(transport_info);
962 }
963
964 void AddFingerprint() {
965 desc_.RemoveTransportInfoByName(kAudioContentName);
966 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000967 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 kIdentityDigest,
969 sizeof(kIdentityDigest));
970 EXPECT_TRUE(desc_.AddTransportInfo(
971 TransportInfo(kAudioContentName,
972 TransportDescription(NS_JINGLE_ICE_UDP,
973 std::vector<std::string>(),
974 kCandidateUfragVoice,
975 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000976 cricket::ICEMODE_FULL,
977 cricket::CONNECTIONROLE_NONE,
978 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_TRUE(desc_.AddTransportInfo(
980 TransportInfo(kVideoContentName,
981 TransportDescription(NS_JINGLE_ICE_UDP,
982 std::vector<std::string>(),
983 kCandidateUfragVideo,
984 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000985 cricket::ICEMODE_FULL,
986 cricket::CONNECTIONROLE_NONE,
987 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989
990 void AddExtmap() {
991 audio_desc_ = static_cast<AudioContentDescription*>(
992 audio_desc_->Copy());
993 video_desc_ = static_cast<VideoContentDescription*>(
994 video_desc_->Copy());
995 audio_desc_->AddRtpHeaderExtension(
996 RtpHeaderExtension(kExtmapUri, kExtmapId));
997 video_desc_->AddRtpHeaderExtension(
998 RtpHeaderExtension(kExtmapUri, kExtmapId));
999 desc_.RemoveContentByName(kAudioContentName);
1000 desc_.RemoveContentByName(kVideoContentName);
1001 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1002 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1003 }
1004
1005 void RemoveCryptos() {
1006 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1007 video_desc_->set_cryptos(std::vector<CryptoParams>());
1008 }
1009
1010 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1011 audio_desc_->set_direction(direction);
1012 video_desc_->set_direction(direction);
1013 std::string new_sdp = kSdpFullString;
1014 ReplaceDirection(direction, &new_sdp);
1015
1016 if (!jdesc_.Initialize(desc_.Copy(),
1017 jdesc_.session_id(),
1018 jdesc_.session_version())) {
1019 return false;
1020 }
1021 std::string message = webrtc::SdpSerialize(jdesc_);
1022 EXPECT_EQ(new_sdp, message);
1023 return true;
1024 }
1025
1026 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1027 audio_desc_ = static_cast<AudioContentDescription*>(
1028 audio_desc_->Copy());
1029 video_desc_ = static_cast<VideoContentDescription*>(
1030 video_desc_->Copy());
1031 desc_.RemoveContentByName(kAudioContentName);
1032 desc_.RemoveContentByName(kVideoContentName);
1033 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1034 audio_desc_);
1035 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1036 video_desc_);
1037 std::string new_sdp = kSdpFullString;
1038 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1039
1040 if (!jdesc_.Initialize(desc_.Copy(),
1041 jdesc_.session_id(),
1042 jdesc_.session_version())) {
1043 return false;
1044 }
1045 std::string message = webrtc::SdpSerialize(jdesc_);
1046 EXPECT_EQ(new_sdp, message);
1047 return true;
1048 }
1049
1050 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 new DataContentDescription());
1053 data_desc_ = data.get();
1054 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001055 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1056 cricket::kGoogleSctpDataCodecName, 0);
1057 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1058 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1060 EXPECT_TRUE(desc_.AddTransportInfo(
1061 TransportInfo(kDataContentName,
1062 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001064 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 }
1066
1067 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001068 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 new DataContentDescription());
1070 data_desc_ = data.get();
1071
1072 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1073 StreamParams data_stream;
1074 data_stream.id = kDataChannelMsid;
1075 data_stream.cname = kDataChannelCname;
1076 data_stream.sync_label = kDataChannelLabel;
1077 data_stream.ssrcs.push_back(kDataChannelSsrc);
1078 data_desc_->AddStream(data_stream);
1079 data_desc_->AddCrypto(CryptoParams(
1080 1, "AES_CM_128_HMAC_SHA1_80",
1081 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1082 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1083 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1084 EXPECT_TRUE(desc_.AddTransportInfo(
1085 TransportInfo(kDataContentName,
1086 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001088 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 }
1090
1091 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1092 std::string new_sdp = kSdpFullString;
1093 ReplaceDirection(direction, &new_sdp);
1094 JsepSessionDescription new_jdesc(kDummyString);
1095
1096 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1097
1098 audio_desc_->set_direction(direction);
1099 video_desc_->set_direction(direction);
1100 if (!jdesc_.Initialize(desc_.Copy(),
1101 jdesc_.session_id(),
1102 jdesc_.session_version())) {
1103 return false;
1104 }
1105 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1106 return true;
1107 }
1108
1109 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1110 std::string new_sdp = kSdpFullString;
1111 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1112 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1113
1114 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1115 audio_desc_ = static_cast<AudioContentDescription*>(
1116 audio_desc_->Copy());
1117 video_desc_ = static_cast<VideoContentDescription*>(
1118 video_desc_->Copy());
1119 desc_.RemoveContentByName(kAudioContentName);
1120 desc_.RemoveContentByName(kVideoContentName);
1121 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1122 audio_desc_);
1123 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1124 video_desc_);
1125 if (!jdesc_.Initialize(desc_.Copy(),
1126 jdesc_.session_id(),
1127 jdesc_.session_version())) {
1128 return false;
1129 }
1130 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1131 return true;
1132 }
1133
1134 void TestDeserializeExtmap(bool session_level, bool media_level) {
1135 AddExtmap();
1136 JsepSessionDescription new_jdesc("dummy");
1137 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1138 jdesc_.session_id(),
1139 jdesc_.session_version()));
1140 JsepSessionDescription jdesc_with_extmap("dummy");
1141 std::string sdp_with_extmap = kSdpString;
1142 if (session_level) {
1143 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1144 &sdp_with_extmap);
1145 }
1146 if (media_level) {
1147 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1148 &sdp_with_extmap);
1149 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1150 &sdp_with_extmap);
1151 }
1152 // The extmap can't be present at the same time in both session level and
1153 // media level.
1154 if (session_level && media_level) {
1155 SdpParseError error;
1156 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1157 &jdesc_with_extmap, &error));
1158 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1159 } else {
1160 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1161 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1162 }
1163 }
1164
1165 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1166 const std::string& name, int expected_value) {
1167 cricket::CodecParameterMap::const_iterator found = params.find(name);
1168 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001169 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 }
1171
1172 void TestDeserializeCodecParams(const CodecParams& params,
1173 JsepSessionDescription* jdesc_output) {
1174 std::string sdp =
1175 "v=0\r\n"
1176 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1177 "s=-\r\n"
1178 "t=0 0\r\n"
1179 // Include semantics for WebRTC Media Streams since it is supported by
1180 // this parser, and will be added to the SDP when serializing a session
1181 // description.
1182 "a=msid-semantic: WMS\r\n"
1183 // Pl type 111 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001184 "m=audio 9 RTP/SAVPF 111 104 103 102\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185 // Pltype 111 listed before 103 and 104 in the map.
1186 "a=rtpmap:111 opus/48000/2\r\n"
1187 // Pltype 103 listed before 104.
1188 "a=rtpmap:103 ISAC/16000\r\n"
1189 "a=rtpmap:104 CELT/32000/2\r\n"
1190 "a=rtpmap:102 ISAC/32000/1\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001191 "a=fmtp:111 0-15,66,70\r\n"
1192 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001194 os << "minptime=" << params.min_ptime
1195 << "; stereo=" << params.stereo
1196 << "; sprop-stereo=" << params.sprop_stereo
1197 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001198 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 << "a=ptime:" << params.ptime << "\r\n"
1200 << "a=maxptime:" << params.max_ptime << "\r\n";
1201 sdp += os.str();
1202
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001203 os.clear();
1204 os.str("");
1205 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001206 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001207 << "a=rtpmap:99 VP8/90000\r\n"
1208 << "a=rtpmap:95 RTX/90000\r\n"
1209 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1210 sdp += os.str();
1211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 // Deserialize
1213 SdpParseError error;
1214 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1215
1216 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1217 ASSERT_TRUE(ac != NULL);
1218 const AudioContentDescription* acd =
1219 static_cast<const AudioContentDescription*>(ac->description);
1220 ASSERT_FALSE(acd->codecs().empty());
1221 cricket::AudioCodec opus = acd->codecs()[0];
1222 EXPECT_EQ("opus", opus.name);
1223 EXPECT_EQ(111, opus.id);
1224 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1225 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1226 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1227 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001228 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1229 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1231 cricket::AudioCodec codec = acd->codecs()[i];
1232 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1233 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1234 if (codec.name == "ISAC") {
1235 if (codec.clockrate == 16000) {
1236 EXPECT_EQ(32000, codec.bitrate);
1237 } else {
1238 EXPECT_EQ(56000, codec.bitrate);
1239 }
1240 }
1241 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001242
1243 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1244 ASSERT_TRUE(vc != NULL);
1245 const VideoContentDescription* vcd =
1246 static_cast<const VideoContentDescription*>(vc->description);
1247 ASSERT_FALSE(vcd->codecs().empty());
1248 cricket::VideoCodec vp8 = vcd->codecs()[0];
1249 EXPECT_EQ("VP8", vp8.name);
1250 EXPECT_EQ(99, vp8.id);
1251 cricket::VideoCodec rtx = vcd->codecs()[1];
1252 EXPECT_EQ("RTX", rtx.name);
1253 EXPECT_EQ(95, rtx.id);
1254 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 }
1256
1257 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1258 bool use_wildcard) {
1259 std::string sdp =
1260 "v=0\r\n"
1261 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1262 "s=-\r\n"
1263 "t=0 0\r\n"
1264 // Include semantics for WebRTC Media Streams since it is supported by
1265 // this parser, and will be added to the SDP when serializing a session
1266 // description.
1267 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001268 "m=audio 9 RTP/SAVPF 111\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 "a=rtpmap:111 opus/48000/2\r\n"
1270 "a=rtcp-fb:111 nack\r\n"
1271 "m=video 3457 RTP/SAVPF 101\r\n"
1272 "a=rtpmap:101 VP8/90000\r\n"
1273 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001274 "a=rtcp-fb:101 nack pli\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 "a=rtcp-fb:101 goog-remb\r\n"
1276 "a=rtcp-fb:101 ccm fir\r\n";
1277 std::ostringstream os;
1278 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1279 sdp += os.str();
1280 // Deserialize
1281 SdpParseError error;
1282 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1283 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1284 ASSERT_TRUE(ac != NULL);
1285 const AudioContentDescription* acd =
1286 static_cast<const AudioContentDescription*>(ac->description);
1287 ASSERT_FALSE(acd->codecs().empty());
1288 cricket::AudioCodec opus = acd->codecs()[0];
1289 EXPECT_EQ(111, opus.id);
1290 EXPECT_TRUE(opus.HasFeedbackParam(
1291 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1292 cricket::kParamValueEmpty)));
1293
1294 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1295 ASSERT_TRUE(vc != NULL);
1296 const VideoContentDescription* vcd =
1297 static_cast<const VideoContentDescription*>(vc->description);
1298 ASSERT_FALSE(vcd->codecs().empty());
1299 cricket::VideoCodec vp8 = vcd->codecs()[0];
1300 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1301 vp8.name.c_str());
1302 EXPECT_EQ(101, vp8.id);
1303 EXPECT_TRUE(vp8.HasFeedbackParam(
1304 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1305 cricket::kParamValueEmpty)));
1306 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001307 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1308 cricket::kRtcpFbNackParamPli)));
1309 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1311 cricket::kParamValueEmpty)));
1312 EXPECT_TRUE(vp8.HasFeedbackParam(
1313 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1314 cricket::kRtcpFbCcmParamFir)));
1315 }
1316
1317 // Two SDP messages can mean the same thing but be different strings, e.g.
1318 // some of the lines can be serialized in different order.
1319 // However, a deserialized description can be compared field by field and has
1320 // no order. If deserializer has already been tested, serializing then
1321 // deserializing and comparing JsepSessionDescription will test
1322 // the serializer sufficiently.
1323 void TestSerialize(const JsepSessionDescription& jdesc) {
1324 std::string message = webrtc::SdpSerialize(jdesc);
1325 JsepSessionDescription jdesc_output_des(kDummyString);
1326 SdpParseError error;
1327 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1328 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1329 }
1330
1331 protected:
1332 SessionDescription desc_;
1333 AudioContentDescription* audio_desc_;
1334 VideoContentDescription* video_desc_;
1335 DataContentDescription* data_desc_;
1336 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001337 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 JsepSessionDescription jdesc_;
1339};
1340
1341void TestMismatch(const std::string& string1, const std::string& string2) {
1342 int position = 0;
1343 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1344 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001345 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 break;
1347 }
1348 }
1349 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1350 << " character\n"
1351 << " 1: " << string1.substr(position, 20) << "\n"
1352 << " 2: " << string2.substr(position, 20) << "\n";
1353}
1354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1356 // SessionDescription with desc and candidates.
1357 std::string message = webrtc::SdpSerialize(jdesc_);
1358 TestMismatch(std::string(kSdpFullString), message);
1359}
1360
1361TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1362 JsepSessionDescription jdesc_empty(kDummyString);
1363 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1364}
1365
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001366// This tests serialization of SDP with only IPv6 candidates and verifies that
1367// IPv6 is used as default address in c line according to preference.
1368TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1369 // Only test 1 m line.
1370 desc_.RemoveContentByName("video_content_name");
1371 // Stun has a high preference than local host.
1372 cricket::Candidate candidate1(
1373 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1374 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1375 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1376 cricket::Candidate candidate2(
1377 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1378 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1379 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1380 JsepSessionDescription jdesc(kDummyString);
1381 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1382
1383 // Only add the candidates to audio m line.
1384 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1385 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1386 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1387 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1388 std::string message = webrtc::SdpSerialize(jdesc);
1389
1390 // Audio line should have a c line like this one.
1391 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1392 // Shouldn't have a IP4 c line.
1393 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1394}
1395
1396// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1397// verifies that IPv4 is used as default address in c line even if the
1398// preference of IPv4 is lower.
1399TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1400 // Only test 1 m line.
1401 desc_.RemoveContentByName("video_content_name");
1402 cricket::Candidate candidate_v4(
1403 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1404 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1405 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1406 cricket::Candidate candidate_v6(
1407 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1408 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1409 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1410 JsepSessionDescription jdesc(kDummyString);
1411 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1412
1413 // Only add the candidates to audio m line.
1414 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1415 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1416 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1417 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1418 std::string message = webrtc::SdpSerialize(jdesc);
1419
1420 // Audio line should have a c line like this one.
1421 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1422 // Shouldn't have a IP6 c line.
1423 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1424}
1425
1426// This tests serialization of SDP with both UDP and TCP candidates and
1427// verifies that UDP is used as default address in c line even if the
1428// preference of UDP is lower.
1429TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1430 // Only test 1 m line.
1431 desc_.RemoveContentByName("video_content_name");
1432 // Stun has a high preference than local host.
1433 cricket::Candidate candidate1(
1434 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1435 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1436 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1437 cricket::Candidate candidate2(
1438 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1439 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1440 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1441 kCandidateFoundation1);
1442 JsepSessionDescription jdesc(kDummyString);
1443 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1444
1445 // Only add the candidates to audio m line.
1446 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1447 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1448 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1449 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1450 std::string message = webrtc::SdpSerialize(jdesc);
1451
1452 // Audio line should have a c line like this one.
1453 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1454 std::string::npos);
1455 // Shouldn't have a IP4 c line.
1456 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1457}
1458
1459// This tests serialization of SDP with only TCP candidates and verifies that
1460// null IPv4 is used as default address in c line.
1461TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1462 // Only test 1 m line.
1463 desc_.RemoveContentByName("video_content_name");
1464 // Stun has a high preference than local host.
1465 cricket::Candidate candidate1(
1466 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1467 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1468 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1469 cricket::Candidate candidate2(
1470 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1471 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1472 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1473 JsepSessionDescription jdesc(kDummyString);
1474 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1475
1476 // Only add the candidates to audio m line.
1477 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1478 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1479 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1480 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1481 std::string message = webrtc::SdpSerialize(jdesc);
1482
1483 // Audio line should have a c line like this one when no any default exists.
1484 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1485}
1486
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1488// the case in a DTLS offer.
1489TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1490 AddFingerprint();
1491 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1492 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1493 kSessionId, kSessionVersion));
1494 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1495
1496 std::string sdp_with_fingerprint = kSdpString;
1497 InjectAfter(kAttributeIcePwdVoice,
1498 kFingerprint, &sdp_with_fingerprint);
1499 InjectAfter(kAttributeIcePwdVideo,
1500 kFingerprint, &sdp_with_fingerprint);
1501
1502 EXPECT_EQ(sdp_with_fingerprint, message);
1503}
1504
1505// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1506// be the case in a DTLS answer.
1507TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1508 AddFingerprint();
1509 RemoveCryptos();
1510 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1511 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1512 kSessionId, kSessionVersion));
1513 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1514
1515 std::string sdp_with_fingerprint = kSdpString;
1516 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1517 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
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
1526TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1527 // JsepSessionDescription with desc but without candidates.
1528 JsepSessionDescription jdesc_no_candidates(kDummyString);
1529 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1530 kSessionId, kSessionVersion));
1531 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1532 EXPECT_EQ(std::string(kSdpString), message);
1533}
1534
1535TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1536 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1537 group.AddContentName(kAudioContentName);
1538 group.AddContentName(kVideoContentName);
1539 desc_.AddGroup(group);
1540 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1541 jdesc_.session_id(),
1542 jdesc_.session_version()));
1543 std::string message = webrtc::SdpSerialize(jdesc_);
1544 std::string sdp_with_bundle = kSdpFullString;
1545 InjectAfter(kSessionTime,
1546 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1547 &sdp_with_bundle);
1548 EXPECT_EQ(sdp_with_bundle, message);
1549}
1550
1551TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1552 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1553 GetFirstVideoContent(&desc_)->description);
1554 vcd->set_bandwidth(100 * 1000);
1555 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1556 GetFirstAudioContent(&desc_)->description);
1557 acd->set_bandwidth(50 * 1000);
1558 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1559 jdesc_.session_id(),
1560 jdesc_.session_version()));
1561 std::string message = webrtc::SdpSerialize(jdesc_);
1562 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001563 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 "b=AS:100\r\n",
1565 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001566 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 "b=AS:50\r\n",
1568 &sdp_with_bandwidth);
1569 EXPECT_EQ(sdp_with_bandwidth, message);
1570}
1571
1572TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1573 std::vector<std::string> transport_options;
1574 transport_options.push_back(kIceOption1);
1575 transport_options.push_back(kIceOption3);
1576 AddIceOptions(kAudioContentName, transport_options);
1577 transport_options.clear();
1578 transport_options.push_back(kIceOption2);
1579 transport_options.push_back(kIceOption3);
1580 AddIceOptions(kVideoContentName, transport_options);
1581 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1582 jdesc_.session_id(),
1583 jdesc_.session_version()));
1584 std::string message = webrtc::SdpSerialize(jdesc_);
1585 std::string sdp_with_ice_options = kSdpFullString;
1586 InjectAfter(kAttributeIcePwdVoice,
1587 "a=ice-options:iceoption1 iceoption3\r\n",
1588 &sdp_with_ice_options);
1589 InjectAfter(kAttributeIcePwdVideo,
1590 "a=ice-options:iceoption2 iceoption3\r\n",
1591 &sdp_with_ice_options);
1592 EXPECT_EQ(sdp_with_ice_options, message);
1593}
1594
1595TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1596 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1597}
1598
1599TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1600 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1601}
1602
1603TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1604 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1605}
1606
1607TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1608 EXPECT_TRUE(TestSerializeRejected(true, false));
1609}
1610
1611TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1612 EXPECT_TRUE(TestSerializeRejected(false, true));
1613}
1614
1615TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1616 EXPECT_TRUE(TestSerializeRejected(true, true));
1617}
1618
1619TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1620 AddRtpDataChannel();
1621 JsepSessionDescription jsep_desc(kDummyString);
1622
1623 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1624 std::string message = webrtc::SdpSerialize(jsep_desc);
1625
1626 std::string expected_sdp = kSdpString;
1627 expected_sdp.append(kSdpRtpDataChannelString);
1628 EXPECT_EQ(expected_sdp, message);
1629}
1630
1631TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1632 AddSctpDataChannel();
1633 JsepSessionDescription jsep_desc(kDummyString);
1634
1635 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1636 std::string message = webrtc::SdpSerialize(jsep_desc);
1637
1638 std::string expected_sdp = kSdpString;
1639 expected_sdp.append(kSdpSctpDataChannelString);
1640 EXPECT_EQ(message, expected_sdp);
1641}
1642
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001643TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1644 AddSctpDataChannel();
1645 JsepSessionDescription jsep_desc(kDummyString);
1646
1647 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1648 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1649 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1650
1651 const int kNewPort = 1234;
1652 cricket::DataCodec codec(
1653 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1654 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1655 dcdesc->AddOrReplaceCodec(codec);
1656
1657 std::string message = webrtc::SdpSerialize(jsep_desc);
1658
1659 std::string expected_sdp = kSdpString;
1660 expected_sdp.append(kSdpSctpDataChannelString);
1661
1662 char default_portstr[16];
1663 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001664 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001665 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001666 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1667 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001668 new_portstr, strlen(new_portstr),
1669 &expected_sdp);
1670
1671 EXPECT_EQ(expected_sdp, message);
1672}
1673
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001674TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1675 AddRtpDataChannel();
1676 data_desc_->set_bandwidth(100*1000);
1677 JsepSessionDescription jsep_desc(kDummyString);
1678
1679 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1680 std::string message = webrtc::SdpSerialize(jsep_desc);
1681
1682 std::string expected_sdp = kSdpString;
1683 expected_sdp.append(kSdpRtpDataChannelString);
1684 // We want to test that serializing data content ignores bandwidth
1685 // settings (it should always be the default). Thus, we don't do
1686 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001687 // TODO(pthatcher): We need to temporarily allow the SDP to control
1688 // this for backwards-compatibility. Once we don't need that any
1689 // more, remove this.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001690 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 +00001691 "b=AS:100\r\n",
1692 &expected_sdp);
1693 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001694}
1695
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1697 AddExtmap();
1698 JsepSessionDescription desc_with_extmap("dummy");
1699 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1700 kSessionId, kSessionVersion));
1701 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1702
1703 std::string sdp_with_extmap = kSdpString;
1704 InjectAfter("a=mid:audio_content_name\r\n",
1705 kExtmap, &sdp_with_extmap);
1706 InjectAfter("a=mid:video_content_name\r\n",
1707 kExtmap, &sdp_with_extmap);
1708
1709 EXPECT_EQ(sdp_with_extmap, message);
1710}
1711
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001712TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1713 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1714 GetFirstVideoContent(&desc_)->description);
1715 vcd->set_buffered_mode_latency(128);
1716
1717 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1718 jdesc_.session_id(),
1719 jdesc_.session_version()));
1720 std::string message = webrtc::SdpSerialize(jdesc_);
1721 std::string sdp_with_buffer_latency = kSdpFullString;
1722 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1723 "a=x-google-buffer-latency:128\r\n",
1724 &sdp_with_buffer_latency);
1725 EXPECT_EQ(sdp_with_buffer_latency, message);
1726}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727
1728TEST_F(WebRtcSdpTest, SerializeCandidates) {
1729 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001730 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731}
1732
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001733// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1734// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001735TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001736 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001737 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1738 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1739 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001740 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1741 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1742 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1743
1744 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1745 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1746}
1747
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1749 JsepSessionDescription jdesc(kDummyString);
1750 // Deserialize
1751 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1752 // Verify
1753 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1754}
1755
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001756TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1757 JsepSessionDescription jdesc(kDummyString);
1758 const char kSdpWithoutMline[] =
1759 "v=0\r\n"
1760 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1761 "s=-\r\n"
1762 "t=0 0\r\n"
1763 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1764 // Deserialize
1765 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1766 EXPECT_EQ(0u, jdesc.description()->contents().size());
1767}
1768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1770 JsepSessionDescription jdesc(kDummyString);
1771 std::string sdp_without_carriage_return = kSdpFullString;
1772 Replace("\r\n", "\n", &sdp_without_carriage_return);
1773 // Deserialize
1774 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1775 // Verify
1776 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1777}
1778
1779TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1780 // SessionDescription with desc but without candidates.
1781 JsepSessionDescription jdesc_no_candidates(kDummyString);
1782 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1783 kSessionId, kSessionVersion));
1784 JsepSessionDescription new_jdesc(kDummyString);
1785 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1786 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1787}
1788
1789TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1790 static const char kSdpNoRtpmapString[] =
1791 "v=0\r\n"
1792 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1793 "s=-\r\n"
1794 "t=0 0\r\n"
1795 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1796 // Codec that doesn't appear in the m= line will be ignored.
1797 "a=rtpmap:104 CELT/32000/2\r\n"
1798 // The rtpmap line for static payload codec is optional.
1799 "a=rtpmap:18 G729/16000\r\n"
1800 "a=rtpmap:103 ISAC/16000\r\n";
1801
1802 JsepSessionDescription jdesc(kDummyString);
1803 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1804 cricket::AudioContentDescription* audio =
1805 static_cast<AudioContentDescription*>(
1806 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1807 AudioCodecs ref_codecs;
1808 // The codecs in the AudioContentDescription will be sorted by preference.
1809 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1810 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1811 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1812 EXPECT_EQ(ref_codecs, audio->codecs());
1813}
1814
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001815TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1816 static const char kSdpNoRtpmapString[] =
1817 "v=0\r\n"
1818 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1819 "s=-\r\n"
1820 "t=0 0\r\n"
1821 "m=audio 49232 RTP/AVP 18 103\r\n"
1822 "a=fmtp:18 annexb=yes\r\n"
1823 "a=rtpmap:103 ISAC/16000\r\n";
1824
1825 JsepSessionDescription jdesc(kDummyString);
1826 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1827 cricket::AudioContentDescription* audio =
1828 static_cast<AudioContentDescription*>(
1829 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1830
1831 cricket::AudioCodec g729 = audio->codecs()[0];
1832 EXPECT_EQ("G729", g729.name);
1833 EXPECT_EQ(8000, g729.clockrate);
1834 EXPECT_EQ(18, g729.id);
1835 cricket::CodecParameterMap::iterator found =
1836 g729.params.find("annexb");
1837 ASSERT_TRUE(found != g729.params.end());
1838 EXPECT_EQ(found->second, "yes");
1839
1840 cricket::AudioCodec isac = audio->codecs()[1];
1841 EXPECT_EQ("ISAC", isac.name);
1842 EXPECT_EQ(103, isac.id);
1843 EXPECT_EQ(16000, isac.clockrate);
1844}
1845
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846// Ensure that we can deserialize SDP with a=fingerprint properly.
1847TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1848 // Add a DTLS a=fingerprint attribute to our session description.
1849 AddFingerprint();
1850 JsepSessionDescription new_jdesc(kDummyString);
1851 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1852 jdesc_.session_id(),
1853 jdesc_.session_version()));
1854
1855 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1856 std::string sdp_with_fingerprint = kSdpString;
1857 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1858 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1859 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1860 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1861}
1862
1863TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1864 JsepSessionDescription jdesc_with_bundle(kDummyString);
1865 std::string sdp_with_bundle = kSdpFullString;
1866 InjectAfter(kSessionTime,
1867 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1868 &sdp_with_bundle);
1869 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1870 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1871 group.AddContentName(kAudioContentName);
1872 group.AddContentName(kVideoContentName);
1873 desc_.AddGroup(group);
1874 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1875 jdesc_.session_id(),
1876 jdesc_.session_version()));
1877 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1878}
1879
1880TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1881 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1882 std::string sdp_with_bandwidth = kSdpFullString;
1883 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1884 "b=AS:100\r\n",
1885 &sdp_with_bandwidth);
1886 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1887 "b=AS:50\r\n",
1888 &sdp_with_bandwidth);
1889 EXPECT_TRUE(
1890 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1891 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1892 GetFirstVideoContent(&desc_)->description);
1893 vcd->set_bandwidth(100 * 1000);
1894 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1895 GetFirstAudioContent(&desc_)->description);
1896 acd->set_bandwidth(50 * 1000);
1897 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1898 jdesc_.session_id(),
1899 jdesc_.session_version()));
1900 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1901}
1902
1903TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1904 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1905 std::string sdp_with_ice_options = kSdpFullString;
1906 InjectAfter(kSessionTime,
1907 "a=ice-options:iceoption3\r\n",
1908 &sdp_with_ice_options);
1909 InjectAfter(kAttributeIcePwdVoice,
1910 "a=ice-options:iceoption1\r\n",
1911 &sdp_with_ice_options);
1912 InjectAfter(kAttributeIcePwdVideo,
1913 "a=ice-options:iceoption2\r\n",
1914 &sdp_with_ice_options);
1915 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1916 std::vector<std::string> transport_options;
1917 transport_options.push_back(kIceOption3);
1918 transport_options.push_back(kIceOption1);
1919 AddIceOptions(kAudioContentName, transport_options);
1920 transport_options.clear();
1921 transport_options.push_back(kIceOption3);
1922 transport_options.push_back(kIceOption2);
1923 AddIceOptions(kVideoContentName, transport_options);
1924 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1925 jdesc_.session_id(),
1926 jdesc_.session_version()));
1927 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1928}
1929
1930TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1931 // Remove the original ice-ufrag and ice-pwd
1932 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1933 std::string sdp_with_ufrag_pwd = kSdpFullString;
1934 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1935 // Add session level ufrag and pwd
1936 InjectAfter(kSessionTime,
1937 "a=ice-pwd:session+level+icepwd\r\n"
1938 "a=ice-ufrag:session+level+iceufrag\r\n",
1939 &sdp_with_ufrag_pwd);
1940 // Add media level ufrag and pwd for audio
1941 InjectAfter("a=mid:audio_content_name\r\n",
1942 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1943 &sdp_with_ufrag_pwd);
1944 // Update the candidate ufrag and pwd to the expected ones.
1945 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1946 "media+level+iceufrag", "media+level+icepwd"));
1947 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1948 "session+level+iceufrag", "session+level+icepwd"));
1949 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1950 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1951}
1952
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001953TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1954 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1955 std::string sdp_with_buffer_latency = kSdpFullString;
1956 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1957 "a=x-google-buffer-latency:128\r\n",
1958 &sdp_with_buffer_latency);
1959
1960 EXPECT_TRUE(
1961 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1962 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1963 GetFirstVideoContent(&desc_)->description);
1964 vcd->set_buffered_mode_latency(128);
1965 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1966 jdesc_.session_id(),
1967 jdesc_.session_version()));
1968 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1969}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970
1971TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1972 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1973}
1974
1975TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1976 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1977}
1978
1979TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1980 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1981}
1982
1983TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1984 EXPECT_TRUE(TestDeserializeRejected(true, false));
1985}
1986
1987TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1988 EXPECT_TRUE(TestDeserializeRejected(false, true));
1989}
1990
1991TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1992 EXPECT_TRUE(TestDeserializeRejected(true, true));
1993}
1994
1995// Tests that we can still handle the sdp uses mslabel and label instead of
1996// msid for backward compatibility.
1997TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1998 JsepSessionDescription jdesc(kDummyString);
1999 std::string sdp_without_msid = kSdpFullString;
2000 Replace("msid", "xmsid", &sdp_without_msid);
2001 // Deserialize
2002 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2003 // Verify
2004 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2005}
2006
2007TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2008 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2009
2010 std::string sdp = kSdpOneCandidate;
2011 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2012 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2013 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2014 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2015
2016 // Candidate line without generation extension.
2017 sdp = kSdpOneCandidate;
2018 Replace(" generation 2", "", &sdp);
2019 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2020 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2021 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2022 Candidate expected = jcandidate_->candidate();
2023 expected.set_generation(0);
2024 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2025
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002026 sdp = kSdpTcpActiveCandidate;
2027 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2028 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002029 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002030 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2031 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2032 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002033 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2034 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2035 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2036 jcandidate_template->candidate()));
2037 sdp = kSdpTcpPassiveCandidate;
2038 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2039 sdp = kSdpTcpSOCandidate;
2040 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041}
2042
2043// This test verifies the deserialization of candidate-attribute
2044// as per RFC 5245. Candiate-attribute will be of the format
2045// candidate:<blah>. This format will be used when candidates
2046// are trickled.
2047TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2048 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2049
2050 std::string candidate_attribute = kRawCandidate;
2051 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2052 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2053 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2054 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2055 EXPECT_EQ(2u, jcandidate.candidate().generation());
2056
2057 // Candidate line without generation extension.
2058 candidate_attribute = kRawCandidate;
2059 Replace(" generation 2", "", &candidate_attribute);
2060 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2061 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2062 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2063 Candidate expected = jcandidate_->candidate();
2064 expected.set_generation(0);
2065 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2066
2067 // Candidate line without candidate:
2068 candidate_attribute = kRawCandidate;
2069 Replace("candidate:", "", &candidate_attribute);
2070 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2071
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002072 // Candidate line with IPV6 address.
2073 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2074}
2075
2076// This test verifies that the deserialization of an invalid candidate string
2077// fails.
2078TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2079 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2080
2081 std::string candidate_attribute = kRawCandidate;
2082 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002084
2085 candidate_attribute = kSdpOneCandidate;
2086 candidate_attribute.replace(0, 1, "x");
2087 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2088
2089 candidate_attribute = kRawCandidate;
2090 candidate_attribute.append("\r\n");
2091 candidate_attribute.append(kRawCandidate);
2092 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2093
2094 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2098 AddRtpDataChannel();
2099 JsepSessionDescription jdesc(kDummyString);
2100 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2101
2102 std::string sdp_with_data = kSdpString;
2103 sdp_with_data.append(kSdpRtpDataChannelString);
2104 JsepSessionDescription jdesc_output(kDummyString);
2105
2106 // Deserialize
2107 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2108 // Verify
2109 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2110}
2111
2112TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2113 AddSctpDataChannel();
2114 JsepSessionDescription jdesc(kDummyString);
2115 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2116
2117 std::string sdp_with_data = kSdpString;
2118 sdp_with_data.append(kSdpSctpDataChannelString);
2119 JsepSessionDescription jdesc_output(kDummyString);
2120
2121 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2122 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2123}
2124
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002125TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2126 AddSctpDataChannel();
2127 JsepSessionDescription jdesc(kDummyString);
2128 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2129
2130 std::string sdp_with_data = kSdpString;
2131 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2132 JsepSessionDescription jdesc_output(kDummyString);
2133
2134 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2135 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2136}
2137
2138// Test to check the behaviour if sctp-port is specified
2139// on the m= line and in a=sctp-port.
2140TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2141 AddSctpDataChannel();
2142 JsepSessionDescription jdesc(kDummyString);
2143 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2144
2145 std::string sdp_with_data = kSdpString;
2146 // Append m= attributes
2147 sdp_with_data.append(kSdpSctpDataChannelString);
2148 // Append a=sctp-port attribute
2149 sdp_with_data.append("a=sctp-port 5000\r\n");
2150 JsepSessionDescription jdesc_output(kDummyString);
2151
2152 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2153}
2154
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002155// For crbug/344475.
2156TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2157 std::string sdp_with_data = kSdpString;
2158 sdp_with_data.append(kSdpSctpDataChannelString);
2159 // Remove the "\n" at the end.
2160 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2161 JsepSessionDescription jdesc_output(kDummyString);
2162
2163 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2164 // No crash is a pass.
2165}
2166
wu@webrtc.org78187522013-10-07 23:32:02 +00002167TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2168 AddSctpDataChannel();
2169 const uint16 kUnusualSctpPort = 9556;
2170 char default_portstr[16];
2171 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002172 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002173 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002174 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002175 kUnusualSctpPort);
2176
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002177 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002178 JsepSessionDescription jdesc(kDummyString);
2179 // take our pre-built session description and change the SCTP port.
2180 cricket::SessionDescription* mutant = desc_.Copy();
2181 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2182 mutant->GetContentDescriptionByName(kDataContentName));
2183 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2184 EXPECT_EQ(codecs.size(), 1UL);
2185 EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId);
2186 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002187 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002188
2189 // note: mutant's owned by jdesc now.
2190 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2191 mutant = NULL;
2192
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002193 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002194 std::string sdp_with_data = kSdpString;
2195 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002196 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002197 unusual_portstr, strlen(unusual_portstr),
2198 &sdp_with_data);
2199 JsepSessionDescription jdesc_output(kDummyString);
2200
2201 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2202 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002203
2204 // We need to test the deserialized JsepSessionDescription from
2205 // kSdpSctpDataChannelStringWithSctpPort for
2206 // draft-ietf-mmusic-sctp-sdp-07
2207 // a=sctp-port
2208 sdp_with_data = kSdpString;
2209 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2210 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2211 unusual_portstr, strlen(unusual_portstr),
2212 &sdp_with_data);
2213
2214 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2215 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002216}
2217
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002218TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2219 AddRtpDataChannel();
2220 JsepSessionDescription jdesc(kDummyString);
2221 // We want to test that deserializing data content ignores bandwidth
2222 // settings (it should always be the default). Thus, we don't do
2223 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002224 // TODO(pthatcher): We need to temporarily allow the SDP to control
2225 // this for backwards-compatibility. Once we don't need that any
2226 // more, remove this.
2227 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2228 GetFirstDataContent(&desc_)->description);
2229 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002230 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2231
2232 std::string sdp_with_bandwidth = kSdpString;
2233 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2234 InjectAfter("a=mid:data_content_name\r\n",
2235 "b=AS:100\r\n",
2236 &sdp_with_bandwidth);
2237 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2238
2239 EXPECT_TRUE(
2240 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2241 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2242}
2243
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2245 TestDeserializeExtmap(true, false);
2246}
2247
2248TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2249 TestDeserializeExtmap(false, true);
2250}
2251
2252TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2253 TestDeserializeExtmap(true, true);
2254}
2255
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002256TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2257 JsepSessionDescription jdesc(kDummyString);
2258 std::string sdp = kSdpFullString;
2259 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2260 // Deserialize
2261 SdpParseError error;
2262 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2263 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2264 EXPECT_EQ(lastline, error.line);
2265 EXPECT_EQ("Invalid SDP line.", error.description);
2266}
2267
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2269 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2270 std::string new_sdp = kSdpOneCandidate;
2271 Replace("udp", "unsupported_transport", &new_sdp);
2272 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2273 new_sdp = kSdpOneCandidate;
2274 Replace("udp", "uDP", &new_sdp);
2275 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2276 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2277 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2278 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2279}
2280
2281TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2282 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2283 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2284 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2285 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2286 Candidate ref_candidate = jcandidate_->candidate();
2287 ref_candidate.set_username("user_rtp");
2288 ref_candidate.set_password("password_rtp");
2289 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2290}
2291
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002292TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2293 JsepSessionDescription jdesc(kDummyString);
2294
2295 // Deserialize
2296 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2297
2298 // Verify
2299 cricket::AudioContentDescription* audio =
2300 static_cast<AudioContentDescription*>(
2301 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2302 EXPECT_TRUE(audio->conference_mode());
2303
2304 cricket::VideoContentDescription* video =
2305 static_cast<VideoContentDescription*>(
2306 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2307 EXPECT_TRUE(video->conference_mode());
2308}
2309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2311 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002312 const char kSdpEmptyType[] = " =candidate";
2313 const char kSdpEqualAsPlus[] = "a+candidate";
2314 const char kSdpSpaceAfterEqual[] = "a= candidate";
2315 const char kSdpUpperType[] = "A=candidate";
2316 const char kSdpEmptyLine[] = "";
2317 const char kSdpMissingValue[] = "a=";
2318
2319 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 "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 +00002321 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 "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 +00002323 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 "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 +00002325 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002326 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002327 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328
2329 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002330 ExpectParseFailure("v=", kSdpDestroyer);
2331 ExpectParseFailure("o=", kSdpDestroyer);
2332 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002334 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335
2336 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002337 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2338 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339
2340 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002341 ExpectParseFailure("a=candidate", kSdpEmptyType);
2342 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2343 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2344 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345
2346 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2347 // because it's orthogonal to what we are replacing and hence
2348 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002349 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2350 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2351 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2352 ExpectParseFailure("a=sendrecv", kSdpMd5);
2353
2354 // Empty Line
2355 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2356 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002357}
2358
2359TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2360 // ssrc
2361 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2362 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2363 // crypto
2364 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2365 // rtpmap
2366 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2367 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2368 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2369 // candidate
2370 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2371 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2372 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2373 ExpectParseFailure("rport 2346", "rport badvalue");
2374 ExpectParseFailure("rport 2346 generation 2",
2375 "rport 2346 generation badvalue");
2376 // m line
2377 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2378 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2379
2380 // bandwidth
2381 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2382 "b=AS:badvalue\r\n",
2383 "b=AS:badvalue");
2384 // rtcp-fb
2385 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2386 "a=rtcp-fb:badvalue nack\r\n",
2387 "a=rtcp-fb:badvalue nack");
2388 // extmap
2389 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2390 "a=extmap:badvalue http://example.com\r\n",
2391 "a=extmap:badvalue http://example.com");
2392 // x-google-buffer-latency
2393 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2394 "a=x-google-buffer-latency:badvalue\r\n",
2395 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396}
2397
2398TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2399 JsepSessionDescription jdesc_output(kDummyString);
2400
2401 const char kSdpWithReorderedPlTypesString[] =
2402 "v=0\r\n"
2403 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2404 "s=-\r\n"
2405 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002406 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2408 // in the map.
2409 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
2410 "a=rtpmap:104 CELT/32000/2\r\n";
2411
2412 // Deserialize
2413 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2414
2415 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2416 ASSERT_TRUE(ac != NULL);
2417 const AudioContentDescription* acd =
2418 static_cast<const AudioContentDescription*>(ac->description);
2419 ASSERT_FALSE(acd->codecs().empty());
2420 EXPECT_EQ("CELT", acd->codecs()[0].name);
2421 EXPECT_EQ(104, acd->codecs()[0].id);
2422}
2423
2424TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2425 JsepSessionDescription jdesc_output(kDummyString);
2426 CodecParams params;
2427 params.max_ptime = 40;
2428 params.ptime = 30;
2429 params.min_ptime = 10;
2430 params.sprop_stereo = 1;
2431 params.stereo = 1;
2432 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002433 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 TestDeserializeCodecParams(params, &jdesc_output);
2435 TestSerialize(jdesc_output);
2436}
2437
2438TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2439 const bool kUseWildcard = false;
2440 JsepSessionDescription jdesc_output(kDummyString);
2441 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2442 TestSerialize(jdesc_output);
2443}
2444
2445TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2446 const bool kUseWildcard = true;
2447 JsepSessionDescription jdesc_output(kDummyString);
2448 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2449 TestSerialize(jdesc_output);
2450}
2451
2452TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2453 JsepSessionDescription jdesc_output(kDummyString);
2454
2455 const char kSdpWithFmtpString[] =
2456 "v=0\r\n"
2457 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2458 "s=-\r\n"
2459 "t=0 0\r\n"
2460 "m=video 3457 RTP/SAVPF 120\r\n"
2461 "a=rtpmap:120 VP8/90000\r\n"
2462 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2463
2464 // Deserialize
2465 SdpParseError error;
2466 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2467 &error));
2468
2469 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2470 ASSERT_TRUE(vc != NULL);
2471 const VideoContentDescription* vcd =
2472 static_cast<const VideoContentDescription*>(vc->description);
2473 ASSERT_FALSE(vcd->codecs().empty());
2474 cricket::VideoCodec vp8 = vcd->codecs()[0];
2475 EXPECT_EQ("VP8", vp8.name);
2476 EXPECT_EQ(120, vp8.id);
2477 cricket::CodecParameterMap::iterator found =
2478 vp8.params.find("x-google-min-bitrate");
2479 ASSERT_TRUE(found != vp8.params.end());
2480 EXPECT_EQ(found->second, "10");
2481 found = vp8.params.find("x-google-max-quantization");
2482 ASSERT_TRUE(found != vp8.params.end());
2483 EXPECT_EQ(found->second, "40");
2484}
2485
2486TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2487 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2488 GetFirstVideoContent(&desc_)->description);
2489
2490 cricket::VideoCodecs codecs = vcd->codecs();
2491 codecs[0].params["x-google-min-bitrate"] = "10";
2492 vcd->set_codecs(codecs);
2493
2494 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2495 jdesc_.session_id(),
2496 jdesc_.session_version()));
2497 std::string message = webrtc::SdpSerialize(jdesc_);
2498 std::string sdp_with_fmtp = kSdpFullString;
2499 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2500 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2501 &sdp_with_fmtp);
2502 EXPECT_EQ(sdp_with_fmtp, message);
2503}
2504
2505TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2506 JsepSessionDescription jdesc_with_icelite(kDummyString);
2507 std::string sdp_with_icelite = kSdpFullString;
2508 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2509 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2510 const cricket::TransportInfo* tinfo1 =
2511 desc->GetTransportInfoByName("audio_content_name");
2512 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2513 const cricket::TransportInfo* tinfo2 =
2514 desc->GetTransportInfoByName("video_content_name");
2515 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2516 InjectAfter(kSessionTime,
2517 "a=ice-lite\r\n",
2518 &sdp_with_icelite);
2519 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2520 desc = jdesc_with_icelite.description();
2521 const cricket::TransportInfo* atinfo =
2522 desc->GetTransportInfoByName("audio_content_name");
2523 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2524 const cricket::TransportInfo* vtinfo =
2525 desc->GetTransportInfoByName("video_content_name");
2526 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2527}
2528
2529// Verifies that the candidates in the input SDP are parsed and serialized
2530// correctly in the output SDP.
2531TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2532 std::string sdp_with_data = kSdpString;
2533 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2534 JsepSessionDescription jdesc_output(kDummyString);
2535
2536 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2537 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2538}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002539
2540TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2541 AddFingerprint();
2542 TransportInfo audio_transport_info =
2543 *(desc_.GetTransportInfoByName(kAudioContentName));
2544 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2545 audio_transport_info.description.connection_role);
2546 audio_transport_info.description.connection_role =
2547 cricket::CONNECTIONROLE_ACTIVE;
2548
2549 TransportInfo video_transport_info =
2550 *(desc_.GetTransportInfoByName(kVideoContentName));
2551 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2552 video_transport_info.description.connection_role);
2553 video_transport_info.description.connection_role =
2554 cricket::CONNECTIONROLE_ACTIVE;
2555
2556 desc_.RemoveTransportInfoByName(kAudioContentName);
2557 desc_.RemoveTransportInfoByName(kVideoContentName);
2558
2559 desc_.AddTransportInfo(audio_transport_info);
2560 desc_.AddTransportInfo(video_transport_info);
2561
2562 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2563 jdesc_.session_id(),
2564 jdesc_.session_version()));
2565 std::string message = webrtc::SdpSerialize(jdesc_);
2566 std::string sdp_with_dtlssetup = kSdpFullString;
2567
2568 // Fingerprint attribute is necessary to add DTLS setup attribute.
2569 InjectAfter(kAttributeIcePwdVoice,
2570 kFingerprint, &sdp_with_dtlssetup);
2571 InjectAfter(kAttributeIcePwdVideo,
2572 kFingerprint, &sdp_with_dtlssetup);
2573 // Now adding |setup| attribute.
2574 InjectAfter(kFingerprint,
2575 "a=setup:active\r\n", &sdp_with_dtlssetup);
2576 EXPECT_EQ(sdp_with_dtlssetup, message);
2577}
2578
2579TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2580 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2581 std::string sdp_with_dtlssetup = kSdpFullString;
2582 InjectAfter(kSessionTime,
2583 "a=setup:actpass\r\n",
2584 &sdp_with_dtlssetup);
2585 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2586 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2587 const cricket::TransportInfo* atinfo =
2588 desc->GetTransportInfoByName("audio_content_name");
2589 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2590 atinfo->description.connection_role);
2591 const cricket::TransportInfo* vtinfo =
2592 desc->GetTransportInfoByName("video_content_name");
2593 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2594 vtinfo->description.connection_role);
2595}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002596
2597// Verifies that the order of the serialized m-lines follows the order of the
2598// ContentInfo in SessionDescription, and vise versa for deserialization.
2599TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2600 JsepSessionDescription jdesc(kDummyString);
2601 const std::string media_content_sdps[3] = {
2602 kSdpAudioString,
2603 kSdpVideoString,
2604 kSdpSctpDataChannelString
2605 };
2606 const cricket::MediaType media_types[3] = {
2607 cricket::MEDIA_TYPE_AUDIO,
2608 cricket::MEDIA_TYPE_VIDEO,
2609 cricket::MEDIA_TYPE_DATA
2610 };
2611
2612 // Verifies all 6 permutations.
2613 for (size_t i = 0; i < 6; ++i) {
2614 size_t media_content_in_sdp[3];
2615 // The index of the first media content.
2616 media_content_in_sdp[0] = i / 2;
2617 // The index of the second media content.
2618 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2619 // The index of the third media content.
2620 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2621
2622 std::string sdp_string = kSdpSessionString;
2623 for (size_t i = 0; i < 3; ++i)
2624 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2625
2626 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2627 cricket::SessionDescription* desc = jdesc.description();
2628 EXPECT_EQ(3u, desc->contents().size());
2629
2630 for (size_t i = 0; i < 3; ++i) {
2631 const cricket::MediaContentDescription* mdesc =
2632 static_cast<const cricket::MediaContentDescription*>(
2633 desc->contents()[i].description);
2634 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2635 }
2636
2637 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2638 EXPECT_EQ(sdp_string, serialized_sdp);
2639 }
2640}