blob: cc684d2ce50a145f418e5f3bd5ca9dffb40b7deb [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2011, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <set>
29#include <string>
30#include <vector>
31
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/webrtcsdp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/constants.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035#include "webrtc/p2p/base/constants.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/gunit.h"
38#include "webrtc/base/logging.h"
39#include "webrtc/base/messagedigest.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/sslfingerprint.h"
42#include "webrtc/base/stringencode.h"
43#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45using cricket::AudioCodec;
46using cricket::AudioContentDescription;
47using cricket::Candidate;
48using cricket::ContentInfo;
49using cricket::CryptoParams;
50using cricket::ContentGroup;
51using cricket::DataCodec;
52using cricket::DataContentDescription;
53using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
54using cricket::ICE_CANDIDATE_COMPONENT_RTP;
55using cricket::kFecSsrcGroupSemantics;
56using cricket::LOCAL_PORT_TYPE;
57using cricket::NS_JINGLE_DRAFT_SCTP;
58using cricket::NS_JINGLE_ICE_UDP;
59using cricket::NS_JINGLE_RTP;
60using cricket::RtpHeaderExtension;
61using cricket::RELAY_PORT_TYPE;
62using cricket::SessionDescription;
63using cricket::StreamParams;
64using cricket::STUN_PORT_TYPE;
65using cricket::TransportDescription;
66using cricket::TransportInfo;
67using cricket::VideoCodec;
68using cricket::VideoContentDescription;
69using webrtc::IceCandidateCollection;
70using webrtc::IceCandidateInterface;
71using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
73using webrtc::SdpParseError;
74using webrtc::SessionDescriptionInterface;
75
76typedef std::vector<AudioCodec> AudioCodecs;
77typedef std::vector<Candidate> Candidates;
78
wu@webrtc.org78187522013-10-07 23:32:02 +000079static const uint32 kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080static const char kSessionTime[] = "t=0 0\r\n";
81static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0
82static const char kCandidateUfragVoice[] = "ufrag_voice";
83static const char kCandidatePwdVoice[] = "pwd_voice";
84static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
85static const char kCandidateUfragVideo[] = "ufrag_video";
86static const char kCandidatePwdVideo[] = "pwd_video";
87static const char kCandidateUfragData[] = "ufrag_data";
88static const char kCandidatePwdData[] = "pwd_data";
89static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
90static const uint32 kCandidateGeneration = 2;
91static const char kCandidateFoundation1[] = "a0+B/1";
92static const char kCandidateFoundation2[] = "a0+B/2";
93static const char kCandidateFoundation3[] = "a0+B/3";
94static const char kCandidateFoundation4[] = "a0+B/4";
95static const char kAttributeCryptoVoice[] =
96 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
97 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
98 "dummy_session_params\r\n";
99static const char kAttributeCryptoVideo[] =
100 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
101 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
102static const char kFingerprint[] = "a=fingerprint:sha-1 "
103 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
104static const int kExtmapId = 1;
105static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
106static const char kExtmap[] =
107 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
108static const char kExtmapWithDirectionAndAttribute[] =
109 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
110
111static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1,
112 0x3F, 0x82, 0x18, 0x3B,
113 0x54, 0x02, 0x12, 0xDF,
114 0x3E, 0x5D, 0x49, 0x6B,
115 0x19, 0xE5, 0x7C, 0xAB};
116
117struct CodecParams {
118 int max_ptime;
119 int ptime;
120 int min_ptime;
121 int sprop_stereo;
122 int stereo;
123 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000124 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125};
126
127// Reference sdp string
128static const char kSdpFullString[] =
129 "v=0\r\n"
130 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
134 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
135 "c=IN IP4 74.125.127.126\r\n"
136 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
137 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
144 "generation 2\r\n"
145 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
146 "raddr 192.168.1.5 rport 2346 "
147 "generation 2\r\n"
148 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
149 "raddr 192.168.1.5 rport 2348 "
150 "generation 2\r\n"
151 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
152 "a=mid:audio_content_name\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
156 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
157 "dummy_session_params\r\n"
158 "a=rtpmap:111 opus/48000/2\r\n"
159 "a=rtpmap:103 ISAC/16000\r\n"
160 "a=rtpmap:104 CELT/32000/2\r\n"
161 "a=ssrc:1 cname:stream_1_cname\r\n"
162 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
163 "a=ssrc:1 mslabel:local_stream_1\r\n"
164 "a=ssrc:1 label:audio_track_id_1\r\n"
165 "a=ssrc:4 cname:stream_2_cname\r\n"
166 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
167 "a=ssrc:4 mslabel:local_stream_2\r\n"
168 "a=ssrc:4 label:audio_track_id_2\r\n"
169 "m=video 3457 RTP/SAVPF 120\r\n"
170 "c=IN IP4 74.125.224.39\r\n"
171 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
172 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
173 "generation 2\r\n"
174 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
175 "generation 2\r\n"
176 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
177 "generation 2\r\n"
178 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
179 "generation 2\r\n"
180 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
181 "generation 2\r\n"
182 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
183 "generation 2\r\n"
184 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
185 "a=mid:video_content_name\r\n"
186 "a=sendrecv\r\n"
187 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
188 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
189 "a=rtpmap:120 VP8/90000\r\n"
190 "a=ssrc:2 cname:stream_1_cname\r\n"
191 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
192 "a=ssrc:2 mslabel:local_stream_1\r\n"
193 "a=ssrc:2 label:video_track_id_1\r\n"
194 "a=ssrc:3 cname:stream_1_cname\r\n"
195 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
196 "a=ssrc:3 mslabel:local_stream_1\r\n"
197 "a=ssrc:3 label:video_track_id_2\r\n"
198 "a=ssrc-group:FEC 5 6\r\n"
199 "a=ssrc:5 cname:stream_2_cname\r\n"
200 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
201 "a=ssrc:5 mslabel:local_stream_2\r\n"
202 "a=ssrc:5 label:video_track_id_3\r\n"
203 "a=ssrc:6 cname:stream_2_cname\r\n"
204 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
205 "a=ssrc:6 mslabel:local_stream_2\r\n"
206 "a=ssrc:6 label:video_track_id_3\r\n";
207
208// SDP reference string without the candidates.
209static const char kSdpString[] =
210 "v=0\r\n"
211 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
214 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000215 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
219 "a=mid:audio_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
223 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
224 "dummy_session_params\r\n"
225 "a=rtpmap:111 opus/48000/2\r\n"
226 "a=rtpmap:103 ISAC/16000\r\n"
227 "a=rtpmap:104 CELT/32000/2\r\n"
228 "a=ssrc:1 cname:stream_1_cname\r\n"
229 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
230 "a=ssrc:1 mslabel:local_stream_1\r\n"
231 "a=ssrc:1 label:audio_track_id_1\r\n"
232 "a=ssrc:4 cname:stream_2_cname\r\n"
233 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
234 "a=ssrc:4 mslabel:local_stream_2\r\n"
235 "a=ssrc:4 label:audio_track_id_2\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000236 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
240 "a=mid:video_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
244 "a=rtpmap:120 VP8/90000\r\n"
245 "a=ssrc:2 cname:stream_1_cname\r\n"
246 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
247 "a=ssrc:2 mslabel:local_stream_1\r\n"
248 "a=ssrc:2 label:video_track_id_1\r\n"
249 "a=ssrc:3 cname:stream_1_cname\r\n"
250 "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n"
251 "a=ssrc:3 mslabel:local_stream_1\r\n"
252 "a=ssrc:3 label:video_track_id_2\r\n"
253 "a=ssrc-group:FEC 5 6\r\n"
254 "a=ssrc:5 cname:stream_2_cname\r\n"
255 "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n"
256 "a=ssrc:5 mslabel:local_stream_2\r\n"
257 "a=ssrc:5 label:video_track_id_3\r\n"
258 "a=ssrc:6 cname:stream_2_cname\r\n"
259 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
260 "a=ssrc:6 mslabel:local_stream_2\r\n"
261 "a=ssrc:6 label:video_track_id_3\r\n";
262
263static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000264 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000265 "c=IN IP4 0.0.0.0\r\n"
266 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n"
270 "a=sendrecv\r\n"
271 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
272 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
273 "a=rtpmap:101 google-data/90000\r\n"
274 "a=ssrc:10 cname:data_channel_cname\r\n"
275 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
276 "a=ssrc:10 mslabel:data_channel\r\n"
277 "a=ssrc:10 label:data_channeld0\r\n";
278
279static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000280 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000281 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 "a=ice-ufrag:ufrag_data\r\n"
283 "a=ice-pwd:pwd_data\r\n"
284 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000287// draft-ietf-mmusic-sctp-sdp-07
288static const char kSdpSctpDataChannelStringWithSctpPort[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000289 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000290 "a=fmtp:webrtc-datachannel max-message-size=100000\r\n"
291 "a=sctp-port 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000292 "c=IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000293 "a=ice-ufrag:ufrag_data\r\n"
294 "a=ice-pwd:pwd_data\r\n"
295 "a=mid:data_content_name\r\n";
296
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297static const char kSdpSctpDataChannelWithCandidatesString[] =
298 "m=application 2345 DTLS/SCTP 5000\r\n"
299 "c=IN IP4 74.125.127.126\r\n"
300 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
301 "generation 2\r\n"
302 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
303 "generation 2\r\n"
304 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
305 "raddr 192.168.1.5 rport 2346 "
306 "generation 2\r\n"
307 "a=ice-ufrag:ufrag_data\r\n"
308 "a=ice-pwd:pwd_data\r\n"
309 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000310 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000312static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000313 "v=0\r\n"
314 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
315 "s=-\r\n"
316 "t=0 0\r\n"
317 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000318 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000319 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000321 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000322 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000323 "a=x-google-flag:conference\r\n";
324
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000325static const char kSdpSessionString[] =
326 "v=0\r\n"
327 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
328 "s=-\r\n"
329 "t=0 0\r\n"
330 "a=msid-semantic: WMS local_stream\r\n";
331
332static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000333 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000334 "c=IN IP4 0.0.0.0\r\n"
335 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000336 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
337 "a=mid:audio_content_name\r\n"
338 "a=sendrecv\r\n"
339 "a=rtpmap:111 opus/48000/2\r\n"
340 "a=ssrc:1 cname:stream_1_cname\r\n"
341 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
342 "a=ssrc:1 mslabel:local_stream\r\n"
343 "a=ssrc:1 label:audio_track_id_1\r\n";
344
345static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000346 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000347 "c=IN IP4 0.0.0.0\r\n"
348 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000349 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
350 "a=mid:video_content_name\r\n"
351 "a=sendrecv\r\n"
352 "a=rtpmap:120 VP8/90000\r\n"
353 "a=ssrc:2 cname:stream_1_cname\r\n"
354 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
355 "a=ssrc:2 mslabel:local_stream\r\n"
356 "a=ssrc:2 label:video_track_id_1\r\n";
357
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358
359// One candidate reference string as per W3c spec.
360// candidate:<blah> not a=candidate:<blah>CRLF
361static const char kRawCandidate[] =
362 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
363// One candidate reference string.
364static const char kSdpOneCandidate[] =
365 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
366 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000367
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000368static const char kSdpTcpActiveCandidate[] =
369 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
370 "tcptype active generation 2";
371static const char kSdpTcpPassiveCandidate[] =
372 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
373 "tcptype passive generation 2";
374static const char kSdpTcpSOCandidate[] =
375 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
376 "tcptype so generation 2";
377static const char kSdpTcpInvalidCandidate[] =
378 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
379 "tcptype invalid generation 2";
380
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000381// One candidate reference string with IPV6 address.
382static const char kRawIPV6Candidate[] =
383 "candidate:a0+B/1 1 udp 2130706432 "
384 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385
386// One candidate reference string.
387static const char kSdpOneCandidateOldFormat[] =
388 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
389 " eth0 username user_rtp password password_rtp generation 2\r\n";
390
391// Session id and version
392static const char kSessionId[] = "18446744069414584320";
393static const char kSessionVersion[] = "18446462598732840960";
394
395// Ice options
396static const char kIceOption1[] = "iceoption1";
397static const char kIceOption2[] = "iceoption2";
398static const char kIceOption3[] = "iceoption3";
399
400// Content name
401static const char kAudioContentName[] = "audio_content_name";
402static const char kVideoContentName[] = "video_content_name";
403static const char kDataContentName[] = "data_content_name";
404
405// MediaStream 1
406static const char kStreamLabel1[] = "local_stream_1";
407static const char kStream1Cname[] = "stream_1_cname";
408static const char kAudioTrackId1[] = "audio_track_id_1";
409static const uint32 kAudioTrack1Ssrc = 1;
410static const char kVideoTrackId1[] = "video_track_id_1";
411static const uint32 kVideoTrack1Ssrc = 2;
412static const char kVideoTrackId2[] = "video_track_id_2";
413static const uint32 kVideoTrack2Ssrc = 3;
414
415// MediaStream 2
416static const char kStreamLabel2[] = "local_stream_2";
417static const char kStream2Cname[] = "stream_2_cname";
418static const char kAudioTrackId2[] = "audio_track_id_2";
419static const uint32 kAudioTrack2Ssrc = 4;
420static const char kVideoTrackId3[] = "video_track_id_3";
421static const uint32 kVideoTrack3Ssrc = 5;
422static const uint32 kVideoTrack4Ssrc = 6;
423
424// DataChannel
425static const char kDataChannelLabel[] = "data_channel";
426static const char kDataChannelMsid[] = "data_channeld0";
427static const char kDataChannelCname[] = "data_channel_cname";
428static const uint32 kDataChannelSsrc = 10;
429
430// Candidate
431static const char kDummyMid[] = "dummy_mid";
432static const int kDummyIndex = 123;
433
434// Misc
435static const char kDummyString[] = "dummy";
436
437// Helper functions
438
439static bool SdpDeserialize(const std::string& message,
440 JsepSessionDescription* jdesc) {
441 return webrtc::SdpDeserialize(message, jdesc, NULL);
442}
443
444static bool SdpDeserializeCandidate(const std::string& message,
445 JsepIceCandidate* candidate) {
446 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
447}
448
449// Add some extra |newlines| to the |message| after |line|.
450static void InjectAfter(const std::string& line,
451 const std::string& newlines,
452 std::string* message) {
453 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 tmp.c_str(), tmp.length(), message);
456}
457
458static void Replace(const std::string& line,
459 const std::string& newlines,
460 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 newlines.c_str(), newlines.length(), message);
463}
464
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000465// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
466// message.
467static void ExpectParseFailure(const std::string& bad_sdp,
468 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000471 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000473 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
474}
475
476// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
477static void ExpectParseFailure(const char* good_part, const char* bad_part) {
478 std::string bad_sdp = kSdpFullString;
479 Replace(good_part, bad_part, &bad_sdp);
480 ExpectParseFailure(bad_sdp, bad_part);
481}
482
483// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
484static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
485 const std::string& newlines,
486 const std::string& bad_part) {
487 std::string bad_sdp = kSdpFullString;
488 InjectAfter(injectpoint, newlines, &bad_sdp);
489 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490}
491
492static void ReplaceDirection(cricket::MediaContentDirection direction,
493 std::string* message) {
494 std::string new_direction;
495 switch (direction) {
496 case cricket::MD_INACTIVE:
497 new_direction = "a=inactive";
498 break;
499 case cricket::MD_SENDONLY:
500 new_direction = "a=sendonly";
501 break;
502 case cricket::MD_RECVONLY:
503 new_direction = "a=recvonly";
504 break;
505 case cricket::MD_SENDRECV:
506 default:
507 new_direction = "a=sendrecv";
508 break;
509 }
510 Replace("a=sendrecv", new_direction, message);
511}
512
513static void ReplaceRejected(bool audio_rejected, bool video_rejected,
514 std::string* message) {
515 if (audio_rejected) {
516 Replace("m=audio 2345", "m=audio 0", message);
517 }
518 if (video_rejected) {
519 Replace("m=video 3457", "m=video 0", message);
520 }
521}
522
523// WebRtcSdpTest
524
525class WebRtcSdpTest : public testing::Test {
526 public:
527 WebRtcSdpTest()
528 : jdesc_(kDummyString) {
529 // AudioContentDescription
530 audio_desc_ = CreateAudioContentDescription();
531 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
532 audio_desc_->AddCodec(opus);
533 audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
534 audio_desc_->AddCodec(AudioCodec(104, "CELT", 32000, 0, 2, 1));
535 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
536
537 // VideoContentDescription
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 rtc::scoped_ptr<VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 new VideoContentDescription());
540 video_desc_ = video.get();
541 StreamParams video_stream1;
542 video_stream1.id = kVideoTrackId1;
543 video_stream1.cname = kStream1Cname;
544 video_stream1.sync_label = kStreamLabel1;
545 video_stream1.ssrcs.push_back(kVideoTrack1Ssrc);
546 video->AddStream(video_stream1);
547 StreamParams video_stream2;
548 video_stream2.id = kVideoTrackId2;
549 video_stream2.cname = kStream1Cname;
550 video_stream2.sync_label = kStreamLabel1;
551 video_stream2.ssrcs.push_back(kVideoTrack2Ssrc);
552 video->AddStream(video_stream2);
553 StreamParams video_stream3;
554 video_stream3.id = kVideoTrackId3;
555 video_stream3.cname = kStream2Cname;
556 video_stream3.sync_label = kStreamLabel2;
557 video_stream3.ssrcs.push_back(kVideoTrack3Ssrc);
558 video_stream3.ssrcs.push_back(kVideoTrack4Ssrc);
559 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs);
560 video_stream3.ssrc_groups.push_back(ssrc_group);
561 video->AddStream(video_stream3);
562 video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
563 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
564 video->set_protocol(cricket::kMediaProtocolSavpf);
565 video->AddCodec(VideoCodec(
566 120,
567 JsepSessionDescription::kDefaultVideoCodecName,
568 JsepSessionDescription::kMaxVideoCodecWidth,
569 JsepSessionDescription::kMaxVideoCodecHeight,
570 JsepSessionDescription::kDefaultVideoCodecFramerate,
571 JsepSessionDescription::kDefaultVideoCodecPreference));
572
573 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP,
574 video.release());
575
576 // TransportInfo
577 EXPECT_TRUE(desc_.AddTransportInfo(
578 TransportInfo(kAudioContentName,
579 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 kCandidateUfragVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000581 kCandidatePwdVoice))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 EXPECT_TRUE(desc_.AddTransportInfo(
583 TransportInfo(kVideoContentName,
584 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 kCandidateUfragVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000586 kCandidatePwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587
588 // v4 host
589 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000591 Candidate candidate1("", ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
592 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
593 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000595 Candidate candidate2("", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
596 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
597 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000599 Candidate candidate3("", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
600 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
601 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000603 Candidate candidate4("", ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
604 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.org950c5182014-12-16 23:01:31 +0000609 cricket::Candidate candidate5("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
610 "udp", v6_address, kCandidatePriority, "", "",
611 cricket::LOCAL_PORT_TYPE,
612 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 v6_address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000614 cricket::Candidate candidate6("", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
615 "udp", v6_address, kCandidatePriority, "", "",
616 cricket::LOCAL_PORT_TYPE,
617 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 v6_address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000619 cricket::Candidate candidate7("", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
620 "udp", v6_address, kCandidatePriority, "", "",
621 cricket::LOCAL_PORT_TYPE,
622 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 v6_address.SetPort(port++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000624 cricket::Candidate candidate8("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
625 "udp", v6_address, kCandidatePriority, "", "",
626 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.org950c5182014-12-16 23:01:31 +0000633 cricket::Candidate candidate9("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
634 "udp", address_stun, kCandidatePriority, "",
635 "", STUN_PORT_TYPE, kCandidateGeneration,
636 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.org950c5182014-12-16 23:01:31 +0000641 cricket::Candidate candidate10("", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
642 "udp", address_stun, kCandidatePriority, "",
643 "", STUN_PORT_TYPE, kCandidateGeneration,
644 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.org950c5182014-12-16 23:01:31 +0000650 cricket::Candidate candidate11("", cricket::ICE_CANDIDATE_COMPONENT_RTCP,
651 "udp", address_relay, kCandidatePriority, "",
652 "", cricket::RELAY_PORT_TYPE,
653 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 address_relay.SetPort(port_relay++);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000655 cricket::Candidate candidate12("", cricket::ICE_CANDIDATE_COMPONENT_RTP,
656 "udp", address_relay, kCandidatePriority, "",
657 "", RELAY_PORT_TYPE, kCandidateGeneration,
658 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659
660 // voice
661 candidates_.push_back(candidate1);
662 candidates_.push_back(candidate2);
663 candidates_.push_back(candidate5);
664 candidates_.push_back(candidate6);
665 candidates_.push_back(candidate9);
666 candidates_.push_back(candidate10);
667
668 // video
669 candidates_.push_back(candidate3);
670 candidates_.push_back(candidate4);
671 candidates_.push_back(candidate7);
672 candidates_.push_back(candidate8);
673 candidates_.push_back(candidate11);
674 candidates_.push_back(candidate12);
675
676 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
677 0, candidate1));
678
679 // Set up JsepSessionDescription.
680 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
681 std::string mline_id;
682 int mline_index = 0;
683 for (size_t i = 0; i< candidates_.size(); ++i) {
684 // In this test, the audio m line index will be 0, and the video m line
685 // will be 1.
686 bool is_video = (i > 5);
687 mline_id = is_video ? "video_content_name" : "audio_content_name";
688 mline_index = is_video ? 1 : 0;
689 JsepIceCandidate jice(mline_id,
690 mline_index,
691 candidates_.at(i));
692 jdesc_.AddCandidate(&jice);
693 }
694 }
695
696 AudioContentDescription* CreateAudioContentDescription() {
697 AudioContentDescription* audio = new AudioContentDescription();
698 audio->set_rtcp_mux(true);
699 StreamParams audio_stream1;
700 audio_stream1.id = kAudioTrackId1;
701 audio_stream1.cname = kStream1Cname;
702 audio_stream1.sync_label = kStreamLabel1;
703 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
704 audio->AddStream(audio_stream1);
705 StreamParams audio_stream2;
706 audio_stream2.id = kAudioTrackId2;
707 audio_stream2.cname = kStream2Cname;
708 audio_stream2.sync_label = kStreamLabel2;
709 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
710 audio->AddStream(audio_stream2);
711 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
712 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
713 "dummy_session_params"));
714 audio->set_protocol(cricket::kMediaProtocolSavpf);
715 return audio;
716 }
717
718 template <class MCD>
719 void CompareMediaContentDescription(const MCD* cd1,
720 const MCD* cd2) {
721 // type
722 EXPECT_EQ(cd1->type(), cd1->type());
723
724 // content direction
725 EXPECT_EQ(cd1->direction(), cd2->direction());
726
727 // rtcp_mux
728 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
729
730 // cryptos
731 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
732 if (cd1->cryptos().size() != cd2->cryptos().size()) {
733 ADD_FAILURE();
734 return;
735 }
736 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
737 const CryptoParams c1 = cd1->cryptos().at(i);
738 const CryptoParams c2 = cd2->cryptos().at(i);
739 EXPECT_TRUE(c1.Matches(c2));
740 EXPECT_EQ(c1.key_params, c2.key_params);
741 EXPECT_EQ(c1.session_params, c2.session_params);
742 }
743 // protocol
744 EXPECT_EQ(cd1->protocol(), cd2->protocol());
745
746 // codecs
747 EXPECT_EQ(cd1->codecs(), cd2->codecs());
748
749 // bandwidth
750 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
751
752 // streams
753 EXPECT_EQ(cd1->streams(), cd2->streams());
754
755 // extmap
756 ASSERT_EQ(cd1->rtp_header_extensions().size(),
757 cd2->rtp_header_extensions().size());
758 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
759 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
760 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
761 EXPECT_EQ(ext1.uri, ext2.uri);
762 EXPECT_EQ(ext1.id, ext2.id);
763 }
764
765 // buffered mode latency
766 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
767 }
768
769
770 void CompareSessionDescription(const SessionDescription& desc1,
771 const SessionDescription& desc2) {
772 // Compare content descriptions.
773 if (desc1.contents().size() != desc2.contents().size()) {
774 ADD_FAILURE();
775 return;
776 }
777 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
778 const cricket::ContentInfo& c1 = desc1.contents().at(i);
779 const cricket::ContentInfo& c2 = desc2.contents().at(i);
780 // content name
781 EXPECT_EQ(c1.name, c2.name);
782 // content type
783 // Note, ASSERT will return from the function, but will not stop the test.
784 ASSERT_EQ(c1.type, c2.type);
785
786 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
787 if (IsAudioContent(&c1)) {
788 const AudioContentDescription* acd1 =
789 static_cast<const AudioContentDescription*>(c1.description);
790 const AudioContentDescription* acd2 =
791 static_cast<const AudioContentDescription*>(c2.description);
792 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
793 }
794
795 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
796 if (IsVideoContent(&c1)) {
797 const VideoContentDescription* vcd1 =
798 static_cast<const VideoContentDescription*>(c1.description);
799 const VideoContentDescription* vcd2 =
800 static_cast<const VideoContentDescription*>(c2.description);
801 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
802 }
803
804 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
805 if (IsDataContent(&c1)) {
806 const DataContentDescription* dcd1 =
807 static_cast<const DataContentDescription*>(c1.description);
808 const DataContentDescription* dcd2 =
809 static_cast<const DataContentDescription*>(c2.description);
810 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
811 }
812 }
813
814 // group
815 const cricket::ContentGroups groups1 = desc1.groups();
816 const cricket::ContentGroups groups2 = desc2.groups();
817 EXPECT_EQ(groups1.size(), groups1.size());
818 if (groups1.size() != groups2.size()) {
819 ADD_FAILURE();
820 return;
821 }
822 for (size_t i = 0; i < groups1.size(); ++i) {
823 const cricket::ContentGroup group1 = groups1.at(i);
824 const cricket::ContentGroup group2 = groups2.at(i);
825 EXPECT_EQ(group1.semantics(), group2.semantics());
826 const cricket::ContentNames names1 = group1.content_names();
827 const cricket::ContentNames names2 = group2.content_names();
828 EXPECT_EQ(names1.size(), names2.size());
829 if (names1.size() != names2.size()) {
830 ADD_FAILURE();
831 return;
832 }
833 cricket::ContentNames::const_iterator iter1 = names1.begin();
834 cricket::ContentNames::const_iterator iter2 = names2.begin();
835 while (iter1 != names1.end()) {
836 EXPECT_EQ(*iter1++, *iter2++);
837 }
838 }
839
840 // transport info
841 const cricket::TransportInfos transports1 = desc1.transport_infos();
842 const cricket::TransportInfos transports2 = desc2.transport_infos();
843 EXPECT_EQ(transports1.size(), transports2.size());
844 if (transports1.size() != transports2.size()) {
845 ADD_FAILURE();
846 return;
847 }
848 for (size_t i = 0; i < transports1.size(); ++i) {
849 const cricket::TransportInfo transport1 = transports1.at(i);
850 const cricket::TransportInfo transport2 = transports2.at(i);
851 EXPECT_EQ(transport1.content_name, transport2.content_name);
852 EXPECT_EQ(transport1.description.transport_type,
853 transport2.description.transport_type);
854 EXPECT_EQ(transport1.description.ice_ufrag,
855 transport2.description.ice_ufrag);
856 EXPECT_EQ(transport1.description.ice_pwd,
857 transport2.description.ice_pwd);
858 if (transport1.description.identity_fingerprint) {
859 EXPECT_EQ(*transport1.description.identity_fingerprint,
860 *transport2.description.identity_fingerprint);
861 } else {
862 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
863 transport2.description.identity_fingerprint.get());
864 }
865 EXPECT_EQ(transport1.description.transport_options,
866 transport2.description.transport_options);
867 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
868 transport2.description.candidates));
869 }
870 }
871
872 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
873 EXPECT_EQ(cs1.size(), cs2.size());
874 if (cs1.size() != cs2.size())
875 return false;
876 for (size_t i = 0; i< cs1.size(); ++i) {
877 const Candidate c1 = cs1.at(i);
878 const Candidate c2 = cs2.at(i);
879 EXPECT_TRUE(c1.IsEquivalent(c2));
880 }
881 return true;
882 }
883
884 bool CompareSessionDescription(
885 const JsepSessionDescription& desc1,
886 const JsepSessionDescription& desc2) {
887 EXPECT_EQ(desc1.session_id(), desc2.session_id());
888 EXPECT_EQ(desc1.session_version(), desc2.session_version());
889 CompareSessionDescription(*desc1.description(), *desc2.description());
890 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
891 return false;
892 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
893 const IceCandidateCollection* cc1 = desc1.candidates(i);
894 const IceCandidateCollection* cc2 = desc2.candidates(i);
895 if (cc1->count() != cc2->count())
896 return false;
897 for (size_t j = 0; j < cc1->count(); ++j) {
898 const IceCandidateInterface* c1 = cc1->at(j);
899 const IceCandidateInterface* c2 = cc2->at(j);
900 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
901 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
902 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
903 }
904 }
905 return true;
906 }
907
908 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
909 // them with invalid keywords so that the parser will just ignore them.
910 bool RemoveCandidateUfragPwd(std::string* sdp) {
911 const char ice_ufrag[] = "a=ice-ufrag";
912 const char ice_ufragx[] = "a=xice-ufrag";
913 const char ice_pwd[] = "a=ice-pwd";
914 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000915 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 ice_pwdx, strlen(ice_pwdx), sdp);
919 return true;
920 }
921
922 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
923 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
924 const std::string& ufrag, const std::string& pwd) {
925 std::string content_name;
926 if (mline_index == 0) {
927 content_name = kAudioContentName;
928 } else if (mline_index == 1) {
929 content_name = kVideoContentName;
930 } else {
931 ASSERT(false);
932 }
933 TransportInfo transport_info(
934 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000935 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 SessionDescription* desc =
937 const_cast<SessionDescription*>(jdesc->description());
938 desc->RemoveTransportInfoByName(content_name);
939 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
940 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
941 const IceCandidateCollection* cc = jdesc_.candidates(i);
942 for (size_t j = 0; j < cc->count(); ++j) {
943 if (cc->at(j)->sdp_mline_index() == mline_index) {
944 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
945 ufrag);
946 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
947 pwd);
948 }
949 }
950 }
951 return true;
952 }
953
954 void AddIceOptions(const std::string& content_name,
955 const std::vector<std::string>& transport_options) {
956 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
957 cricket::TransportInfo transport_info =
958 *(desc_.GetTransportInfoByName(content_name));
959 desc_.RemoveTransportInfoByName(content_name);
960 transport_info.description.transport_options = transport_options;
961 desc_.AddTransportInfo(transport_info);
962 }
963
964 void AddFingerprint() {
965 desc_.RemoveTransportInfoByName(kAudioContentName);
966 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000967 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 kIdentityDigest,
969 sizeof(kIdentityDigest));
970 EXPECT_TRUE(desc_.AddTransportInfo(
971 TransportInfo(kAudioContentName,
972 TransportDescription(NS_JINGLE_ICE_UDP,
973 std::vector<std::string>(),
974 kCandidateUfragVoice,
975 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000976 cricket::ICEMODE_FULL,
977 cricket::CONNECTIONROLE_NONE,
978 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_TRUE(desc_.AddTransportInfo(
980 TransportInfo(kVideoContentName,
981 TransportDescription(NS_JINGLE_ICE_UDP,
982 std::vector<std::string>(),
983 kCandidateUfragVideo,
984 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000985 cricket::ICEMODE_FULL,
986 cricket::CONNECTIONROLE_NONE,
987 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989
990 void AddExtmap() {
991 audio_desc_ = static_cast<AudioContentDescription*>(
992 audio_desc_->Copy());
993 video_desc_ = static_cast<VideoContentDescription*>(
994 video_desc_->Copy());
995 audio_desc_->AddRtpHeaderExtension(
996 RtpHeaderExtension(kExtmapUri, kExtmapId));
997 video_desc_->AddRtpHeaderExtension(
998 RtpHeaderExtension(kExtmapUri, kExtmapId));
999 desc_.RemoveContentByName(kAudioContentName);
1000 desc_.RemoveContentByName(kVideoContentName);
1001 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1002 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1003 }
1004
1005 void RemoveCryptos() {
1006 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1007 video_desc_->set_cryptos(std::vector<CryptoParams>());
1008 }
1009
1010 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1011 audio_desc_->set_direction(direction);
1012 video_desc_->set_direction(direction);
1013 std::string new_sdp = kSdpFullString;
1014 ReplaceDirection(direction, &new_sdp);
1015
1016 if (!jdesc_.Initialize(desc_.Copy(),
1017 jdesc_.session_id(),
1018 jdesc_.session_version())) {
1019 return false;
1020 }
1021 std::string message = webrtc::SdpSerialize(jdesc_);
1022 EXPECT_EQ(new_sdp, message);
1023 return true;
1024 }
1025
1026 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1027 audio_desc_ = static_cast<AudioContentDescription*>(
1028 audio_desc_->Copy());
1029 video_desc_ = static_cast<VideoContentDescription*>(
1030 video_desc_->Copy());
1031 desc_.RemoveContentByName(kAudioContentName);
1032 desc_.RemoveContentByName(kVideoContentName);
1033 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1034 audio_desc_);
1035 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1036 video_desc_);
1037 std::string new_sdp = kSdpFullString;
1038 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1039
1040 if (!jdesc_.Initialize(desc_.Copy(),
1041 jdesc_.session_id(),
1042 jdesc_.session_version())) {
1043 return false;
1044 }
1045 std::string message = webrtc::SdpSerialize(jdesc_);
1046 EXPECT_EQ(new_sdp, message);
1047 return true;
1048 }
1049
1050 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 new DataContentDescription());
1053 data_desc_ = data.get();
1054 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001055 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1056 cricket::kGoogleSctpDataCodecName, 0);
1057 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1058 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1060 EXPECT_TRUE(desc_.AddTransportInfo(
1061 TransportInfo(kDataContentName,
1062 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001064 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 }
1066
1067 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001068 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 new DataContentDescription());
1070 data_desc_ = data.get();
1071
1072 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1073 StreamParams data_stream;
1074 data_stream.id = kDataChannelMsid;
1075 data_stream.cname = kDataChannelCname;
1076 data_stream.sync_label = kDataChannelLabel;
1077 data_stream.ssrcs.push_back(kDataChannelSsrc);
1078 data_desc_->AddStream(data_stream);
1079 data_desc_->AddCrypto(CryptoParams(
1080 1, "AES_CM_128_HMAC_SHA1_80",
1081 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1082 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1083 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1084 EXPECT_TRUE(desc_.AddTransportInfo(
1085 TransportInfo(kDataContentName,
1086 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001088 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 }
1090
1091 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1092 std::string new_sdp = kSdpFullString;
1093 ReplaceDirection(direction, &new_sdp);
1094 JsepSessionDescription new_jdesc(kDummyString);
1095
1096 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1097
1098 audio_desc_->set_direction(direction);
1099 video_desc_->set_direction(direction);
1100 if (!jdesc_.Initialize(desc_.Copy(),
1101 jdesc_.session_id(),
1102 jdesc_.session_version())) {
1103 return false;
1104 }
1105 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1106 return true;
1107 }
1108
1109 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1110 std::string new_sdp = kSdpFullString;
1111 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1112 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1113
1114 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1115 audio_desc_ = static_cast<AudioContentDescription*>(
1116 audio_desc_->Copy());
1117 video_desc_ = static_cast<VideoContentDescription*>(
1118 video_desc_->Copy());
1119 desc_.RemoveContentByName(kAudioContentName);
1120 desc_.RemoveContentByName(kVideoContentName);
1121 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1122 audio_desc_);
1123 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1124 video_desc_);
1125 if (!jdesc_.Initialize(desc_.Copy(),
1126 jdesc_.session_id(),
1127 jdesc_.session_version())) {
1128 return false;
1129 }
1130 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1131 return true;
1132 }
1133
1134 void TestDeserializeExtmap(bool session_level, bool media_level) {
1135 AddExtmap();
1136 JsepSessionDescription new_jdesc("dummy");
1137 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1138 jdesc_.session_id(),
1139 jdesc_.session_version()));
1140 JsepSessionDescription jdesc_with_extmap("dummy");
1141 std::string sdp_with_extmap = kSdpString;
1142 if (session_level) {
1143 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1144 &sdp_with_extmap);
1145 }
1146 if (media_level) {
1147 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1148 &sdp_with_extmap);
1149 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1150 &sdp_with_extmap);
1151 }
1152 // The extmap can't be present at the same time in both session level and
1153 // media level.
1154 if (session_level && media_level) {
1155 SdpParseError error;
1156 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1157 &jdesc_with_extmap, &error));
1158 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1159 } else {
1160 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1161 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1162 }
1163 }
1164
1165 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1166 const std::string& name, int expected_value) {
1167 cricket::CodecParameterMap::const_iterator found = params.find(name);
1168 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001169 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 }
1171
1172 void TestDeserializeCodecParams(const CodecParams& params,
1173 JsepSessionDescription* jdesc_output) {
1174 std::string sdp =
1175 "v=0\r\n"
1176 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1177 "s=-\r\n"
1178 "t=0 0\r\n"
1179 // Include semantics for WebRTC Media Streams since it is supported by
1180 // this parser, and will be added to the SDP when serializing a session
1181 // description.
1182 "a=msid-semantic: WMS\r\n"
1183 // Pl type 111 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001184 "m=audio 9 RTP/SAVPF 111 104 103 102\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185 // Pltype 111 listed before 103 and 104 in the map.
1186 "a=rtpmap:111 opus/48000/2\r\n"
1187 // Pltype 103 listed before 104.
1188 "a=rtpmap:103 ISAC/16000\r\n"
1189 "a=rtpmap:104 CELT/32000/2\r\n"
1190 "a=rtpmap:102 ISAC/32000/1\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001191 "a=fmtp:111 0-15,66,70\r\n"
1192 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001194 os << "minptime=" << params.min_ptime
1195 << "; stereo=" << params.stereo
1196 << "; sprop-stereo=" << params.sprop_stereo
1197 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001198 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 << "a=ptime:" << params.ptime << "\r\n"
1200 << "a=maxptime:" << params.max_ptime << "\r\n";
1201 sdp += os.str();
1202
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001203 os.clear();
1204 os.str("");
1205 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001206 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001207 << "a=rtpmap:99 VP8/90000\r\n"
1208 << "a=rtpmap:95 RTX/90000\r\n"
1209 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1210 sdp += os.str();
1211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 // Deserialize
1213 SdpParseError error;
1214 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1215
1216 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1217 ASSERT_TRUE(ac != NULL);
1218 const AudioContentDescription* acd =
1219 static_cast<const AudioContentDescription*>(ac->description);
1220 ASSERT_FALSE(acd->codecs().empty());
1221 cricket::AudioCodec opus = acd->codecs()[0];
1222 EXPECT_EQ("opus", opus.name);
1223 EXPECT_EQ(111, opus.id);
1224 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1225 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1226 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1227 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001228 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1229 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1231 cricket::AudioCodec codec = acd->codecs()[i];
1232 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1233 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1234 if (codec.name == "ISAC") {
1235 if (codec.clockrate == 16000) {
1236 EXPECT_EQ(32000, codec.bitrate);
1237 } else {
1238 EXPECT_EQ(56000, codec.bitrate);
1239 }
1240 }
1241 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001242
1243 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1244 ASSERT_TRUE(vc != NULL);
1245 const VideoContentDescription* vcd =
1246 static_cast<const VideoContentDescription*>(vc->description);
1247 ASSERT_FALSE(vcd->codecs().empty());
1248 cricket::VideoCodec vp8 = vcd->codecs()[0];
1249 EXPECT_EQ("VP8", vp8.name);
1250 EXPECT_EQ(99, vp8.id);
1251 cricket::VideoCodec rtx = vcd->codecs()[1];
1252 EXPECT_EQ("RTX", rtx.name);
1253 EXPECT_EQ(95, rtx.id);
1254 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 }
1256
1257 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1258 bool use_wildcard) {
1259 std::string sdp =
1260 "v=0\r\n"
1261 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1262 "s=-\r\n"
1263 "t=0 0\r\n"
1264 // Include semantics for WebRTC Media Streams since it is supported by
1265 // this parser, and will be added to the SDP when serializing a session
1266 // description.
1267 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001268 "m=audio 9 RTP/SAVPF 111\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 "a=rtpmap:111 opus/48000/2\r\n"
1270 "a=rtcp-fb:111 nack\r\n"
1271 "m=video 3457 RTP/SAVPF 101\r\n"
1272 "a=rtpmap:101 VP8/90000\r\n"
1273 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001274 "a=rtcp-fb:101 nack pli\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 "a=rtcp-fb:101 goog-remb\r\n"
1276 "a=rtcp-fb:101 ccm fir\r\n";
1277 std::ostringstream os;
1278 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1279 sdp += os.str();
1280 // Deserialize
1281 SdpParseError error;
1282 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1283 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1284 ASSERT_TRUE(ac != NULL);
1285 const AudioContentDescription* acd =
1286 static_cast<const AudioContentDescription*>(ac->description);
1287 ASSERT_FALSE(acd->codecs().empty());
1288 cricket::AudioCodec opus = acd->codecs()[0];
1289 EXPECT_EQ(111, opus.id);
1290 EXPECT_TRUE(opus.HasFeedbackParam(
1291 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1292 cricket::kParamValueEmpty)));
1293
1294 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1295 ASSERT_TRUE(vc != NULL);
1296 const VideoContentDescription* vcd =
1297 static_cast<const VideoContentDescription*>(vc->description);
1298 ASSERT_FALSE(vcd->codecs().empty());
1299 cricket::VideoCodec vp8 = vcd->codecs()[0];
1300 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1301 vp8.name.c_str());
1302 EXPECT_EQ(101, vp8.id);
1303 EXPECT_TRUE(vp8.HasFeedbackParam(
1304 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1305 cricket::kParamValueEmpty)));
1306 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001307 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1308 cricket::kRtcpFbNackParamPli)));
1309 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1311 cricket::kParamValueEmpty)));
1312 EXPECT_TRUE(vp8.HasFeedbackParam(
1313 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1314 cricket::kRtcpFbCcmParamFir)));
1315 }
1316
1317 // Two SDP messages can mean the same thing but be different strings, e.g.
1318 // some of the lines can be serialized in different order.
1319 // However, a deserialized description can be compared field by field and has
1320 // no order. If deserializer has already been tested, serializing then
1321 // deserializing and comparing JsepSessionDescription will test
1322 // the serializer sufficiently.
1323 void TestSerialize(const JsepSessionDescription& jdesc) {
1324 std::string message = webrtc::SdpSerialize(jdesc);
1325 JsepSessionDescription jdesc_output_des(kDummyString);
1326 SdpParseError error;
1327 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1328 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1329 }
1330
1331 protected:
1332 SessionDescription desc_;
1333 AudioContentDescription* audio_desc_;
1334 VideoContentDescription* video_desc_;
1335 DataContentDescription* data_desc_;
1336 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001337 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 JsepSessionDescription jdesc_;
1339};
1340
1341void TestMismatch(const std::string& string1, const std::string& string2) {
1342 int position = 0;
1343 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1344 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001345 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 break;
1347 }
1348 }
1349 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1350 << " character\n"
1351 << " 1: " << string1.substr(position, 20) << "\n"
1352 << " 2: " << string2.substr(position, 20) << "\n";
1353}
1354
1355std::string GetLine(const std::string& message,
1356 const std::string& session_description_name) {
1357 size_t start = message.find(session_description_name);
1358 if (std::string::npos == start) {
1359 return "";
1360 }
1361 size_t stop = message.find("\r\n", start);
1362 if (std::string::npos == stop) {
1363 return "";
1364 }
1365 if (stop <= start) {
1366 return "";
1367 }
1368 return message.substr(start, stop - start);
1369}
1370
1371TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1372 // SessionDescription with desc and candidates.
1373 std::string message = webrtc::SdpSerialize(jdesc_);
1374 TestMismatch(std::string(kSdpFullString), message);
1375}
1376
1377TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1378 JsepSessionDescription jdesc_empty(kDummyString);
1379 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1380}
1381
1382// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1383// the case in a DTLS offer.
1384TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1385 AddFingerprint();
1386 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1387 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1388 kSessionId, kSessionVersion));
1389 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1390
1391 std::string sdp_with_fingerprint = kSdpString;
1392 InjectAfter(kAttributeIcePwdVoice,
1393 kFingerprint, &sdp_with_fingerprint);
1394 InjectAfter(kAttributeIcePwdVideo,
1395 kFingerprint, &sdp_with_fingerprint);
1396
1397 EXPECT_EQ(sdp_with_fingerprint, message);
1398}
1399
1400// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1401// be the case in a DTLS answer.
1402TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1403 AddFingerprint();
1404 RemoveCryptos();
1405 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1406 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1407 kSessionId, kSessionVersion));
1408 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1409
1410 std::string sdp_with_fingerprint = kSdpString;
1411 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1412 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1413 InjectAfter(kAttributeIcePwdVoice,
1414 kFingerprint, &sdp_with_fingerprint);
1415 InjectAfter(kAttributeIcePwdVideo,
1416 kFingerprint, &sdp_with_fingerprint);
1417
1418 EXPECT_EQ(sdp_with_fingerprint, message);
1419}
1420
1421TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1422 // JsepSessionDescription with desc but without candidates.
1423 JsepSessionDescription jdesc_no_candidates(kDummyString);
1424 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1425 kSessionId, kSessionVersion));
1426 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1427 EXPECT_EQ(std::string(kSdpString), message);
1428}
1429
1430TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1431 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1432 group.AddContentName(kAudioContentName);
1433 group.AddContentName(kVideoContentName);
1434 desc_.AddGroup(group);
1435 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1436 jdesc_.session_id(),
1437 jdesc_.session_version()));
1438 std::string message = webrtc::SdpSerialize(jdesc_);
1439 std::string sdp_with_bundle = kSdpFullString;
1440 InjectAfter(kSessionTime,
1441 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1442 &sdp_with_bundle);
1443 EXPECT_EQ(sdp_with_bundle, message);
1444}
1445
1446TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1447 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1448 GetFirstVideoContent(&desc_)->description);
1449 vcd->set_bandwidth(100 * 1000);
1450 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1451 GetFirstAudioContent(&desc_)->description);
1452 acd->set_bandwidth(50 * 1000);
1453 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1454 jdesc_.session_id(),
1455 jdesc_.session_version()));
1456 std::string message = webrtc::SdpSerialize(jdesc_);
1457 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001458 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 "b=AS:100\r\n",
1460 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001461 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 "b=AS:50\r\n",
1463 &sdp_with_bandwidth);
1464 EXPECT_EQ(sdp_with_bandwidth, message);
1465}
1466
1467TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1468 std::vector<std::string> transport_options;
1469 transport_options.push_back(kIceOption1);
1470 transport_options.push_back(kIceOption3);
1471 AddIceOptions(kAudioContentName, transport_options);
1472 transport_options.clear();
1473 transport_options.push_back(kIceOption2);
1474 transport_options.push_back(kIceOption3);
1475 AddIceOptions(kVideoContentName, transport_options);
1476 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1477 jdesc_.session_id(),
1478 jdesc_.session_version()));
1479 std::string message = webrtc::SdpSerialize(jdesc_);
1480 std::string sdp_with_ice_options = kSdpFullString;
1481 InjectAfter(kAttributeIcePwdVoice,
1482 "a=ice-options:iceoption1 iceoption3\r\n",
1483 &sdp_with_ice_options);
1484 InjectAfter(kAttributeIcePwdVideo,
1485 "a=ice-options:iceoption2 iceoption3\r\n",
1486 &sdp_with_ice_options);
1487 EXPECT_EQ(sdp_with_ice_options, message);
1488}
1489
1490TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1491 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1492}
1493
1494TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1495 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1496}
1497
1498TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1499 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1500}
1501
1502TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1503 EXPECT_TRUE(TestSerializeRejected(true, false));
1504}
1505
1506TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1507 EXPECT_TRUE(TestSerializeRejected(false, true));
1508}
1509
1510TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1511 EXPECT_TRUE(TestSerializeRejected(true, true));
1512}
1513
1514TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1515 AddRtpDataChannel();
1516 JsepSessionDescription jsep_desc(kDummyString);
1517
1518 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1519 std::string message = webrtc::SdpSerialize(jsep_desc);
1520
1521 std::string expected_sdp = kSdpString;
1522 expected_sdp.append(kSdpRtpDataChannelString);
1523 EXPECT_EQ(expected_sdp, message);
1524}
1525
1526TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1527 AddSctpDataChannel();
1528 JsepSessionDescription jsep_desc(kDummyString);
1529
1530 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1531 std::string message = webrtc::SdpSerialize(jsep_desc);
1532
1533 std::string expected_sdp = kSdpString;
1534 expected_sdp.append(kSdpSctpDataChannelString);
1535 EXPECT_EQ(message, expected_sdp);
1536}
1537
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001538TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1539 AddSctpDataChannel();
1540 JsepSessionDescription jsep_desc(kDummyString);
1541
1542 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1543 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1544 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1545
1546 const int kNewPort = 1234;
1547 cricket::DataCodec codec(
1548 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1549 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1550 dcdesc->AddOrReplaceCodec(codec);
1551
1552 std::string message = webrtc::SdpSerialize(jsep_desc);
1553
1554 std::string expected_sdp = kSdpString;
1555 expected_sdp.append(kSdpSctpDataChannelString);
1556
1557 char default_portstr[16];
1558 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001559 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001560 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001561 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1562 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001563 new_portstr, strlen(new_portstr),
1564 &expected_sdp);
1565
1566 EXPECT_EQ(expected_sdp, message);
1567}
1568
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001569TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1570 AddRtpDataChannel();
1571 data_desc_->set_bandwidth(100*1000);
1572 JsepSessionDescription jsep_desc(kDummyString);
1573
1574 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1575 std::string message = webrtc::SdpSerialize(jsep_desc);
1576
1577 std::string expected_sdp = kSdpString;
1578 expected_sdp.append(kSdpRtpDataChannelString);
1579 // We want to test that serializing data content ignores bandwidth
1580 // settings (it should always be the default). Thus, we don't do
1581 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001582 // TODO(pthatcher): We need to temporarily allow the SDP to control
1583 // this for backwards-compatibility. Once we don't need that any
1584 // more, remove this.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001585 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 +00001586 "b=AS:100\r\n",
1587 &expected_sdp);
1588 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001589}
1590
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1592 AddExtmap();
1593 JsepSessionDescription desc_with_extmap("dummy");
1594 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1595 kSessionId, kSessionVersion));
1596 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1597
1598 std::string sdp_with_extmap = kSdpString;
1599 InjectAfter("a=mid:audio_content_name\r\n",
1600 kExtmap, &sdp_with_extmap);
1601 InjectAfter("a=mid:video_content_name\r\n",
1602 kExtmap, &sdp_with_extmap);
1603
1604 EXPECT_EQ(sdp_with_extmap, message);
1605}
1606
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001607TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1608 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1609 GetFirstVideoContent(&desc_)->description);
1610 vcd->set_buffered_mode_latency(128);
1611
1612 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1613 jdesc_.session_id(),
1614 jdesc_.session_version()));
1615 std::string message = webrtc::SdpSerialize(jdesc_);
1616 std::string sdp_with_buffer_latency = kSdpFullString;
1617 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1618 "a=x-google-buffer-latency:128\r\n",
1619 &sdp_with_buffer_latency);
1620 EXPECT_EQ(sdp_with_buffer_latency, message);
1621}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622
1623TEST_F(WebRtcSdpTest, SerializeCandidates) {
1624 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001625 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626}
1627
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001628// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1629// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001630TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001631 Candidate candidate("", ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1632 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1633 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1634 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001635 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1636 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1637 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1638
1639 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1640 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1641}
1642
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1644 JsepSessionDescription jdesc(kDummyString);
1645 // Deserialize
1646 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1647 // Verify
1648 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1649}
1650
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001651TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1652 JsepSessionDescription jdesc(kDummyString);
1653 const char kSdpWithoutMline[] =
1654 "v=0\r\n"
1655 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1656 "s=-\r\n"
1657 "t=0 0\r\n"
1658 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1659 // Deserialize
1660 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1661 EXPECT_EQ(0u, jdesc.description()->contents().size());
1662}
1663
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1665 JsepSessionDescription jdesc(kDummyString);
1666 std::string sdp_without_carriage_return = kSdpFullString;
1667 Replace("\r\n", "\n", &sdp_without_carriage_return);
1668 // Deserialize
1669 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1670 // Verify
1671 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1672}
1673
1674TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1675 // SessionDescription with desc but without candidates.
1676 JsepSessionDescription jdesc_no_candidates(kDummyString);
1677 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1678 kSessionId, kSessionVersion));
1679 JsepSessionDescription new_jdesc(kDummyString);
1680 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1681 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1682}
1683
1684TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1685 static const char kSdpNoRtpmapString[] =
1686 "v=0\r\n"
1687 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1688 "s=-\r\n"
1689 "t=0 0\r\n"
1690 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1691 // Codec that doesn't appear in the m= line will be ignored.
1692 "a=rtpmap:104 CELT/32000/2\r\n"
1693 // The rtpmap line for static payload codec is optional.
1694 "a=rtpmap:18 G729/16000\r\n"
1695 "a=rtpmap:103 ISAC/16000\r\n";
1696
1697 JsepSessionDescription jdesc(kDummyString);
1698 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1699 cricket::AudioContentDescription* audio =
1700 static_cast<AudioContentDescription*>(
1701 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1702 AudioCodecs ref_codecs;
1703 // The codecs in the AudioContentDescription will be sorted by preference.
1704 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1705 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1706 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1707 EXPECT_EQ(ref_codecs, audio->codecs());
1708}
1709
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001710TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1711 static const char kSdpNoRtpmapString[] =
1712 "v=0\r\n"
1713 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1714 "s=-\r\n"
1715 "t=0 0\r\n"
1716 "m=audio 49232 RTP/AVP 18 103\r\n"
1717 "a=fmtp:18 annexb=yes\r\n"
1718 "a=rtpmap:103 ISAC/16000\r\n";
1719
1720 JsepSessionDescription jdesc(kDummyString);
1721 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1722 cricket::AudioContentDescription* audio =
1723 static_cast<AudioContentDescription*>(
1724 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1725
1726 cricket::AudioCodec g729 = audio->codecs()[0];
1727 EXPECT_EQ("G729", g729.name);
1728 EXPECT_EQ(8000, g729.clockrate);
1729 EXPECT_EQ(18, g729.id);
1730 cricket::CodecParameterMap::iterator found =
1731 g729.params.find("annexb");
1732 ASSERT_TRUE(found != g729.params.end());
1733 EXPECT_EQ(found->second, "yes");
1734
1735 cricket::AudioCodec isac = audio->codecs()[1];
1736 EXPECT_EQ("ISAC", isac.name);
1737 EXPECT_EQ(103, isac.id);
1738 EXPECT_EQ(16000, isac.clockrate);
1739}
1740
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741// Ensure that we can deserialize SDP with a=fingerprint properly.
1742TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1743 // Add a DTLS a=fingerprint attribute to our session description.
1744 AddFingerprint();
1745 JsepSessionDescription new_jdesc(kDummyString);
1746 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1747 jdesc_.session_id(),
1748 jdesc_.session_version()));
1749
1750 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1751 std::string sdp_with_fingerprint = kSdpString;
1752 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1753 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1754 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1755 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1756}
1757
1758TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1759 JsepSessionDescription jdesc_with_bundle(kDummyString);
1760 std::string sdp_with_bundle = kSdpFullString;
1761 InjectAfter(kSessionTime,
1762 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1763 &sdp_with_bundle);
1764 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1765 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1766 group.AddContentName(kAudioContentName);
1767 group.AddContentName(kVideoContentName);
1768 desc_.AddGroup(group);
1769 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1770 jdesc_.session_id(),
1771 jdesc_.session_version()));
1772 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1773}
1774
1775TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1776 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1777 std::string sdp_with_bandwidth = kSdpFullString;
1778 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1779 "b=AS:100\r\n",
1780 &sdp_with_bandwidth);
1781 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1782 "b=AS:50\r\n",
1783 &sdp_with_bandwidth);
1784 EXPECT_TRUE(
1785 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1786 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1787 GetFirstVideoContent(&desc_)->description);
1788 vcd->set_bandwidth(100 * 1000);
1789 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1790 GetFirstAudioContent(&desc_)->description);
1791 acd->set_bandwidth(50 * 1000);
1792 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1793 jdesc_.session_id(),
1794 jdesc_.session_version()));
1795 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1796}
1797
1798TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1799 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1800 std::string sdp_with_ice_options = kSdpFullString;
1801 InjectAfter(kSessionTime,
1802 "a=ice-options:iceoption3\r\n",
1803 &sdp_with_ice_options);
1804 InjectAfter(kAttributeIcePwdVoice,
1805 "a=ice-options:iceoption1\r\n",
1806 &sdp_with_ice_options);
1807 InjectAfter(kAttributeIcePwdVideo,
1808 "a=ice-options:iceoption2\r\n",
1809 &sdp_with_ice_options);
1810 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1811 std::vector<std::string> transport_options;
1812 transport_options.push_back(kIceOption3);
1813 transport_options.push_back(kIceOption1);
1814 AddIceOptions(kAudioContentName, transport_options);
1815 transport_options.clear();
1816 transport_options.push_back(kIceOption3);
1817 transport_options.push_back(kIceOption2);
1818 AddIceOptions(kVideoContentName, transport_options);
1819 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1820 jdesc_.session_id(),
1821 jdesc_.session_version()));
1822 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1823}
1824
1825TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1826 // Remove the original ice-ufrag and ice-pwd
1827 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1828 std::string sdp_with_ufrag_pwd = kSdpFullString;
1829 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1830 // Add session level ufrag and pwd
1831 InjectAfter(kSessionTime,
1832 "a=ice-pwd:session+level+icepwd\r\n"
1833 "a=ice-ufrag:session+level+iceufrag\r\n",
1834 &sdp_with_ufrag_pwd);
1835 // Add media level ufrag and pwd for audio
1836 InjectAfter("a=mid:audio_content_name\r\n",
1837 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1838 &sdp_with_ufrag_pwd);
1839 // Update the candidate ufrag and pwd to the expected ones.
1840 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1841 "media+level+iceufrag", "media+level+icepwd"));
1842 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1843 "session+level+iceufrag", "session+level+icepwd"));
1844 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1845 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1846}
1847
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001848TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1849 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1850 std::string sdp_with_buffer_latency = kSdpFullString;
1851 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1852 "a=x-google-buffer-latency:128\r\n",
1853 &sdp_with_buffer_latency);
1854
1855 EXPECT_TRUE(
1856 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1857 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1858 GetFirstVideoContent(&desc_)->description);
1859 vcd->set_buffered_mode_latency(128);
1860 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1861 jdesc_.session_id(),
1862 jdesc_.session_version()));
1863 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1864}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865
1866TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1867 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1868}
1869
1870TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1871 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1872}
1873
1874TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1875 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1876}
1877
1878TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1879 EXPECT_TRUE(TestDeserializeRejected(true, false));
1880}
1881
1882TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1883 EXPECT_TRUE(TestDeserializeRejected(false, true));
1884}
1885
1886TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1887 EXPECT_TRUE(TestDeserializeRejected(true, true));
1888}
1889
1890// Tests that we can still handle the sdp uses mslabel and label instead of
1891// msid for backward compatibility.
1892TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1893 JsepSessionDescription jdesc(kDummyString);
1894 std::string sdp_without_msid = kSdpFullString;
1895 Replace("msid", "xmsid", &sdp_without_msid);
1896 // Deserialize
1897 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1898 // Verify
1899 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1900}
1901
1902TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1903 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1904
1905 std::string sdp = kSdpOneCandidate;
1906 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1907 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1908 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1909 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1910
1911 // Candidate line without generation extension.
1912 sdp = kSdpOneCandidate;
1913 Replace(" generation 2", "", &sdp);
1914 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1915 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1916 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1917 Candidate expected = jcandidate_->candidate();
1918 expected.set_generation(0);
1919 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1920
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001921 sdp = kSdpTcpActiveCandidate;
1922 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1923 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001924 Candidate candidate("", ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1925 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1926 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1927 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001928 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
1929 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1930 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
1931 jcandidate_template->candidate()));
1932 sdp = kSdpTcpPassiveCandidate;
1933 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1934 sdp = kSdpTcpSOCandidate;
1935 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936}
1937
1938// This test verifies the deserialization of candidate-attribute
1939// as per RFC 5245. Candiate-attribute will be of the format
1940// candidate:<blah>. This format will be used when candidates
1941// are trickled.
1942TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
1943 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1944
1945 std::string candidate_attribute = kRawCandidate;
1946 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1947 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1948 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1949 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1950 EXPECT_EQ(2u, jcandidate.candidate().generation());
1951
1952 // Candidate line without generation extension.
1953 candidate_attribute = kRawCandidate;
1954 Replace(" generation 2", "", &candidate_attribute);
1955 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1956 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1957 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1958 Candidate expected = jcandidate_->candidate();
1959 expected.set_generation(0);
1960 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1961
1962 // Candidate line without candidate:
1963 candidate_attribute = kRawCandidate;
1964 Replace("candidate:", "", &candidate_attribute);
1965 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1966
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001967 // Candidate line with IPV6 address.
1968 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
1969}
1970
1971// This test verifies that the deserialization of an invalid candidate string
1972// fails.
1973TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
1974 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1975
1976 std::string candidate_attribute = kRawCandidate;
1977 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001979
1980 candidate_attribute = kSdpOneCandidate;
1981 candidate_attribute.replace(0, 1, "x");
1982 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1983
1984 candidate_attribute = kRawCandidate;
1985 candidate_attribute.append("\r\n");
1986 candidate_attribute.append(kRawCandidate);
1987 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1988
1989 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990}
1991
1992TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
1993 AddRtpDataChannel();
1994 JsepSessionDescription jdesc(kDummyString);
1995 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1996
1997 std::string sdp_with_data = kSdpString;
1998 sdp_with_data.append(kSdpRtpDataChannelString);
1999 JsepSessionDescription jdesc_output(kDummyString);
2000
2001 // Deserialize
2002 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2003 // Verify
2004 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2005}
2006
2007TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2008 AddSctpDataChannel();
2009 JsepSessionDescription jdesc(kDummyString);
2010 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2011
2012 std::string sdp_with_data = kSdpString;
2013 sdp_with_data.append(kSdpSctpDataChannelString);
2014 JsepSessionDescription jdesc_output(kDummyString);
2015
2016 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2017 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2018}
2019
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002020TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2021 AddSctpDataChannel();
2022 JsepSessionDescription jdesc(kDummyString);
2023 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2024
2025 std::string sdp_with_data = kSdpString;
2026 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2027 JsepSessionDescription jdesc_output(kDummyString);
2028
2029 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2030 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2031}
2032
2033// Test to check the behaviour if sctp-port is specified
2034// on the m= line and in a=sctp-port.
2035TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2036 AddSctpDataChannel();
2037 JsepSessionDescription jdesc(kDummyString);
2038 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2039
2040 std::string sdp_with_data = kSdpString;
2041 // Append m= attributes
2042 sdp_with_data.append(kSdpSctpDataChannelString);
2043 // Append a=sctp-port attribute
2044 sdp_with_data.append("a=sctp-port 5000\r\n");
2045 JsepSessionDescription jdesc_output(kDummyString);
2046
2047 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2048}
2049
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002050// For crbug/344475.
2051TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2052 std::string sdp_with_data = kSdpString;
2053 sdp_with_data.append(kSdpSctpDataChannelString);
2054 // Remove the "\n" at the end.
2055 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2056 JsepSessionDescription jdesc_output(kDummyString);
2057
2058 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2059 // No crash is a pass.
2060}
2061
wu@webrtc.org78187522013-10-07 23:32:02 +00002062TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2063 AddSctpDataChannel();
2064 const uint16 kUnusualSctpPort = 9556;
2065 char default_portstr[16];
2066 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002067 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002068 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002069 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002070 kUnusualSctpPort);
2071
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002072 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002073 JsepSessionDescription jdesc(kDummyString);
2074 // take our pre-built session description and change the SCTP port.
2075 cricket::SessionDescription* mutant = desc_.Copy();
2076 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2077 mutant->GetContentDescriptionByName(kDataContentName));
2078 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2079 EXPECT_EQ(codecs.size(), 1UL);
2080 EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId);
2081 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002082 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002083
2084 // note: mutant's owned by jdesc now.
2085 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2086 mutant = NULL;
2087
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002088 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002089 std::string sdp_with_data = kSdpString;
2090 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002091 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002092 unusual_portstr, strlen(unusual_portstr),
2093 &sdp_with_data);
2094 JsepSessionDescription jdesc_output(kDummyString);
2095
2096 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2097 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002098
2099 // We need to test the deserialized JsepSessionDescription from
2100 // kSdpSctpDataChannelStringWithSctpPort for
2101 // draft-ietf-mmusic-sctp-sdp-07
2102 // a=sctp-port
2103 sdp_with_data = kSdpString;
2104 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2105 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2106 unusual_portstr, strlen(unusual_portstr),
2107 &sdp_with_data);
2108
2109 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2110 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002111}
2112
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002113TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2114 AddRtpDataChannel();
2115 JsepSessionDescription jdesc(kDummyString);
2116 // We want to test that deserializing data content ignores bandwidth
2117 // settings (it should always be the default). Thus, we don't do
2118 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002119 // TODO(pthatcher): We need to temporarily allow the SDP to control
2120 // this for backwards-compatibility. Once we don't need that any
2121 // more, remove this.
2122 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2123 GetFirstDataContent(&desc_)->description);
2124 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002125 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2126
2127 std::string sdp_with_bandwidth = kSdpString;
2128 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2129 InjectAfter("a=mid:data_content_name\r\n",
2130 "b=AS:100\r\n",
2131 &sdp_with_bandwidth);
2132 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2133
2134 EXPECT_TRUE(
2135 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2136 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2137}
2138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2140 TestDeserializeExtmap(true, false);
2141}
2142
2143TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2144 TestDeserializeExtmap(false, true);
2145}
2146
2147TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2148 TestDeserializeExtmap(true, true);
2149}
2150
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002151TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2152 JsepSessionDescription jdesc(kDummyString);
2153 std::string sdp = kSdpFullString;
2154 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2155 // Deserialize
2156 SdpParseError error;
2157 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2158 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2159 EXPECT_EQ(lastline, error.line);
2160 EXPECT_EQ("Invalid SDP line.", error.description);
2161}
2162
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2164 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2165 std::string new_sdp = kSdpOneCandidate;
2166 Replace("udp", "unsupported_transport", &new_sdp);
2167 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2168 new_sdp = kSdpOneCandidate;
2169 Replace("udp", "uDP", &new_sdp);
2170 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2171 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2172 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2173 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2174}
2175
2176TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2177 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2178 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2179 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2180 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2181 Candidate ref_candidate = jcandidate_->candidate();
2182 ref_candidate.set_username("user_rtp");
2183 ref_candidate.set_password("password_rtp");
2184 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2185}
2186
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002187TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2188 JsepSessionDescription jdesc(kDummyString);
2189
2190 // Deserialize
2191 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2192
2193 // Verify
2194 cricket::AudioContentDescription* audio =
2195 static_cast<AudioContentDescription*>(
2196 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2197 EXPECT_TRUE(audio->conference_mode());
2198
2199 cricket::VideoContentDescription* video =
2200 static_cast<VideoContentDescription*>(
2201 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2202 EXPECT_TRUE(video->conference_mode());
2203}
2204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2206 const char kSdpDestroyer[] = "!@#$%^&";
2207 const char kSdpInvalidLine1[] = " =candidate";
2208 const char kSdpInvalidLine2[] = "a+candidate";
2209 const char kSdpInvalidLine3[] = "a= candidate";
2210 // Broken fingerprint.
2211 const char kSdpInvalidLine4[] = "a=fingerprint:sha-1 "
2212 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
2213 // Extra field.
2214 const char kSdpInvalidLine5[] = "a=fingerprint:sha-1 "
2215 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
2216 // Missing space.
2217 const char kSdpInvalidLine6[] = "a=fingerprint:sha-1"
2218 "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 +00002219 // MD5 is not allowed in fingerprints.
2220 const char kSdpInvalidLine7[] = "a=fingerprint:md5 "
2221 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222
2223 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002224 ExpectParseFailure("v=", kSdpDestroyer);
2225 ExpectParseFailure("o=", kSdpDestroyer);
2226 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002228 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229
2230 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002231 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2232 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 // Invalid lines
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002235 ExpectParseFailure("a=candidate", kSdpInvalidLine1);
2236 ExpectParseFailure("a=candidate", kSdpInvalidLine2);
2237 ExpectParseFailure("a=candidate", kSdpInvalidLine3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238
2239 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2240 // because it's orthogonal to what we are replacing and hence
2241 // safe.
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002242 ExpectParseFailure("a=sendrecv", kSdpInvalidLine4);
2243 ExpectParseFailure("a=sendrecv", kSdpInvalidLine5);
2244 ExpectParseFailure("a=sendrecv", kSdpInvalidLine6);
2245 ExpectParseFailure("a=sendrecv", kSdpInvalidLine7);
2246}
2247
2248TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2249 // ssrc
2250 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2251 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2252 // crypto
2253 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2254 // rtpmap
2255 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2256 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2257 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2258 // candidate
2259 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2260 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2261 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2262 ExpectParseFailure("rport 2346", "rport badvalue");
2263 ExpectParseFailure("rport 2346 generation 2",
2264 "rport 2346 generation badvalue");
2265 // m line
2266 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2267 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2268
2269 // bandwidth
2270 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2271 "b=AS:badvalue\r\n",
2272 "b=AS:badvalue");
2273 // rtcp-fb
2274 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2275 "a=rtcp-fb:badvalue nack\r\n",
2276 "a=rtcp-fb:badvalue nack");
2277 // extmap
2278 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2279 "a=extmap:badvalue http://example.com\r\n",
2280 "a=extmap:badvalue http://example.com");
2281 // x-google-buffer-latency
2282 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2283 "a=x-google-buffer-latency:badvalue\r\n",
2284 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285}
2286
2287TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2288 JsepSessionDescription jdesc_output(kDummyString);
2289
2290 const char kSdpWithReorderedPlTypesString[] =
2291 "v=0\r\n"
2292 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2293 "s=-\r\n"
2294 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002295 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2297 // in the map.
2298 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
2299 "a=rtpmap:104 CELT/32000/2\r\n";
2300
2301 // Deserialize
2302 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2303
2304 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2305 ASSERT_TRUE(ac != NULL);
2306 const AudioContentDescription* acd =
2307 static_cast<const AudioContentDescription*>(ac->description);
2308 ASSERT_FALSE(acd->codecs().empty());
2309 EXPECT_EQ("CELT", acd->codecs()[0].name);
2310 EXPECT_EQ(104, acd->codecs()[0].id);
2311}
2312
2313TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2314 JsepSessionDescription jdesc_output(kDummyString);
2315 CodecParams params;
2316 params.max_ptime = 40;
2317 params.ptime = 30;
2318 params.min_ptime = 10;
2319 params.sprop_stereo = 1;
2320 params.stereo = 1;
2321 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002322 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 TestDeserializeCodecParams(params, &jdesc_output);
2324 TestSerialize(jdesc_output);
2325}
2326
2327TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2328 const bool kUseWildcard = false;
2329 JsepSessionDescription jdesc_output(kDummyString);
2330 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2331 TestSerialize(jdesc_output);
2332}
2333
2334TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2335 const bool kUseWildcard = true;
2336 JsepSessionDescription jdesc_output(kDummyString);
2337 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2338 TestSerialize(jdesc_output);
2339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2342 JsepSessionDescription jdesc_output(kDummyString);
2343
2344 const char kSdpWithFmtpString[] =
2345 "v=0\r\n"
2346 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2347 "s=-\r\n"
2348 "t=0 0\r\n"
2349 "m=video 3457 RTP/SAVPF 120\r\n"
2350 "a=rtpmap:120 VP8/90000\r\n"
2351 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2352
2353 // Deserialize
2354 SdpParseError error;
2355 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2356 &error));
2357
2358 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2359 ASSERT_TRUE(vc != NULL);
2360 const VideoContentDescription* vcd =
2361 static_cast<const VideoContentDescription*>(vc->description);
2362 ASSERT_FALSE(vcd->codecs().empty());
2363 cricket::VideoCodec vp8 = vcd->codecs()[0];
2364 EXPECT_EQ("VP8", vp8.name);
2365 EXPECT_EQ(120, vp8.id);
2366 cricket::CodecParameterMap::iterator found =
2367 vp8.params.find("x-google-min-bitrate");
2368 ASSERT_TRUE(found != vp8.params.end());
2369 EXPECT_EQ(found->second, "10");
2370 found = vp8.params.find("x-google-max-quantization");
2371 ASSERT_TRUE(found != vp8.params.end());
2372 EXPECT_EQ(found->second, "40");
2373}
2374
2375TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2376 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2377 GetFirstVideoContent(&desc_)->description);
2378
2379 cricket::VideoCodecs codecs = vcd->codecs();
2380 codecs[0].params["x-google-min-bitrate"] = "10";
2381 vcd->set_codecs(codecs);
2382
2383 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2384 jdesc_.session_id(),
2385 jdesc_.session_version()));
2386 std::string message = webrtc::SdpSerialize(jdesc_);
2387 std::string sdp_with_fmtp = kSdpFullString;
2388 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2389 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2390 &sdp_with_fmtp);
2391 EXPECT_EQ(sdp_with_fmtp, message);
2392}
2393
2394TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2395 JsepSessionDescription jdesc_with_icelite(kDummyString);
2396 std::string sdp_with_icelite = kSdpFullString;
2397 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2398 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2399 const cricket::TransportInfo* tinfo1 =
2400 desc->GetTransportInfoByName("audio_content_name");
2401 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2402 const cricket::TransportInfo* tinfo2 =
2403 desc->GetTransportInfoByName("video_content_name");
2404 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2405 InjectAfter(kSessionTime,
2406 "a=ice-lite\r\n",
2407 &sdp_with_icelite);
2408 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2409 desc = jdesc_with_icelite.description();
2410 const cricket::TransportInfo* atinfo =
2411 desc->GetTransportInfoByName("audio_content_name");
2412 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2413 const cricket::TransportInfo* vtinfo =
2414 desc->GetTransportInfoByName("video_content_name");
2415 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2416}
2417
2418// Verifies that the candidates in the input SDP are parsed and serialized
2419// correctly in the output SDP.
2420TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2421 std::string sdp_with_data = kSdpString;
2422 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2423 JsepSessionDescription jdesc_output(kDummyString);
2424
2425 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2426 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2427}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002428
2429TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2430 AddFingerprint();
2431 TransportInfo audio_transport_info =
2432 *(desc_.GetTransportInfoByName(kAudioContentName));
2433 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2434 audio_transport_info.description.connection_role);
2435 audio_transport_info.description.connection_role =
2436 cricket::CONNECTIONROLE_ACTIVE;
2437
2438 TransportInfo video_transport_info =
2439 *(desc_.GetTransportInfoByName(kVideoContentName));
2440 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2441 video_transport_info.description.connection_role);
2442 video_transport_info.description.connection_role =
2443 cricket::CONNECTIONROLE_ACTIVE;
2444
2445 desc_.RemoveTransportInfoByName(kAudioContentName);
2446 desc_.RemoveTransportInfoByName(kVideoContentName);
2447
2448 desc_.AddTransportInfo(audio_transport_info);
2449 desc_.AddTransportInfo(video_transport_info);
2450
2451 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2452 jdesc_.session_id(),
2453 jdesc_.session_version()));
2454 std::string message = webrtc::SdpSerialize(jdesc_);
2455 std::string sdp_with_dtlssetup = kSdpFullString;
2456
2457 // Fingerprint attribute is necessary to add DTLS setup attribute.
2458 InjectAfter(kAttributeIcePwdVoice,
2459 kFingerprint, &sdp_with_dtlssetup);
2460 InjectAfter(kAttributeIcePwdVideo,
2461 kFingerprint, &sdp_with_dtlssetup);
2462 // Now adding |setup| attribute.
2463 InjectAfter(kFingerprint,
2464 "a=setup:active\r\n", &sdp_with_dtlssetup);
2465 EXPECT_EQ(sdp_with_dtlssetup, message);
2466}
2467
2468TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2469 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2470 std::string sdp_with_dtlssetup = kSdpFullString;
2471 InjectAfter(kSessionTime,
2472 "a=setup:actpass\r\n",
2473 &sdp_with_dtlssetup);
2474 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2475 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2476 const cricket::TransportInfo* atinfo =
2477 desc->GetTransportInfoByName("audio_content_name");
2478 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2479 atinfo->description.connection_role);
2480 const cricket::TransportInfo* vtinfo =
2481 desc->GetTransportInfoByName("video_content_name");
2482 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2483 vtinfo->description.connection_role);
2484}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002485
2486// Verifies that the order of the serialized m-lines follows the order of the
2487// ContentInfo in SessionDescription, and vise versa for deserialization.
2488TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2489 JsepSessionDescription jdesc(kDummyString);
2490 const std::string media_content_sdps[3] = {
2491 kSdpAudioString,
2492 kSdpVideoString,
2493 kSdpSctpDataChannelString
2494 };
2495 const cricket::MediaType media_types[3] = {
2496 cricket::MEDIA_TYPE_AUDIO,
2497 cricket::MEDIA_TYPE_VIDEO,
2498 cricket::MEDIA_TYPE_DATA
2499 };
2500
2501 // Verifies all 6 permutations.
2502 for (size_t i = 0; i < 6; ++i) {
2503 size_t media_content_in_sdp[3];
2504 // The index of the first media content.
2505 media_content_in_sdp[0] = i / 2;
2506 // The index of the second media content.
2507 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2508 // The index of the third media content.
2509 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2510
2511 std::string sdp_string = kSdpSessionString;
2512 for (size_t i = 0; i < 3; ++i)
2513 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2514
2515 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2516 cricket::SessionDescription* desc = jdesc.description();
2517 EXPECT_EQ(3u, desc->contents().size());
2518
2519 for (size_t i = 0; i < 3; ++i) {
2520 const cricket::MediaContentDescription* mdesc =
2521 static_cast<const cricket::MediaContentDescription*>(
2522 desc->contents()[i].description);
2523 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2524 }
2525
2526 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2527 EXPECT_EQ(sdp_string, serialized_sdp);
2528 }
2529}