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