blob: a64714881375cf748d8a6b4a7a20bd2e39f2369f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2011 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
117struct CodecParams {
118 int max_ptime;
119 int ptime;
120 int min_ptime;
121 int sprop_stereo;
122 int stereo;
123 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000124 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125};
126
127// Reference sdp string
128static const char kSdpFullString[] =
129 "v=0\r\n"
130 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
134 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
135 "c=IN IP4 74.125.127.126\r\n"
136 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
137 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
146 "raddr 192.168.1.5 rport 2346 "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
149 "raddr 192.168.1.5 rport 2348 "
150 "generation 2\r\n"
151 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
152 "a=mid:audio_content_name\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000160 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
165 "a=ssrc:4 cname:stream_2_cname\r\n"
166 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
167 "a=ssrc:4 mslabel:local_stream_2\r\n"
168 "a=ssrc:4 label:audio_track_id_2\r\n"
169 "m=video 3457 RTP/SAVPF 120\r\n"
170 "c=IN IP4 74.125.224.39\r\n"
171 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
172 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
183 "generation 2\r\n"
184 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
185 "a=mid:video_content_name\r\n"
186 "a=sendrecv\r\n"
187 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
188 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
189 "a=rtpmap:120 VP8/90000\r\n"
190 "a=ssrc:2 cname:stream_1_cname\r\n"
191 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
192 "a=ssrc:2 mslabel:local_stream_1\r\n"
193 "a=ssrc:2 label:video_track_id_1\r\n"
194 "a=ssrc:3 cname:stream_1_cname\r\n"
195 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
196 "a=ssrc:3 mslabel:local_stream_1\r\n"
197 "a=ssrc:3 label:video_track_id_2\r\n"
198 "a=ssrc-group:FEC 5 6\r\n"
199 "a=ssrc:5 cname:stream_2_cname\r\n"
200 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
201 "a=ssrc:5 mslabel:local_stream_2\r\n"
202 "a=ssrc:5 label:video_track_id_3\r\n"
203 "a=ssrc:6 cname:stream_2_cname\r\n"
204 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:6 mslabel:local_stream_2\r\n"
206 "a=ssrc:6 label:video_track_id_3\r\n";
207
208// SDP reference string without the candidates.
209static const char kSdpString[] =
210 "v=0\r\n"
211 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
214 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000215 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
219 "a=mid:audio_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
223 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
224 "dummy_session_params\r\n"
225 "a=rtpmap:111 opus/48000/2\r\n"
226 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000227 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 "a=ssrc:1 cname:stream_1_cname\r\n"
229 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
230 "a=ssrc:1 mslabel:local_stream_1\r\n"
231 "a=ssrc:1 label:audio_track_id_1\r\n"
232 "a=ssrc:4 cname:stream_2_cname\r\n"
233 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
234 "a=ssrc:4 mslabel:local_stream_2\r\n"
235 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000236 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
240 "a=mid:video_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
244 "a=rtpmap:120 VP8/90000\r\n"
245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
250 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
251 "a=ssrc:3 mslabel:local_stream_1\r\n"
252 "a=ssrc:3 label:video_track_id_2\r\n"
253 "a=ssrc-group:FEC 5 6\r\n"
254 "a=ssrc:5 cname:stream_2_cname\r\n"
255 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
256 "a=ssrc:5 mslabel:local_stream_2\r\n"
257 "a=ssrc:5 label:video_track_id_3\r\n"
258 "a=ssrc:6 cname:stream_2_cname\r\n"
259 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:6 mslabel:local_stream_2\r\n"
261 "a=ssrc:6 label:video_track_id_3\r\n";
262
263static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000264 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
279static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000280 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000281 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000287// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000288static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000289 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
290 "a=max-message-size=100000\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000291 "a=sctp-port 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000292 "c=IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n";
296
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));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000534 audio_desc_->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 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 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000743
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +0000745 // Use an equivalence class here, for old and new versions of the
746 // protocol description.
747 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
748 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp) {
749 const bool cd2_is_also_udp_dtls_sctp =
750 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
751 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp;
752 EXPECT_TRUE(cd2_is_also_udp_dtls_sctp);
753 } else {
754 EXPECT_EQ(cd1->protocol(), cd2->protocol());
755 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756
757 // codecs
758 EXPECT_EQ(cd1->codecs(), cd2->codecs());
759
760 // bandwidth
761 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
762
763 // streams
764 EXPECT_EQ(cd1->streams(), cd2->streams());
765
766 // extmap
767 ASSERT_EQ(cd1->rtp_header_extensions().size(),
768 cd2->rtp_header_extensions().size());
769 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
770 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
771 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
772 EXPECT_EQ(ext1.uri, ext2.uri);
773 EXPECT_EQ(ext1.id, ext2.id);
774 }
775
776 // buffered mode latency
777 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
778 }
779
780
781 void CompareSessionDescription(const SessionDescription& desc1,
782 const SessionDescription& desc2) {
783 // Compare content descriptions.
784 if (desc1.contents().size() != desc2.contents().size()) {
785 ADD_FAILURE();
786 return;
787 }
788 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
789 const cricket::ContentInfo& c1 = desc1.contents().at(i);
790 const cricket::ContentInfo& c2 = desc2.contents().at(i);
791 // content name
792 EXPECT_EQ(c1.name, c2.name);
793 // content type
794 // Note, ASSERT will return from the function, but will not stop the test.
795 ASSERT_EQ(c1.type, c2.type);
796
797 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
798 if (IsAudioContent(&c1)) {
799 const AudioContentDescription* acd1 =
800 static_cast<const AudioContentDescription*>(c1.description);
801 const AudioContentDescription* acd2 =
802 static_cast<const AudioContentDescription*>(c2.description);
803 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
804 }
805
806 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
807 if (IsVideoContent(&c1)) {
808 const VideoContentDescription* vcd1 =
809 static_cast<const VideoContentDescription*>(c1.description);
810 const VideoContentDescription* vcd2 =
811 static_cast<const VideoContentDescription*>(c2.description);
812 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
813 }
814
815 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
816 if (IsDataContent(&c1)) {
817 const DataContentDescription* dcd1 =
818 static_cast<const DataContentDescription*>(c1.description);
819 const DataContentDescription* dcd2 =
820 static_cast<const DataContentDescription*>(c2.description);
821 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
822 }
823 }
824
825 // group
826 const cricket::ContentGroups groups1 = desc1.groups();
827 const cricket::ContentGroups groups2 = desc2.groups();
828 EXPECT_EQ(groups1.size(), groups1.size());
829 if (groups1.size() != groups2.size()) {
830 ADD_FAILURE();
831 return;
832 }
833 for (size_t i = 0; i < groups1.size(); ++i) {
834 const cricket::ContentGroup group1 = groups1.at(i);
835 const cricket::ContentGroup group2 = groups2.at(i);
836 EXPECT_EQ(group1.semantics(), group2.semantics());
837 const cricket::ContentNames names1 = group1.content_names();
838 const cricket::ContentNames names2 = group2.content_names();
839 EXPECT_EQ(names1.size(), names2.size());
840 if (names1.size() != names2.size()) {
841 ADD_FAILURE();
842 return;
843 }
844 cricket::ContentNames::const_iterator iter1 = names1.begin();
845 cricket::ContentNames::const_iterator iter2 = names2.begin();
846 while (iter1 != names1.end()) {
847 EXPECT_EQ(*iter1++, *iter2++);
848 }
849 }
850
851 // transport info
852 const cricket::TransportInfos transports1 = desc1.transport_infos();
853 const cricket::TransportInfos transports2 = desc2.transport_infos();
854 EXPECT_EQ(transports1.size(), transports2.size());
855 if (transports1.size() != transports2.size()) {
856 ADD_FAILURE();
857 return;
858 }
859 for (size_t i = 0; i < transports1.size(); ++i) {
860 const cricket::TransportInfo transport1 = transports1.at(i);
861 const cricket::TransportInfo transport2 = transports2.at(i);
862 EXPECT_EQ(transport1.content_name, transport2.content_name);
863 EXPECT_EQ(transport1.description.transport_type,
864 transport2.description.transport_type);
865 EXPECT_EQ(transport1.description.ice_ufrag,
866 transport2.description.ice_ufrag);
867 EXPECT_EQ(transport1.description.ice_pwd,
868 transport2.description.ice_pwd);
869 if (transport1.description.identity_fingerprint) {
870 EXPECT_EQ(*transport1.description.identity_fingerprint,
871 *transport2.description.identity_fingerprint);
872 } else {
873 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
874 transport2.description.identity_fingerprint.get());
875 }
876 EXPECT_EQ(transport1.description.transport_options,
877 transport2.description.transport_options);
878 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
879 transport2.description.candidates));
880 }
881 }
882
883 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
884 EXPECT_EQ(cs1.size(), cs2.size());
885 if (cs1.size() != cs2.size())
886 return false;
887 for (size_t i = 0; i< cs1.size(); ++i) {
888 const Candidate c1 = cs1.at(i);
889 const Candidate c2 = cs2.at(i);
890 EXPECT_TRUE(c1.IsEquivalent(c2));
891 }
892 return true;
893 }
894
895 bool CompareSessionDescription(
896 const JsepSessionDescription& desc1,
897 const JsepSessionDescription& desc2) {
898 EXPECT_EQ(desc1.session_id(), desc2.session_id());
899 EXPECT_EQ(desc1.session_version(), desc2.session_version());
900 CompareSessionDescription(*desc1.description(), *desc2.description());
901 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
902 return false;
903 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
904 const IceCandidateCollection* cc1 = desc1.candidates(i);
905 const IceCandidateCollection* cc2 = desc2.candidates(i);
906 if (cc1->count() != cc2->count())
907 return false;
908 for (size_t j = 0; j < cc1->count(); ++j) {
909 const IceCandidateInterface* c1 = cc1->at(j);
910 const IceCandidateInterface* c2 = cc2->at(j);
911 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
912 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
913 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
914 }
915 }
916 return true;
917 }
918
919 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
920 // them with invalid keywords so that the parser will just ignore them.
921 bool RemoveCandidateUfragPwd(std::string* sdp) {
922 const char ice_ufrag[] = "a=ice-ufrag";
923 const char ice_ufragx[] = "a=xice-ufrag";
924 const char ice_pwd[] = "a=ice-pwd";
925 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000928 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 ice_pwdx, strlen(ice_pwdx), sdp);
930 return true;
931 }
932
933 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
934 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
935 const std::string& ufrag, const std::string& pwd) {
936 std::string content_name;
937 if (mline_index == 0) {
938 content_name = kAudioContentName;
939 } else if (mline_index == 1) {
940 content_name = kVideoContentName;
941 } else {
942 ASSERT(false);
943 }
944 TransportInfo transport_info(
945 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000946 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 SessionDescription* desc =
948 const_cast<SessionDescription*>(jdesc->description());
949 desc->RemoveTransportInfoByName(content_name);
950 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
951 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
952 const IceCandidateCollection* cc = jdesc_.candidates(i);
953 for (size_t j = 0; j < cc->count(); ++j) {
954 if (cc->at(j)->sdp_mline_index() == mline_index) {
955 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
956 ufrag);
957 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
958 pwd);
959 }
960 }
961 }
962 return true;
963 }
964
965 void AddIceOptions(const std::string& content_name,
966 const std::vector<std::string>& transport_options) {
967 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
968 cricket::TransportInfo transport_info =
969 *(desc_.GetTransportInfoByName(content_name));
970 desc_.RemoveTransportInfoByName(content_name);
971 transport_info.description.transport_options = transport_options;
972 desc_.AddTransportInfo(transport_info);
973 }
974
975 void AddFingerprint() {
976 desc_.RemoveTransportInfoByName(kAudioContentName);
977 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000978 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 kIdentityDigest,
980 sizeof(kIdentityDigest));
981 EXPECT_TRUE(desc_.AddTransportInfo(
982 TransportInfo(kAudioContentName,
983 TransportDescription(NS_JINGLE_ICE_UDP,
984 std::vector<std::string>(),
985 kCandidateUfragVoice,
986 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000987 cricket::ICEMODE_FULL,
988 cricket::CONNECTIONROLE_NONE,
989 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 EXPECT_TRUE(desc_.AddTransportInfo(
991 TransportInfo(kVideoContentName,
992 TransportDescription(NS_JINGLE_ICE_UDP,
993 std::vector<std::string>(),
994 kCandidateUfragVideo,
995 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000996 cricket::ICEMODE_FULL,
997 cricket::CONNECTIONROLE_NONE,
998 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 }
1000
1001 void AddExtmap() {
1002 audio_desc_ = static_cast<AudioContentDescription*>(
1003 audio_desc_->Copy());
1004 video_desc_ = static_cast<VideoContentDescription*>(
1005 video_desc_->Copy());
1006 audio_desc_->AddRtpHeaderExtension(
1007 RtpHeaderExtension(kExtmapUri, kExtmapId));
1008 video_desc_->AddRtpHeaderExtension(
1009 RtpHeaderExtension(kExtmapUri, kExtmapId));
1010 desc_.RemoveContentByName(kAudioContentName);
1011 desc_.RemoveContentByName(kVideoContentName);
1012 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1013 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1014 }
1015
1016 void RemoveCryptos() {
1017 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1018 video_desc_->set_cryptos(std::vector<CryptoParams>());
1019 }
1020
1021 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1022 audio_desc_->set_direction(direction);
1023 video_desc_->set_direction(direction);
1024 std::string new_sdp = kSdpFullString;
1025 ReplaceDirection(direction, &new_sdp);
1026
1027 if (!jdesc_.Initialize(desc_.Copy(),
1028 jdesc_.session_id(),
1029 jdesc_.session_version())) {
1030 return false;
1031 }
1032 std::string message = webrtc::SdpSerialize(jdesc_);
1033 EXPECT_EQ(new_sdp, message);
1034 return true;
1035 }
1036
1037 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1038 audio_desc_ = static_cast<AudioContentDescription*>(
1039 audio_desc_->Copy());
1040 video_desc_ = static_cast<VideoContentDescription*>(
1041 video_desc_->Copy());
1042 desc_.RemoveContentByName(kAudioContentName);
1043 desc_.RemoveContentByName(kVideoContentName);
1044 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1045 audio_desc_);
1046 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1047 video_desc_);
1048 std::string new_sdp = kSdpFullString;
1049 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1050
1051 if (!jdesc_.Initialize(desc_.Copy(),
1052 jdesc_.session_id(),
1053 jdesc_.session_version())) {
1054 return false;
1055 }
1056 std::string message = webrtc::SdpSerialize(jdesc_);
1057 EXPECT_EQ(new_sdp, message);
1058 return true;
1059 }
1060
1061 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 new DataContentDescription());
1064 data_desc_ = data.get();
1065 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001066 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1067 cricket::kGoogleSctpDataCodecName, 0);
1068 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1069 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1071 EXPECT_TRUE(desc_.AddTransportInfo(
1072 TransportInfo(kDataContentName,
1073 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001075 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 }
1077
1078 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001079 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 new DataContentDescription());
1081 data_desc_ = data.get();
1082
1083 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1084 StreamParams data_stream;
1085 data_stream.id = kDataChannelMsid;
1086 data_stream.cname = kDataChannelCname;
1087 data_stream.sync_label = kDataChannelLabel;
1088 data_stream.ssrcs.push_back(kDataChannelSsrc);
1089 data_desc_->AddStream(data_stream);
1090 data_desc_->AddCrypto(CryptoParams(
1091 1, "AES_CM_128_HMAC_SHA1_80",
1092 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1093 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1094 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1095 EXPECT_TRUE(desc_.AddTransportInfo(
1096 TransportInfo(kDataContentName,
1097 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001099 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 }
1101
1102 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1103 std::string new_sdp = kSdpFullString;
1104 ReplaceDirection(direction, &new_sdp);
1105 JsepSessionDescription new_jdesc(kDummyString);
1106
1107 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1108
1109 audio_desc_->set_direction(direction);
1110 video_desc_->set_direction(direction);
1111 if (!jdesc_.Initialize(desc_.Copy(),
1112 jdesc_.session_id(),
1113 jdesc_.session_version())) {
1114 return false;
1115 }
1116 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1117 return true;
1118 }
1119
1120 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1121 std::string new_sdp = kSdpFullString;
1122 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1123 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1124
1125 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1126 audio_desc_ = static_cast<AudioContentDescription*>(
1127 audio_desc_->Copy());
1128 video_desc_ = static_cast<VideoContentDescription*>(
1129 video_desc_->Copy());
1130 desc_.RemoveContentByName(kAudioContentName);
1131 desc_.RemoveContentByName(kVideoContentName);
1132 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1133 audio_desc_);
1134 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1135 video_desc_);
1136 if (!jdesc_.Initialize(desc_.Copy(),
1137 jdesc_.session_id(),
1138 jdesc_.session_version())) {
1139 return false;
1140 }
1141 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1142 return true;
1143 }
1144
1145 void TestDeserializeExtmap(bool session_level, bool media_level) {
1146 AddExtmap();
1147 JsepSessionDescription new_jdesc("dummy");
1148 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1149 jdesc_.session_id(),
1150 jdesc_.session_version()));
1151 JsepSessionDescription jdesc_with_extmap("dummy");
1152 std::string sdp_with_extmap = kSdpString;
1153 if (session_level) {
1154 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1155 &sdp_with_extmap);
1156 }
1157 if (media_level) {
1158 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1159 &sdp_with_extmap);
1160 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1161 &sdp_with_extmap);
1162 }
1163 // The extmap can't be present at the same time in both session level and
1164 // media level.
1165 if (session_level && media_level) {
1166 SdpParseError error;
1167 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1168 &jdesc_with_extmap, &error));
1169 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1170 } else {
1171 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1172 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1173 }
1174 }
1175
1176 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1177 const std::string& name, int expected_value) {
1178 cricket::CodecParameterMap::const_iterator found = params.find(name);
1179 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001180 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 }
1182
1183 void TestDeserializeCodecParams(const CodecParams& params,
1184 JsepSessionDescription* jdesc_output) {
1185 std::string sdp =
1186 "v=0\r\n"
1187 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1188 "s=-\r\n"
1189 "t=0 0\r\n"
1190 // Include semantics for WebRTC Media Streams since it is supported by
1191 // this parser, and will be added to the SDP when serializing a session
1192 // description.
1193 "a=msid-semantic: WMS\r\n"
1194 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001195 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196 // Pltype 111 listed before 103 and 104 in the map.
1197 "a=rtpmap:111 opus/48000/2\r\n"
1198 // Pltype 103 listed before 104.
1199 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001200 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001201 "a=fmtp:111 0-15,66,70\r\n"
1202 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001204 os << "minptime=" << params.min_ptime
1205 << "; stereo=" << params.stereo
1206 << "; sprop-stereo=" << params.sprop_stereo
1207 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001208 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 << "a=ptime:" << params.ptime << "\r\n"
1210 << "a=maxptime:" << params.max_ptime << "\r\n";
1211 sdp += os.str();
1212
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001213 os.clear();
1214 os.str("");
1215 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001216 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001217 << "a=rtpmap:99 VP8/90000\r\n"
1218 << "a=rtpmap:95 RTX/90000\r\n"
1219 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1220 sdp += os.str();
1221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 // Deserialize
1223 SdpParseError error;
1224 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1225
1226 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1227 ASSERT_TRUE(ac != NULL);
1228 const AudioContentDescription* acd =
1229 static_cast<const AudioContentDescription*>(ac->description);
1230 ASSERT_FALSE(acd->codecs().empty());
1231 cricket::AudioCodec opus = acd->codecs()[0];
1232 EXPECT_EQ("opus", opus.name);
1233 EXPECT_EQ(111, opus.id);
1234 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1235 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1236 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1237 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001238 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1239 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1241 cricket::AudioCodec codec = acd->codecs()[i];
1242 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1243 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1244 if (codec.name == "ISAC") {
1245 if (codec.clockrate == 16000) {
1246 EXPECT_EQ(32000, codec.bitrate);
1247 } else {
1248 EXPECT_EQ(56000, codec.bitrate);
1249 }
1250 }
1251 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001252
1253 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1254 ASSERT_TRUE(vc != NULL);
1255 const VideoContentDescription* vcd =
1256 static_cast<const VideoContentDescription*>(vc->description);
1257 ASSERT_FALSE(vcd->codecs().empty());
1258 cricket::VideoCodec vp8 = vcd->codecs()[0];
1259 EXPECT_EQ("VP8", vp8.name);
1260 EXPECT_EQ(99, vp8.id);
1261 cricket::VideoCodec rtx = vcd->codecs()[1];
1262 EXPECT_EQ("RTX", rtx.name);
1263 EXPECT_EQ(95, rtx.id);
1264 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 }
1266
1267 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1268 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001269 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 "v=0\r\n"
1271 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1272 "s=-\r\n"
1273 "t=0 0\r\n"
1274 // Include semantics for WebRTC Media Streams since it is supported by
1275 // this parser, and will be added to the SDP when serializing a session
1276 // description.
1277 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001278 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001279 "a=rtpmap:111 opus/48000/2\r\n";
1280 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 "m=video 3457 RTP/SAVPF 101\r\n"
1282 "a=rtpmap:101 VP8/90000\r\n"
1283 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001284 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001285 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001287 os << sdp_session_and_audio;
1288 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1289 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001291 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 // Deserialize
1293 SdpParseError error;
1294 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1295 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1296 ASSERT_TRUE(ac != NULL);
1297 const AudioContentDescription* acd =
1298 static_cast<const AudioContentDescription*>(ac->description);
1299 ASSERT_FALSE(acd->codecs().empty());
1300 cricket::AudioCodec opus = acd->codecs()[0];
1301 EXPECT_EQ(111, opus.id);
1302 EXPECT_TRUE(opus.HasFeedbackParam(
1303 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1304 cricket::kParamValueEmpty)));
1305
1306 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1307 ASSERT_TRUE(vc != NULL);
1308 const VideoContentDescription* vcd =
1309 static_cast<const VideoContentDescription*>(vc->description);
1310 ASSERT_FALSE(vcd->codecs().empty());
1311 cricket::VideoCodec vp8 = vcd->codecs()[0];
1312 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1313 vp8.name.c_str());
1314 EXPECT_EQ(101, vp8.id);
1315 EXPECT_TRUE(vp8.HasFeedbackParam(
1316 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1317 cricket::kParamValueEmpty)));
1318 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001319 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1320 cricket::kRtcpFbNackParamPli)));
1321 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1323 cricket::kParamValueEmpty)));
1324 EXPECT_TRUE(vp8.HasFeedbackParam(
1325 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1326 cricket::kRtcpFbCcmParamFir)));
1327 }
1328
1329 // Two SDP messages can mean the same thing but be different strings, e.g.
1330 // some of the lines can be serialized in different order.
1331 // However, a deserialized description can be compared field by field and has
1332 // no order. If deserializer has already been tested, serializing then
1333 // deserializing and comparing JsepSessionDescription will test
1334 // the serializer sufficiently.
1335 void TestSerialize(const JsepSessionDescription& jdesc) {
1336 std::string message = webrtc::SdpSerialize(jdesc);
1337 JsepSessionDescription jdesc_output_des(kDummyString);
1338 SdpParseError error;
1339 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1340 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1341 }
1342
1343 protected:
1344 SessionDescription desc_;
1345 AudioContentDescription* audio_desc_;
1346 VideoContentDescription* video_desc_;
1347 DataContentDescription* data_desc_;
1348 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001349 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 JsepSessionDescription jdesc_;
1351};
1352
1353void TestMismatch(const std::string& string1, const std::string& string2) {
1354 int position = 0;
1355 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1356 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001357 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 break;
1359 }
1360 }
1361 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1362 << " character\n"
1363 << " 1: " << string1.substr(position, 20) << "\n"
1364 << " 2: " << string2.substr(position, 20) << "\n";
1365}
1366
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1368 // SessionDescription with desc and candidates.
1369 std::string message = webrtc::SdpSerialize(jdesc_);
1370 TestMismatch(std::string(kSdpFullString), message);
1371}
1372
1373TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1374 JsepSessionDescription jdesc_empty(kDummyString);
1375 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1376}
1377
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001378// This tests serialization of SDP with only IPv6 candidates and verifies that
1379// IPv6 is used as default address in c line according to preference.
1380TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1381 // Only test 1 m line.
1382 desc_.RemoveContentByName("video_content_name");
1383 // Stun has a high preference than local host.
1384 cricket::Candidate candidate1(
1385 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1386 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1387 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1388 cricket::Candidate candidate2(
1389 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1390 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1391 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1392 JsepSessionDescription jdesc(kDummyString);
1393 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1394
1395 // Only add the candidates to audio m line.
1396 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1397 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1398 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1399 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1400 std::string message = webrtc::SdpSerialize(jdesc);
1401
1402 // Audio line should have a c line like this one.
1403 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1404 // Shouldn't have a IP4 c line.
1405 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1406}
1407
1408// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1409// verifies that IPv4 is used as default address in c line even if the
1410// preference of IPv4 is lower.
1411TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1412 // Only test 1 m line.
1413 desc_.RemoveContentByName("video_content_name");
1414 cricket::Candidate candidate_v4(
1415 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1416 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1417 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1418 cricket::Candidate candidate_v6(
1419 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1420 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1421 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1422 JsepSessionDescription jdesc(kDummyString);
1423 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1424
1425 // Only add the candidates to audio m line.
1426 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1427 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1428 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1429 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
1430 std::string message = webrtc::SdpSerialize(jdesc);
1431
1432 // Audio line should have a c line like this one.
1433 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1434 // Shouldn't have a IP6 c line.
1435 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1436}
1437
1438// This tests serialization of SDP with both UDP and TCP candidates and
1439// verifies that UDP is used as default address in c line even if the
1440// preference of UDP is lower.
1441TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1442 // Only test 1 m line.
1443 desc_.RemoveContentByName("video_content_name");
1444 // Stun has a high preference than local host.
1445 cricket::Candidate candidate1(
1446 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1447 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1448 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1449 cricket::Candidate candidate2(
1450 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1451 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1452 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1453 kCandidateFoundation1);
1454 JsepSessionDescription jdesc(kDummyString);
1455 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1456
1457 // Only add the candidates to audio m line.
1458 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1459 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1460 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1461 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1462 std::string message = webrtc::SdpSerialize(jdesc);
1463
1464 // Audio line should have a c line like this one.
1465 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1466 std::string::npos);
1467 // Shouldn't have a IP4 c line.
1468 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1469}
1470
1471// This tests serialization of SDP with only TCP candidates and verifies that
1472// null IPv4 is used as default address in c line.
1473TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1474 // Only test 1 m line.
1475 desc_.RemoveContentByName("video_content_name");
1476 // Stun has a high preference than local host.
1477 cricket::Candidate candidate1(
1478 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1479 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1480 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1481 cricket::Candidate candidate2(
1482 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1483 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1484 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1485 JsepSessionDescription jdesc(kDummyString);
1486 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1487
1488 // Only add the candidates to audio m line.
1489 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1490 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1491 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1492 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
1493 std::string message = webrtc::SdpSerialize(jdesc);
1494
1495 // Audio line should have a c line like this one when no any default exists.
1496 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1497}
1498
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1500// the case in a DTLS offer.
1501TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1502 AddFingerprint();
1503 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1504 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1505 kSessionId, kSessionVersion));
1506 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1507
1508 std::string sdp_with_fingerprint = kSdpString;
1509 InjectAfter(kAttributeIcePwdVoice,
1510 kFingerprint, &sdp_with_fingerprint);
1511 InjectAfter(kAttributeIcePwdVideo,
1512 kFingerprint, &sdp_with_fingerprint);
1513
1514 EXPECT_EQ(sdp_with_fingerprint, message);
1515}
1516
1517// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1518// be the case in a DTLS answer.
1519TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1520 AddFingerprint();
1521 RemoveCryptos();
1522 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1523 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1524 kSessionId, kSessionVersion));
1525 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1526
1527 std::string sdp_with_fingerprint = kSdpString;
1528 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1529 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1530 InjectAfter(kAttributeIcePwdVoice,
1531 kFingerprint, &sdp_with_fingerprint);
1532 InjectAfter(kAttributeIcePwdVideo,
1533 kFingerprint, &sdp_with_fingerprint);
1534
1535 EXPECT_EQ(sdp_with_fingerprint, message);
1536}
1537
1538TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1539 // JsepSessionDescription with desc but without candidates.
1540 JsepSessionDescription jdesc_no_candidates(kDummyString);
1541 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1542 kSessionId, kSessionVersion));
1543 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1544 EXPECT_EQ(std::string(kSdpString), message);
1545}
1546
1547TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1548 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1549 group.AddContentName(kAudioContentName);
1550 group.AddContentName(kVideoContentName);
1551 desc_.AddGroup(group);
1552 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1553 jdesc_.session_id(),
1554 jdesc_.session_version()));
1555 std::string message = webrtc::SdpSerialize(jdesc_);
1556 std::string sdp_with_bundle = kSdpFullString;
1557 InjectAfter(kSessionTime,
1558 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1559 &sdp_with_bundle);
1560 EXPECT_EQ(sdp_with_bundle, message);
1561}
1562
1563TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1564 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1565 GetFirstVideoContent(&desc_)->description);
1566 vcd->set_bandwidth(100 * 1000);
1567 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1568 GetFirstAudioContent(&desc_)->description);
1569 acd->set_bandwidth(50 * 1000);
1570 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1571 jdesc_.session_id(),
1572 jdesc_.session_version()));
1573 std::string message = webrtc::SdpSerialize(jdesc_);
1574 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001575 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 "b=AS:100\r\n",
1577 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001578 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 "b=AS:50\r\n",
1580 &sdp_with_bandwidth);
1581 EXPECT_EQ(sdp_with_bandwidth, message);
1582}
1583
1584TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1585 std::vector<std::string> transport_options;
1586 transport_options.push_back(kIceOption1);
1587 transport_options.push_back(kIceOption3);
1588 AddIceOptions(kAudioContentName, transport_options);
1589 transport_options.clear();
1590 transport_options.push_back(kIceOption2);
1591 transport_options.push_back(kIceOption3);
1592 AddIceOptions(kVideoContentName, transport_options);
1593 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1594 jdesc_.session_id(),
1595 jdesc_.session_version()));
1596 std::string message = webrtc::SdpSerialize(jdesc_);
1597 std::string sdp_with_ice_options = kSdpFullString;
1598 InjectAfter(kAttributeIcePwdVoice,
1599 "a=ice-options:iceoption1 iceoption3\r\n",
1600 &sdp_with_ice_options);
1601 InjectAfter(kAttributeIcePwdVideo,
1602 "a=ice-options:iceoption2 iceoption3\r\n",
1603 &sdp_with_ice_options);
1604 EXPECT_EQ(sdp_with_ice_options, message);
1605}
1606
1607TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1608 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1609}
1610
1611TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1612 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1613}
1614
1615TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1616 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1617}
1618
1619TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1620 EXPECT_TRUE(TestSerializeRejected(true, false));
1621}
1622
1623TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1624 EXPECT_TRUE(TestSerializeRejected(false, true));
1625}
1626
1627TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1628 EXPECT_TRUE(TestSerializeRejected(true, true));
1629}
1630
1631TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1632 AddRtpDataChannel();
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(kSdpRtpDataChannelString);
1640 EXPECT_EQ(expected_sdp, message);
1641}
1642
1643TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1644 AddSctpDataChannel();
1645 JsepSessionDescription jsep_desc(kDummyString);
1646
1647 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1648 std::string message = webrtc::SdpSerialize(jsep_desc);
1649
1650 std::string expected_sdp = kSdpString;
1651 expected_sdp.append(kSdpSctpDataChannelString);
1652 EXPECT_EQ(message, expected_sdp);
1653}
1654
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001655TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1656 AddSctpDataChannel();
1657 JsepSessionDescription jsep_desc(kDummyString);
1658
1659 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1660 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1661 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1662
1663 const int kNewPort = 1234;
1664 cricket::DataCodec codec(
1665 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1666 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1667 dcdesc->AddOrReplaceCodec(codec);
1668
1669 std::string message = webrtc::SdpSerialize(jsep_desc);
1670
1671 std::string expected_sdp = kSdpString;
1672 expected_sdp.append(kSdpSctpDataChannelString);
1673
1674 char default_portstr[16];
1675 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001676 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001677 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001678 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1679 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001680 new_portstr, strlen(new_portstr),
1681 &expected_sdp);
1682
1683 EXPECT_EQ(expected_sdp, message);
1684}
1685
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001686TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1687 AddRtpDataChannel();
1688 data_desc_->set_bandwidth(100*1000);
1689 JsepSessionDescription jsep_desc(kDummyString);
1690
1691 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1692 std::string message = webrtc::SdpSerialize(jsep_desc);
1693
1694 std::string expected_sdp = kSdpString;
1695 expected_sdp.append(kSdpRtpDataChannelString);
1696 // We want to test that serializing data content ignores bandwidth
1697 // settings (it should always be the default). Thus, we don't do
1698 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001699 // TODO(pthatcher): We need to temporarily allow the SDP to control
1700 // this for backwards-compatibility. Once we don't need that any
1701 // more, remove this.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001702 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 +00001703 "b=AS:100\r\n",
1704 &expected_sdp);
1705 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001706}
1707
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1709 AddExtmap();
1710 JsepSessionDescription desc_with_extmap("dummy");
1711 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1712 kSessionId, kSessionVersion));
1713 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1714
1715 std::string sdp_with_extmap = kSdpString;
1716 InjectAfter("a=mid:audio_content_name\r\n",
1717 kExtmap, &sdp_with_extmap);
1718 InjectAfter("a=mid:video_content_name\r\n",
1719 kExtmap, &sdp_with_extmap);
1720
1721 EXPECT_EQ(sdp_with_extmap, message);
1722}
1723
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001724TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1725 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1726 GetFirstVideoContent(&desc_)->description);
1727 vcd->set_buffered_mode_latency(128);
1728
1729 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1730 jdesc_.session_id(),
1731 jdesc_.session_version()));
1732 std::string message = webrtc::SdpSerialize(jdesc_);
1733 std::string sdp_with_buffer_latency = kSdpFullString;
1734 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1735 "a=x-google-buffer-latency:128\r\n",
1736 &sdp_with_buffer_latency);
1737 EXPECT_EQ(sdp_with_buffer_latency, message);
1738}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739
1740TEST_F(WebRtcSdpTest, SerializeCandidates) {
1741 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001742 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743}
1744
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001745// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1746// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001747TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001748 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001749 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1750 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1751 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001752 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1753 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1754 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1755
1756 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1757 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1758}
1759
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1761 JsepSessionDescription jdesc(kDummyString);
1762 // Deserialize
1763 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1764 // Verify
1765 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1766}
1767
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001768TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1769 JsepSessionDescription jdesc(kDummyString);
1770 const char kSdpWithoutMline[] =
1771 "v=0\r\n"
1772 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1773 "s=-\r\n"
1774 "t=0 0\r\n"
1775 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1776 // Deserialize
1777 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1778 EXPECT_EQ(0u, jdesc.description()->contents().size());
1779}
1780
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1782 JsepSessionDescription jdesc(kDummyString);
1783 std::string sdp_without_carriage_return = kSdpFullString;
1784 Replace("\r\n", "\n", &sdp_without_carriage_return);
1785 // Deserialize
1786 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1787 // Verify
1788 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1789}
1790
1791TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1792 // SessionDescription with desc but without candidates.
1793 JsepSessionDescription jdesc_no_candidates(kDummyString);
1794 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1795 kSessionId, kSessionVersion));
1796 JsepSessionDescription new_jdesc(kDummyString);
1797 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1798 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1799}
1800
1801TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1802 static const char kSdpNoRtpmapString[] =
1803 "v=0\r\n"
1804 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1805 "s=-\r\n"
1806 "t=0 0\r\n"
1807 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1808 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001809 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 // The rtpmap line for static payload codec is optional.
1811 "a=rtpmap:18 G729/16000\r\n"
1812 "a=rtpmap:103 ISAC/16000\r\n";
1813
1814 JsepSessionDescription jdesc(kDummyString);
1815 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1816 cricket::AudioContentDescription* audio =
1817 static_cast<AudioContentDescription*>(
1818 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1819 AudioCodecs ref_codecs;
1820 // The codecs in the AudioContentDescription will be sorted by preference.
1821 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1822 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1823 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1824 EXPECT_EQ(ref_codecs, audio->codecs());
1825}
1826
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001827TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1828 static const char kSdpNoRtpmapString[] =
1829 "v=0\r\n"
1830 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1831 "s=-\r\n"
1832 "t=0 0\r\n"
1833 "m=audio 49232 RTP/AVP 18 103\r\n"
1834 "a=fmtp:18 annexb=yes\r\n"
1835 "a=rtpmap:103 ISAC/16000\r\n";
1836
1837 JsepSessionDescription jdesc(kDummyString);
1838 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1839 cricket::AudioContentDescription* audio =
1840 static_cast<AudioContentDescription*>(
1841 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1842
1843 cricket::AudioCodec g729 = audio->codecs()[0];
1844 EXPECT_EQ("G729", g729.name);
1845 EXPECT_EQ(8000, g729.clockrate);
1846 EXPECT_EQ(18, g729.id);
1847 cricket::CodecParameterMap::iterator found =
1848 g729.params.find("annexb");
1849 ASSERT_TRUE(found != g729.params.end());
1850 EXPECT_EQ(found->second, "yes");
1851
1852 cricket::AudioCodec isac = audio->codecs()[1];
1853 EXPECT_EQ("ISAC", isac.name);
1854 EXPECT_EQ(103, isac.id);
1855 EXPECT_EQ(16000, isac.clockrate);
1856}
1857
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858// Ensure that we can deserialize SDP with a=fingerprint properly.
1859TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1860 // Add a DTLS a=fingerprint attribute to our session description.
1861 AddFingerprint();
1862 JsepSessionDescription new_jdesc(kDummyString);
1863 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1864 jdesc_.session_id(),
1865 jdesc_.session_version()));
1866
1867 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1868 std::string sdp_with_fingerprint = kSdpString;
1869 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1870 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1871 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1872 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1873}
1874
1875TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1876 JsepSessionDescription jdesc_with_bundle(kDummyString);
1877 std::string sdp_with_bundle = kSdpFullString;
1878 InjectAfter(kSessionTime,
1879 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1880 &sdp_with_bundle);
1881 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1882 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1883 group.AddContentName(kAudioContentName);
1884 group.AddContentName(kVideoContentName);
1885 desc_.AddGroup(group);
1886 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1887 jdesc_.session_id(),
1888 jdesc_.session_version()));
1889 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1890}
1891
1892TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1893 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1894 std::string sdp_with_bandwidth = kSdpFullString;
1895 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1896 "b=AS:100\r\n",
1897 &sdp_with_bandwidth);
1898 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1899 "b=AS:50\r\n",
1900 &sdp_with_bandwidth);
1901 EXPECT_TRUE(
1902 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1903 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1904 GetFirstVideoContent(&desc_)->description);
1905 vcd->set_bandwidth(100 * 1000);
1906 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1907 GetFirstAudioContent(&desc_)->description);
1908 acd->set_bandwidth(50 * 1000);
1909 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1910 jdesc_.session_id(),
1911 jdesc_.session_version()));
1912 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1913}
1914
1915TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1916 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1917 std::string sdp_with_ice_options = kSdpFullString;
1918 InjectAfter(kSessionTime,
1919 "a=ice-options:iceoption3\r\n",
1920 &sdp_with_ice_options);
1921 InjectAfter(kAttributeIcePwdVoice,
1922 "a=ice-options:iceoption1\r\n",
1923 &sdp_with_ice_options);
1924 InjectAfter(kAttributeIcePwdVideo,
1925 "a=ice-options:iceoption2\r\n",
1926 &sdp_with_ice_options);
1927 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1928 std::vector<std::string> transport_options;
1929 transport_options.push_back(kIceOption3);
1930 transport_options.push_back(kIceOption1);
1931 AddIceOptions(kAudioContentName, transport_options);
1932 transport_options.clear();
1933 transport_options.push_back(kIceOption3);
1934 transport_options.push_back(kIceOption2);
1935 AddIceOptions(kVideoContentName, transport_options);
1936 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1937 jdesc_.session_id(),
1938 jdesc_.session_version()));
1939 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1940}
1941
1942TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1943 // Remove the original ice-ufrag and ice-pwd
1944 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1945 std::string sdp_with_ufrag_pwd = kSdpFullString;
1946 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1947 // Add session level ufrag and pwd
1948 InjectAfter(kSessionTime,
1949 "a=ice-pwd:session+level+icepwd\r\n"
1950 "a=ice-ufrag:session+level+iceufrag\r\n",
1951 &sdp_with_ufrag_pwd);
1952 // Add media level ufrag and pwd for audio
1953 InjectAfter("a=mid:audio_content_name\r\n",
1954 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1955 &sdp_with_ufrag_pwd);
1956 // Update the candidate ufrag and pwd to the expected ones.
1957 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1958 "media+level+iceufrag", "media+level+icepwd"));
1959 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1960 "session+level+iceufrag", "session+level+icepwd"));
1961 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1962 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1963}
1964
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001965TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1966 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1967 std::string sdp_with_buffer_latency = kSdpFullString;
1968 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1969 "a=x-google-buffer-latency:128\r\n",
1970 &sdp_with_buffer_latency);
1971
1972 EXPECT_TRUE(
1973 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1974 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1975 GetFirstVideoContent(&desc_)->description);
1976 vcd->set_buffered_mode_latency(128);
1977 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1978 jdesc_.session_id(),
1979 jdesc_.session_version()));
1980 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1981}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982
1983TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1984 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1985}
1986
1987TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1988 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1989}
1990
1991TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1992 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1993}
1994
1995TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1996 EXPECT_TRUE(TestDeserializeRejected(true, false));
1997}
1998
1999TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2000 EXPECT_TRUE(TestDeserializeRejected(false, true));
2001}
2002
2003TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2004 EXPECT_TRUE(TestDeserializeRejected(true, true));
2005}
2006
2007// Tests that we can still handle the sdp uses mslabel and label instead of
2008// msid for backward compatibility.
2009TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
2010 JsepSessionDescription jdesc(kDummyString);
2011 std::string sdp_without_msid = kSdpFullString;
2012 Replace("msid", "xmsid", &sdp_without_msid);
2013 // Deserialize
2014 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2015 // Verify
2016 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2017}
2018
2019TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2020 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2021
2022 std::string sdp = kSdpOneCandidate;
2023 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2024 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2025 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2026 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2027
2028 // Candidate line without generation extension.
2029 sdp = kSdpOneCandidate;
2030 Replace(" generation 2", "", &sdp);
2031 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2032 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2033 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2034 Candidate expected = jcandidate_->candidate();
2035 expected.set_generation(0);
2036 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2037
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002038 sdp = kSdpTcpActiveCandidate;
2039 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2040 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002041 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002042 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2043 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2044 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002045 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2046 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2047 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2048 jcandidate_template->candidate()));
2049 sdp = kSdpTcpPassiveCandidate;
2050 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2051 sdp = kSdpTcpSOCandidate;
2052 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053}
2054
2055// This test verifies the deserialization of candidate-attribute
2056// as per RFC 5245. Candiate-attribute will be of the format
2057// candidate:<blah>. This format will be used when candidates
2058// are trickled.
2059TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2060 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2061
2062 std::string candidate_attribute = kRawCandidate;
2063 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2064 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2065 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2066 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2067 EXPECT_EQ(2u, jcandidate.candidate().generation());
2068
2069 // Candidate line without generation extension.
2070 candidate_attribute = kRawCandidate;
2071 Replace(" generation 2", "", &candidate_attribute);
2072 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2073 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2074 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2075 Candidate expected = jcandidate_->candidate();
2076 expected.set_generation(0);
2077 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2078
2079 // Candidate line without candidate:
2080 candidate_attribute = kRawCandidate;
2081 Replace("candidate:", "", &candidate_attribute);
2082 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2083
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002084 // Candidate line with IPV6 address.
2085 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2086}
2087
2088// This test verifies that the deserialization of an invalid candidate string
2089// fails.
2090TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2091 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2092
2093 std::string candidate_attribute = kRawCandidate;
2094 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002096
2097 candidate_attribute = kSdpOneCandidate;
2098 candidate_attribute.replace(0, 1, "x");
2099 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2100
2101 candidate_attribute = kRawCandidate;
2102 candidate_attribute.append("\r\n");
2103 candidate_attribute.append(kRawCandidate);
2104 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2105
2106 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2110 AddRtpDataChannel();
2111 JsepSessionDescription jdesc(kDummyString);
2112 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2113
2114 std::string sdp_with_data = kSdpString;
2115 sdp_with_data.append(kSdpRtpDataChannelString);
2116 JsepSessionDescription jdesc_output(kDummyString);
2117
2118 // Deserialize
2119 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2120 // Verify
2121 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2122}
2123
2124TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2125 AddSctpDataChannel();
2126 JsepSessionDescription jdesc(kDummyString);
2127 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2128
2129 std::string sdp_with_data = kSdpString;
2130 sdp_with_data.append(kSdpSctpDataChannelString);
2131 JsepSessionDescription jdesc_output(kDummyString);
2132
2133 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2134 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2135}
2136
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002137TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2138 AddSctpDataChannel();
2139 JsepSessionDescription jdesc(kDummyString);
2140 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2141
2142 std::string sdp_with_data = kSdpString;
2143 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2144 JsepSessionDescription jdesc_output(kDummyString);
2145
2146 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2147 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2148}
2149
2150// Test to check the behaviour if sctp-port is specified
2151// on the m= line and in a=sctp-port.
2152TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2153 AddSctpDataChannel();
2154 JsepSessionDescription jdesc(kDummyString);
2155 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2156
2157 std::string sdp_with_data = kSdpString;
2158 // Append m= attributes
2159 sdp_with_data.append(kSdpSctpDataChannelString);
2160 // Append a=sctp-port attribute
2161 sdp_with_data.append("a=sctp-port 5000\r\n");
2162 JsepSessionDescription jdesc_output(kDummyString);
2163
2164 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2165}
2166
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002167// For crbug/344475.
2168TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2169 std::string sdp_with_data = kSdpString;
2170 sdp_with_data.append(kSdpSctpDataChannelString);
2171 // Remove the "\n" at the end.
2172 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2173 JsepSessionDescription jdesc_output(kDummyString);
2174
2175 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2176 // No crash is a pass.
2177}
2178
wu@webrtc.org78187522013-10-07 23:32:02 +00002179TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2180 AddSctpDataChannel();
2181 const uint16 kUnusualSctpPort = 9556;
2182 char default_portstr[16];
2183 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002184 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002185 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002186 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002187 kUnusualSctpPort);
2188
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002189 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002190 JsepSessionDescription jdesc(kDummyString);
2191 // take our pre-built session description and change the SCTP port.
2192 cricket::SessionDescription* mutant = desc_.Copy();
2193 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2194 mutant->GetContentDescriptionByName(kDataContentName));
2195 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002196 EXPECT_EQ(1U, codecs.size());
2197 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002198 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002199 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002200
2201 // note: mutant's owned by jdesc now.
2202 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2203 mutant = NULL;
2204
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002205 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002206 std::string sdp_with_data = kSdpString;
2207 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002208 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002209 unusual_portstr, strlen(unusual_portstr),
2210 &sdp_with_data);
2211 JsepSessionDescription jdesc_output(kDummyString);
2212
2213 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2214 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002215
2216 // We need to test the deserialized JsepSessionDescription from
2217 // kSdpSctpDataChannelStringWithSctpPort for
2218 // draft-ietf-mmusic-sctp-sdp-07
2219 // a=sctp-port
2220 sdp_with_data = kSdpString;
2221 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2222 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2223 unusual_portstr, strlen(unusual_portstr),
2224 &sdp_with_data);
2225
2226 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2227 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002228}
2229
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002230TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2231 AddRtpDataChannel();
2232 JsepSessionDescription jdesc(kDummyString);
2233 // We want to test that deserializing data content ignores bandwidth
2234 // settings (it should always be the default). Thus, we don't do
2235 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002236 // TODO(pthatcher): We need to temporarily allow the SDP to control
2237 // this for backwards-compatibility. Once we don't need that any
2238 // more, remove this.
2239 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2240 GetFirstDataContent(&desc_)->description);
2241 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002242 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2243
2244 std::string sdp_with_bandwidth = kSdpString;
2245 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2246 InjectAfter("a=mid:data_content_name\r\n",
2247 "b=AS:100\r\n",
2248 &sdp_with_bandwidth);
2249 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2250
2251 EXPECT_TRUE(
2252 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2253 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2254}
2255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2257 TestDeserializeExtmap(true, false);
2258}
2259
2260TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2261 TestDeserializeExtmap(false, true);
2262}
2263
2264TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2265 TestDeserializeExtmap(true, true);
2266}
2267
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002268TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2269 JsepSessionDescription jdesc(kDummyString);
2270 std::string sdp = kSdpFullString;
2271 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2272 // Deserialize
2273 SdpParseError error;
2274 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2275 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2276 EXPECT_EQ(lastline, error.line);
2277 EXPECT_EQ("Invalid SDP line.", error.description);
2278}
2279
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2281 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2282 std::string new_sdp = kSdpOneCandidate;
2283 Replace("udp", "unsupported_transport", &new_sdp);
2284 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2285 new_sdp = kSdpOneCandidate;
2286 Replace("udp", "uDP", &new_sdp);
2287 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2288 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2289 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2290 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2291}
2292
2293TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2294 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2295 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2296 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2297 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2298 Candidate ref_candidate = jcandidate_->candidate();
2299 ref_candidate.set_username("user_rtp");
2300 ref_candidate.set_password("password_rtp");
2301 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2302}
2303
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002304TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2305 JsepSessionDescription jdesc(kDummyString);
2306
2307 // Deserialize
2308 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2309
2310 // Verify
2311 cricket::AudioContentDescription* audio =
2312 static_cast<AudioContentDescription*>(
2313 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2314 EXPECT_TRUE(audio->conference_mode());
2315
2316 cricket::VideoContentDescription* video =
2317 static_cast<VideoContentDescription*>(
2318 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2319 EXPECT_TRUE(video->conference_mode());
2320}
2321
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2323 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002324 const char kSdpEmptyType[] = " =candidate";
2325 const char kSdpEqualAsPlus[] = "a+candidate";
2326 const char kSdpSpaceAfterEqual[] = "a= candidate";
2327 const char kSdpUpperType[] = "A=candidate";
2328 const char kSdpEmptyLine[] = "";
2329 const char kSdpMissingValue[] = "a=";
2330
2331 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 "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 +00002333 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 "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 +00002335 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 "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 +00002337 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002338 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002339 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340
2341 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002342 ExpectParseFailure("v=", kSdpDestroyer);
2343 ExpectParseFailure("o=", kSdpDestroyer);
2344 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002346 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347
2348 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002349 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2350 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351
2352 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002353 ExpectParseFailure("a=candidate", kSdpEmptyType);
2354 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2355 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2356 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
2358 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2359 // because it's orthogonal to what we are replacing and hence
2360 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002361 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2362 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2363 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2364 ExpectParseFailure("a=sendrecv", kSdpMd5);
2365
2366 // Empty Line
2367 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2368 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002369}
2370
2371TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2372 // ssrc
2373 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2374 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2375 // crypto
2376 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2377 // rtpmap
2378 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2379 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2380 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2381 // candidate
2382 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2383 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2384 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2385 ExpectParseFailure("rport 2346", "rport badvalue");
2386 ExpectParseFailure("rport 2346 generation 2",
2387 "rport 2346 generation badvalue");
2388 // m line
2389 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2390 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2391
2392 // bandwidth
2393 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2394 "b=AS:badvalue\r\n",
2395 "b=AS:badvalue");
2396 // rtcp-fb
2397 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2398 "a=rtcp-fb:badvalue nack\r\n",
2399 "a=rtcp-fb:badvalue nack");
2400 // extmap
2401 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2402 "a=extmap:badvalue http://example.com\r\n",
2403 "a=extmap:badvalue http://example.com");
2404 // x-google-buffer-latency
2405 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2406 "a=x-google-buffer-latency:badvalue\r\n",
2407 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408}
2409
2410TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2411 JsepSessionDescription jdesc_output(kDummyString);
2412
2413 const char kSdpWithReorderedPlTypesString[] =
2414 "v=0\r\n"
2415 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2416 "s=-\r\n"
2417 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002418 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2420 // in the map.
2421 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002422 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423
2424 // Deserialize
2425 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2426
2427 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2428 ASSERT_TRUE(ac != NULL);
2429 const AudioContentDescription* acd =
2430 static_cast<const AudioContentDescription*>(ac->description);
2431 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002432 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2433 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 EXPECT_EQ(104, acd->codecs()[0].id);
2435}
2436
2437TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2438 JsepSessionDescription jdesc_output(kDummyString);
2439 CodecParams params;
2440 params.max_ptime = 40;
2441 params.ptime = 30;
2442 params.min_ptime = 10;
2443 params.sprop_stereo = 1;
2444 params.stereo = 1;
2445 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002446 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 TestDeserializeCodecParams(params, &jdesc_output);
2448 TestSerialize(jdesc_output);
2449}
2450
2451TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2452 const bool kUseWildcard = false;
2453 JsepSessionDescription jdesc_output(kDummyString);
2454 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2455 TestSerialize(jdesc_output);
2456}
2457
2458TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2459 const bool kUseWildcard = true;
2460 JsepSessionDescription jdesc_output(kDummyString);
2461 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2462 TestSerialize(jdesc_output);
2463}
2464
2465TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2466 JsepSessionDescription jdesc_output(kDummyString);
2467
2468 const char kSdpWithFmtpString[] =
2469 "v=0\r\n"
2470 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2471 "s=-\r\n"
2472 "t=0 0\r\n"
2473 "m=video 3457 RTP/SAVPF 120\r\n"
2474 "a=rtpmap:120 VP8/90000\r\n"
2475 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2476
2477 // Deserialize
2478 SdpParseError error;
2479 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2480 &error));
2481
2482 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2483 ASSERT_TRUE(vc != NULL);
2484 const VideoContentDescription* vcd =
2485 static_cast<const VideoContentDescription*>(vc->description);
2486 ASSERT_FALSE(vcd->codecs().empty());
2487 cricket::VideoCodec vp8 = vcd->codecs()[0];
2488 EXPECT_EQ("VP8", vp8.name);
2489 EXPECT_EQ(120, vp8.id);
2490 cricket::CodecParameterMap::iterator found =
2491 vp8.params.find("x-google-min-bitrate");
2492 ASSERT_TRUE(found != vp8.params.end());
2493 EXPECT_EQ(found->second, "10");
2494 found = vp8.params.find("x-google-max-quantization");
2495 ASSERT_TRUE(found != vp8.params.end());
2496 EXPECT_EQ(found->second, "40");
2497}
2498
2499TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2500 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2501 GetFirstVideoContent(&desc_)->description);
2502
2503 cricket::VideoCodecs codecs = vcd->codecs();
2504 codecs[0].params["x-google-min-bitrate"] = "10";
2505 vcd->set_codecs(codecs);
2506
2507 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2508 jdesc_.session_id(),
2509 jdesc_.session_version()));
2510 std::string message = webrtc::SdpSerialize(jdesc_);
2511 std::string sdp_with_fmtp = kSdpFullString;
2512 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2513 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2514 &sdp_with_fmtp);
2515 EXPECT_EQ(sdp_with_fmtp, message);
2516}
2517
2518TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2519 JsepSessionDescription jdesc_with_icelite(kDummyString);
2520 std::string sdp_with_icelite = kSdpFullString;
2521 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2522 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2523 const cricket::TransportInfo* tinfo1 =
2524 desc->GetTransportInfoByName("audio_content_name");
2525 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2526 const cricket::TransportInfo* tinfo2 =
2527 desc->GetTransportInfoByName("video_content_name");
2528 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2529 InjectAfter(kSessionTime,
2530 "a=ice-lite\r\n",
2531 &sdp_with_icelite);
2532 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2533 desc = jdesc_with_icelite.description();
2534 const cricket::TransportInfo* atinfo =
2535 desc->GetTransportInfoByName("audio_content_name");
2536 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2537 const cricket::TransportInfo* vtinfo =
2538 desc->GetTransportInfoByName("video_content_name");
2539 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2540}
2541
2542// Verifies that the candidates in the input SDP are parsed and serialized
2543// correctly in the output SDP.
2544TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2545 std::string sdp_with_data = kSdpString;
2546 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2547 JsepSessionDescription jdesc_output(kDummyString);
2548
2549 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2550 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2551}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002552
2553TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2554 AddFingerprint();
2555 TransportInfo audio_transport_info =
2556 *(desc_.GetTransportInfoByName(kAudioContentName));
2557 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2558 audio_transport_info.description.connection_role);
2559 audio_transport_info.description.connection_role =
2560 cricket::CONNECTIONROLE_ACTIVE;
2561
2562 TransportInfo video_transport_info =
2563 *(desc_.GetTransportInfoByName(kVideoContentName));
2564 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2565 video_transport_info.description.connection_role);
2566 video_transport_info.description.connection_role =
2567 cricket::CONNECTIONROLE_ACTIVE;
2568
2569 desc_.RemoveTransportInfoByName(kAudioContentName);
2570 desc_.RemoveTransportInfoByName(kVideoContentName);
2571
2572 desc_.AddTransportInfo(audio_transport_info);
2573 desc_.AddTransportInfo(video_transport_info);
2574
2575 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2576 jdesc_.session_id(),
2577 jdesc_.session_version()));
2578 std::string message = webrtc::SdpSerialize(jdesc_);
2579 std::string sdp_with_dtlssetup = kSdpFullString;
2580
2581 // Fingerprint attribute is necessary to add DTLS setup attribute.
2582 InjectAfter(kAttributeIcePwdVoice,
2583 kFingerprint, &sdp_with_dtlssetup);
2584 InjectAfter(kAttributeIcePwdVideo,
2585 kFingerprint, &sdp_with_dtlssetup);
2586 // Now adding |setup| attribute.
2587 InjectAfter(kFingerprint,
2588 "a=setup:active\r\n", &sdp_with_dtlssetup);
2589 EXPECT_EQ(sdp_with_dtlssetup, message);
2590}
2591
2592TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2593 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2594 std::string sdp_with_dtlssetup = kSdpFullString;
2595 InjectAfter(kSessionTime,
2596 "a=setup:actpass\r\n",
2597 &sdp_with_dtlssetup);
2598 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2599 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2600 const cricket::TransportInfo* atinfo =
2601 desc->GetTransportInfoByName("audio_content_name");
2602 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2603 atinfo->description.connection_role);
2604 const cricket::TransportInfo* vtinfo =
2605 desc->GetTransportInfoByName("video_content_name");
2606 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2607 vtinfo->description.connection_role);
2608}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002609
2610// Verifies that the order of the serialized m-lines follows the order of the
2611// ContentInfo in SessionDescription, and vise versa for deserialization.
2612TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2613 JsepSessionDescription jdesc(kDummyString);
2614 const std::string media_content_sdps[3] = {
2615 kSdpAudioString,
2616 kSdpVideoString,
2617 kSdpSctpDataChannelString
2618 };
2619 const cricket::MediaType media_types[3] = {
2620 cricket::MEDIA_TYPE_AUDIO,
2621 cricket::MEDIA_TYPE_VIDEO,
2622 cricket::MEDIA_TYPE_DATA
2623 };
2624
2625 // Verifies all 6 permutations.
2626 for (size_t i = 0; i < 6; ++i) {
2627 size_t media_content_in_sdp[3];
2628 // The index of the first media content.
2629 media_content_in_sdp[0] = i / 2;
2630 // The index of the second media content.
2631 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2632 // The index of the third media content.
2633 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2634
2635 std::string sdp_string = kSdpSessionString;
2636 for (size_t i = 0; i < 3; ++i)
2637 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2638
2639 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2640 cricket::SessionDescription* desc = jdesc.description();
2641 EXPECT_EQ(3u, desc->contents().size());
2642
2643 for (size_t i = 0; i < 3; ++i) {
2644 const cricket::MediaContentDescription* mdesc =
2645 static_cast<const cricket::MediaContentDescription*>(
2646 desc->contents()[i].description);
2647 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2648 }
2649
2650 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2651 EXPECT_EQ(sdp_string, serialized_sdp);
2652 }
2653}