blob: 975b0acd0de4079319a23117cb2ebdd0e3d904af [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.org61c12472015-01-15 06:53:07 +0000591 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000592 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
593 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000595 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000596 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
597 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000599 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000600 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
601 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000603 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000604 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
605 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
607 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000608 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000609 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
610 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000611 cricket::LOCAL_PORT_TYPE,
612 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000614 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
615 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000616 cricket::LOCAL_PORT_TYPE,
617 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000619 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
620 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000621 cricket::LOCAL_PORT_TYPE,
622 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000624 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
625 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000626 cricket::LOCAL_PORT_TYPE,
627 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628
629 // stun
630 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000631 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
632 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000633 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
634 address_stun, kCandidatePriority, "", "",
635 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000636 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 candidate9.set_related_address(rel_address_stun);
638
639 address_stun.SetPort(port_stun++);
640 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000641 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
642 address_stun, kCandidatePriority, "", "",
643 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000644 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 candidate10.set_related_address(rel_address_stun);
646
647 // relay
648 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000650 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
651 address_relay, kCandidatePriority, "", "",
652 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000653 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000655 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
656 address_relay, kCandidatePriority, "", "",
657 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000658 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659
660 // voice
661 candidates_.push_back(candidate1);
662 candidates_.push_back(candidate2);
663 candidates_.push_back(candidate5);
664 candidates_.push_back(candidate6);
665 candidates_.push_back(candidate9);
666 candidates_.push_back(candidate10);
667
668 // video
669 candidates_.push_back(candidate3);
670 candidates_.push_back(candidate4);
671 candidates_.push_back(candidate7);
672 candidates_.push_back(candidate8);
673 candidates_.push_back(candidate11);
674 candidates_.push_back(candidate12);
675
676 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
677 0, candidate1));
678
679 // Set up JsepSessionDescription.
680 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
681 std::string mline_id;
682 int mline_index = 0;
683 for (size_t i = 0; i< candidates_.size(); ++i) {
684 // In this test, the audio m line index will be 0, and the video m line
685 // will be 1.
686 bool is_video = (i > 5);
687 mline_id = is_video ? "video_content_name" : "audio_content_name";
688 mline_index = is_video ? 1 : 0;
689 JsepIceCandidate jice(mline_id,
690 mline_index,
691 candidates_.at(i));
692 jdesc_.AddCandidate(&jice);
693 }
694 }
695
696 AudioContentDescription* CreateAudioContentDescription() {
697 AudioContentDescription* audio = new AudioContentDescription();
698 audio->set_rtcp_mux(true);
699 StreamParams audio_stream1;
700 audio_stream1.id = kAudioTrackId1;
701 audio_stream1.cname = kStream1Cname;
702 audio_stream1.sync_label = kStreamLabel1;
703 audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc);
704 audio->AddStream(audio_stream1);
705 StreamParams audio_stream2;
706 audio_stream2.id = kAudioTrackId2;
707 audio_stream2.cname = kStream2Cname;
708 audio_stream2.sync_label = kStreamLabel2;
709 audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc);
710 audio->AddStream(audio_stream2);
711 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
712 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
713 "dummy_session_params"));
714 audio->set_protocol(cricket::kMediaProtocolSavpf);
715 return audio;
716 }
717
718 template <class MCD>
719 void CompareMediaContentDescription(const MCD* cd1,
720 const MCD* cd2) {
721 // type
722 EXPECT_EQ(cd1->type(), cd1->type());
723
724 // content direction
725 EXPECT_EQ(cd1->direction(), cd2->direction());
726
727 // rtcp_mux
728 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
729
730 // cryptos
731 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
732 if (cd1->cryptos().size() != cd2->cryptos().size()) {
733 ADD_FAILURE();
734 return;
735 }
736 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
737 const CryptoParams c1 = cd1->cryptos().at(i);
738 const CryptoParams c2 = cd2->cryptos().at(i);
739 EXPECT_TRUE(c1.Matches(c2));
740 EXPECT_EQ(c1.key_params, c2.key_params);
741 EXPECT_EQ(c1.session_params, c2.session_params);
742 }
743 // protocol
744 EXPECT_EQ(cd1->protocol(), cd2->protocol());
745
746 // codecs
747 EXPECT_EQ(cd1->codecs(), cd2->codecs());
748
749 // bandwidth
750 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
751
752 // streams
753 EXPECT_EQ(cd1->streams(), cd2->streams());
754
755 // extmap
756 ASSERT_EQ(cd1->rtp_header_extensions().size(),
757 cd2->rtp_header_extensions().size());
758 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
759 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
760 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
761 EXPECT_EQ(ext1.uri, ext2.uri);
762 EXPECT_EQ(ext1.id, ext2.id);
763 }
764
765 // buffered mode latency
766 EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency());
767 }
768
769
770 void CompareSessionDescription(const SessionDescription& desc1,
771 const SessionDescription& desc2) {
772 // Compare content descriptions.
773 if (desc1.contents().size() != desc2.contents().size()) {
774 ADD_FAILURE();
775 return;
776 }
777 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
778 const cricket::ContentInfo& c1 = desc1.contents().at(i);
779 const cricket::ContentInfo& c2 = desc2.contents().at(i);
780 // content name
781 EXPECT_EQ(c1.name, c2.name);
782 // content type
783 // Note, ASSERT will return from the function, but will not stop the test.
784 ASSERT_EQ(c1.type, c2.type);
785
786 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
787 if (IsAudioContent(&c1)) {
788 const AudioContentDescription* acd1 =
789 static_cast<const AudioContentDescription*>(c1.description);
790 const AudioContentDescription* acd2 =
791 static_cast<const AudioContentDescription*>(c2.description);
792 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
793 }
794
795 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
796 if (IsVideoContent(&c1)) {
797 const VideoContentDescription* vcd1 =
798 static_cast<const VideoContentDescription*>(c1.description);
799 const VideoContentDescription* vcd2 =
800 static_cast<const VideoContentDescription*>(c2.description);
801 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
802 }
803
804 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
805 if (IsDataContent(&c1)) {
806 const DataContentDescription* dcd1 =
807 static_cast<const DataContentDescription*>(c1.description);
808 const DataContentDescription* dcd2 =
809 static_cast<const DataContentDescription*>(c2.description);
810 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
811 }
812 }
813
814 // group
815 const cricket::ContentGroups groups1 = desc1.groups();
816 const cricket::ContentGroups groups2 = desc2.groups();
817 EXPECT_EQ(groups1.size(), groups1.size());
818 if (groups1.size() != groups2.size()) {
819 ADD_FAILURE();
820 return;
821 }
822 for (size_t i = 0; i < groups1.size(); ++i) {
823 const cricket::ContentGroup group1 = groups1.at(i);
824 const cricket::ContentGroup group2 = groups2.at(i);
825 EXPECT_EQ(group1.semantics(), group2.semantics());
826 const cricket::ContentNames names1 = group1.content_names();
827 const cricket::ContentNames names2 = group2.content_names();
828 EXPECT_EQ(names1.size(), names2.size());
829 if (names1.size() != names2.size()) {
830 ADD_FAILURE();
831 return;
832 }
833 cricket::ContentNames::const_iterator iter1 = names1.begin();
834 cricket::ContentNames::const_iterator iter2 = names2.begin();
835 while (iter1 != names1.end()) {
836 EXPECT_EQ(*iter1++, *iter2++);
837 }
838 }
839
840 // transport info
841 const cricket::TransportInfos transports1 = desc1.transport_infos();
842 const cricket::TransportInfos transports2 = desc2.transport_infos();
843 EXPECT_EQ(transports1.size(), transports2.size());
844 if (transports1.size() != transports2.size()) {
845 ADD_FAILURE();
846 return;
847 }
848 for (size_t i = 0; i < transports1.size(); ++i) {
849 const cricket::TransportInfo transport1 = transports1.at(i);
850 const cricket::TransportInfo transport2 = transports2.at(i);
851 EXPECT_EQ(transport1.content_name, transport2.content_name);
852 EXPECT_EQ(transport1.description.transport_type,
853 transport2.description.transport_type);
854 EXPECT_EQ(transport1.description.ice_ufrag,
855 transport2.description.ice_ufrag);
856 EXPECT_EQ(transport1.description.ice_pwd,
857 transport2.description.ice_pwd);
858 if (transport1.description.identity_fingerprint) {
859 EXPECT_EQ(*transport1.description.identity_fingerprint,
860 *transport2.description.identity_fingerprint);
861 } else {
862 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
863 transport2.description.identity_fingerprint.get());
864 }
865 EXPECT_EQ(transport1.description.transport_options,
866 transport2.description.transport_options);
867 EXPECT_TRUE(CompareCandidates(transport1.description.candidates,
868 transport2.description.candidates));
869 }
870 }
871
872 bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) {
873 EXPECT_EQ(cs1.size(), cs2.size());
874 if (cs1.size() != cs2.size())
875 return false;
876 for (size_t i = 0; i< cs1.size(); ++i) {
877 const Candidate c1 = cs1.at(i);
878 const Candidate c2 = cs2.at(i);
879 EXPECT_TRUE(c1.IsEquivalent(c2));
880 }
881 return true;
882 }
883
884 bool CompareSessionDescription(
885 const JsepSessionDescription& desc1,
886 const JsepSessionDescription& desc2) {
887 EXPECT_EQ(desc1.session_id(), desc2.session_id());
888 EXPECT_EQ(desc1.session_version(), desc2.session_version());
889 CompareSessionDescription(*desc1.description(), *desc2.description());
890 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
891 return false;
892 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
893 const IceCandidateCollection* cc1 = desc1.candidates(i);
894 const IceCandidateCollection* cc2 = desc2.candidates(i);
895 if (cc1->count() != cc2->count())
896 return false;
897 for (size_t j = 0; j < cc1->count(); ++j) {
898 const IceCandidateInterface* c1 = cc1->at(j);
899 const IceCandidateInterface* c2 = cc2->at(j);
900 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
901 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
902 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
903 }
904 }
905 return true;
906 }
907
908 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
909 // them with invalid keywords so that the parser will just ignore them.
910 bool RemoveCandidateUfragPwd(std::string* sdp) {
911 const char ice_ufrag[] = "a=ice-ufrag";
912 const char ice_ufragx[] = "a=xice-ufrag";
913 const char ice_pwd[] = "a=ice-pwd";
914 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000915 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 ice_pwdx, strlen(ice_pwdx), sdp);
919 return true;
920 }
921
922 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
923 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
924 const std::string& ufrag, const std::string& pwd) {
925 std::string content_name;
926 if (mline_index == 0) {
927 content_name = kAudioContentName;
928 } else if (mline_index == 1) {
929 content_name = kVideoContentName;
930 } else {
931 ASSERT(false);
932 }
933 TransportInfo transport_info(
934 content_name, TransportDescription(NS_JINGLE_ICE_UDP,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000935 ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 SessionDescription* desc =
937 const_cast<SessionDescription*>(jdesc->description());
938 desc->RemoveTransportInfoByName(content_name);
939 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
940 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
941 const IceCandidateCollection* cc = jdesc_.candidates(i);
942 for (size_t j = 0; j < cc->count(); ++j) {
943 if (cc->at(j)->sdp_mline_index() == mline_index) {
944 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
945 ufrag);
946 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
947 pwd);
948 }
949 }
950 }
951 return true;
952 }
953
954 void AddIceOptions(const std::string& content_name,
955 const std::vector<std::string>& transport_options) {
956 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
957 cricket::TransportInfo transport_info =
958 *(desc_.GetTransportInfoByName(content_name));
959 desc_.RemoveTransportInfoByName(content_name);
960 transport_info.description.transport_options = transport_options;
961 desc_.AddTransportInfo(transport_info);
962 }
963
964 void AddFingerprint() {
965 desc_.RemoveTransportInfoByName(kAudioContentName);
966 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000967 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 kIdentityDigest,
969 sizeof(kIdentityDigest));
970 EXPECT_TRUE(desc_.AddTransportInfo(
971 TransportInfo(kAudioContentName,
972 TransportDescription(NS_JINGLE_ICE_UDP,
973 std::vector<std::string>(),
974 kCandidateUfragVoice,
975 kCandidatePwdVoice,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000976 cricket::ICEMODE_FULL,
977 cricket::CONNECTIONROLE_NONE,
978 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_TRUE(desc_.AddTransportInfo(
980 TransportInfo(kVideoContentName,
981 TransportDescription(NS_JINGLE_ICE_UDP,
982 std::vector<std::string>(),
983 kCandidateUfragVideo,
984 kCandidatePwdVideo,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000985 cricket::ICEMODE_FULL,
986 cricket::CONNECTIONROLE_NONE,
987 &fingerprint, Candidates()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989
990 void AddExtmap() {
991 audio_desc_ = static_cast<AudioContentDescription*>(
992 audio_desc_->Copy());
993 video_desc_ = static_cast<VideoContentDescription*>(
994 video_desc_->Copy());
995 audio_desc_->AddRtpHeaderExtension(
996 RtpHeaderExtension(kExtmapUri, kExtmapId));
997 video_desc_->AddRtpHeaderExtension(
998 RtpHeaderExtension(kExtmapUri, kExtmapId));
999 desc_.RemoveContentByName(kAudioContentName);
1000 desc_.RemoveContentByName(kVideoContentName);
1001 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1002 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1003 }
1004
1005 void RemoveCryptos() {
1006 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1007 video_desc_->set_cryptos(std::vector<CryptoParams>());
1008 }
1009
1010 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1011 audio_desc_->set_direction(direction);
1012 video_desc_->set_direction(direction);
1013 std::string new_sdp = kSdpFullString;
1014 ReplaceDirection(direction, &new_sdp);
1015
1016 if (!jdesc_.Initialize(desc_.Copy(),
1017 jdesc_.session_id(),
1018 jdesc_.session_version())) {
1019 return false;
1020 }
1021 std::string message = webrtc::SdpSerialize(jdesc_);
1022 EXPECT_EQ(new_sdp, message);
1023 return true;
1024 }
1025
1026 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1027 audio_desc_ = static_cast<AudioContentDescription*>(
1028 audio_desc_->Copy());
1029 video_desc_ = static_cast<VideoContentDescription*>(
1030 video_desc_->Copy());
1031 desc_.RemoveContentByName(kAudioContentName);
1032 desc_.RemoveContentByName(kVideoContentName);
1033 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1034 audio_desc_);
1035 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1036 video_desc_);
1037 std::string new_sdp = kSdpFullString;
1038 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1039
1040 if (!jdesc_.Initialize(desc_.Copy(),
1041 jdesc_.session_id(),
1042 jdesc_.session_version())) {
1043 return false;
1044 }
1045 std::string message = webrtc::SdpSerialize(jdesc_);
1046 EXPECT_EQ(new_sdp, message);
1047 return true;
1048 }
1049
1050 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 new DataContentDescription());
1053 data_desc_ = data.get();
1054 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001055 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1056 cricket::kGoogleSctpDataCodecName, 0);
1057 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1058 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1060 EXPECT_TRUE(desc_.AddTransportInfo(
1061 TransportInfo(kDataContentName,
1062 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001064 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 }
1066
1067 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001068 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 new DataContentDescription());
1070 data_desc_ = data.get();
1071
1072 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1073 StreamParams data_stream;
1074 data_stream.id = kDataChannelMsid;
1075 data_stream.cname = kDataChannelCname;
1076 data_stream.sync_label = kDataChannelLabel;
1077 data_stream.ssrcs.push_back(kDataChannelSsrc);
1078 data_desc_->AddStream(data_stream);
1079 data_desc_->AddCrypto(CryptoParams(
1080 1, "AES_CM_128_HMAC_SHA1_80",
1081 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1082 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1083 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
1084 EXPECT_TRUE(desc_.AddTransportInfo(
1085 TransportInfo(kDataContentName,
1086 TransportDescription(NS_JINGLE_ICE_UDP,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 kCandidateUfragData,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001088 kCandidatePwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 }
1090
1091 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1092 std::string new_sdp = kSdpFullString;
1093 ReplaceDirection(direction, &new_sdp);
1094 JsepSessionDescription new_jdesc(kDummyString);
1095
1096 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1097
1098 audio_desc_->set_direction(direction);
1099 video_desc_->set_direction(direction);
1100 if (!jdesc_.Initialize(desc_.Copy(),
1101 jdesc_.session_id(),
1102 jdesc_.session_version())) {
1103 return false;
1104 }
1105 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1106 return true;
1107 }
1108
1109 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
1110 std::string new_sdp = kSdpFullString;
1111 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1112 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
1113
1114 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1115 audio_desc_ = static_cast<AudioContentDescription*>(
1116 audio_desc_->Copy());
1117 video_desc_ = static_cast<VideoContentDescription*>(
1118 video_desc_->Copy());
1119 desc_.RemoveContentByName(kAudioContentName);
1120 desc_.RemoveContentByName(kVideoContentName);
1121 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1122 audio_desc_);
1123 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1124 video_desc_);
1125 if (!jdesc_.Initialize(desc_.Copy(),
1126 jdesc_.session_id(),
1127 jdesc_.session_version())) {
1128 return false;
1129 }
1130 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1131 return true;
1132 }
1133
1134 void TestDeserializeExtmap(bool session_level, bool media_level) {
1135 AddExtmap();
1136 JsepSessionDescription new_jdesc("dummy");
1137 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1138 jdesc_.session_id(),
1139 jdesc_.session_version()));
1140 JsepSessionDescription jdesc_with_extmap("dummy");
1141 std::string sdp_with_extmap = kSdpString;
1142 if (session_level) {
1143 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1144 &sdp_with_extmap);
1145 }
1146 if (media_level) {
1147 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1148 &sdp_with_extmap);
1149 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1150 &sdp_with_extmap);
1151 }
1152 // The extmap can't be present at the same time in both session level and
1153 // media level.
1154 if (session_level && media_level) {
1155 SdpParseError error;
1156 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1157 &jdesc_with_extmap, &error));
1158 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1159 } else {
1160 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1161 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1162 }
1163 }
1164
1165 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1166 const std::string& name, int expected_value) {
1167 cricket::CodecParameterMap::const_iterator found = params.find(name);
1168 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001169 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 }
1171
1172 void TestDeserializeCodecParams(const CodecParams& params,
1173 JsepSessionDescription* jdesc_output) {
1174 std::string sdp =
1175 "v=0\r\n"
1176 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1177 "s=-\r\n"
1178 "t=0 0\r\n"
1179 // Include semantics for WebRTC Media Streams since it is supported by
1180 // this parser, and will be added to the SDP when serializing a session
1181 // description.
1182 "a=msid-semantic: WMS\r\n"
1183 // Pl type 111 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001184 "m=audio 9 RTP/SAVPF 111 104 103 102\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185 // Pltype 111 listed before 103 and 104 in the map.
1186 "a=rtpmap:111 opus/48000/2\r\n"
1187 // Pltype 103 listed before 104.
1188 "a=rtpmap:103 ISAC/16000\r\n"
1189 "a=rtpmap:104 CELT/32000/2\r\n"
1190 "a=rtpmap:102 ISAC/32000/1\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001191 "a=fmtp:111 0-15,66,70\r\n"
1192 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 std::ostringstream os;
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001194 os << "minptime=" << params.min_ptime
1195 << "; stereo=" << params.stereo
1196 << "; sprop-stereo=" << params.sprop_stereo
1197 << "; useinbandfec=" << params.useinband
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001198 << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 << "a=ptime:" << params.ptime << "\r\n"
1200 << "a=maxptime:" << params.max_ptime << "\r\n";
1201 sdp += os.str();
1202
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001203 os.clear();
1204 os.str("");
1205 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001206 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001207 << "a=rtpmap:99 VP8/90000\r\n"
1208 << "a=rtpmap:95 RTX/90000\r\n"
1209 << "a=fmtp:95 apt=99;rtx-time=1000\r\n";
1210 sdp += os.str();
1211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 // Deserialize
1213 SdpParseError error;
1214 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1215
1216 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1217 ASSERT_TRUE(ac != NULL);
1218 const AudioContentDescription* acd =
1219 static_cast<const AudioContentDescription*>(ac->description);
1220 ASSERT_FALSE(acd->codecs().empty());
1221 cricket::AudioCodec opus = acd->codecs()[0];
1222 EXPECT_EQ("opus", opus.name);
1223 EXPECT_EQ(111, opus.id);
1224 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1225 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1226 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1227 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001228 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1229 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1231 cricket::AudioCodec codec = acd->codecs()[i];
1232 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1233 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1234 if (codec.name == "ISAC") {
1235 if (codec.clockrate == 16000) {
1236 EXPECT_EQ(32000, codec.bitrate);
1237 } else {
1238 EXPECT_EQ(56000, codec.bitrate);
1239 }
1240 }
1241 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001242
1243 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1244 ASSERT_TRUE(vc != NULL);
1245 const VideoContentDescription* vcd =
1246 static_cast<const VideoContentDescription*>(vc->description);
1247 ASSERT_FALSE(vcd->codecs().empty());
1248 cricket::VideoCodec vp8 = vcd->codecs()[0];
1249 EXPECT_EQ("VP8", vp8.name);
1250 EXPECT_EQ(99, vp8.id);
1251 cricket::VideoCodec rtx = vcd->codecs()[1];
1252 EXPECT_EQ("RTX", rtx.name);
1253 EXPECT_EQ(95, rtx.id);
1254 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 }
1256
1257 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1258 bool use_wildcard) {
1259 std::string sdp =
1260 "v=0\r\n"
1261 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1262 "s=-\r\n"
1263 "t=0 0\r\n"
1264 // Include semantics for WebRTC Media Streams since it is supported by
1265 // this parser, and will be added to the SDP when serializing a session
1266 // description.
1267 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001268 "m=audio 9 RTP/SAVPF 111\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 "a=rtpmap:111 opus/48000/2\r\n"
1270 "a=rtcp-fb:111 nack\r\n"
1271 "m=video 3457 RTP/SAVPF 101\r\n"
1272 "a=rtpmap:101 VP8/90000\r\n"
1273 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001274 "a=rtcp-fb:101 nack pli\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 "a=rtcp-fb:101 goog-remb\r\n"
1276 "a=rtcp-fb:101 ccm fir\r\n";
1277 std::ostringstream os;
1278 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
1279 sdp += os.str();
1280 // Deserialize
1281 SdpParseError error;
1282 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1283 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1284 ASSERT_TRUE(ac != NULL);
1285 const AudioContentDescription* acd =
1286 static_cast<const AudioContentDescription*>(ac->description);
1287 ASSERT_FALSE(acd->codecs().empty());
1288 cricket::AudioCodec opus = acd->codecs()[0];
1289 EXPECT_EQ(111, opus.id);
1290 EXPECT_TRUE(opus.HasFeedbackParam(
1291 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1292 cricket::kParamValueEmpty)));
1293
1294 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1295 ASSERT_TRUE(vc != NULL);
1296 const VideoContentDescription* vcd =
1297 static_cast<const VideoContentDescription*>(vc->description);
1298 ASSERT_FALSE(vcd->codecs().empty());
1299 cricket::VideoCodec vp8 = vcd->codecs()[0];
1300 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1301 vp8.name.c_str());
1302 EXPECT_EQ(101, vp8.id);
1303 EXPECT_TRUE(vp8.HasFeedbackParam(
1304 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1305 cricket::kParamValueEmpty)));
1306 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001307 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1308 cricket::kRtcpFbNackParamPli)));
1309 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1311 cricket::kParamValueEmpty)));
1312 EXPECT_TRUE(vp8.HasFeedbackParam(
1313 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1314 cricket::kRtcpFbCcmParamFir)));
1315 }
1316
1317 // Two SDP messages can mean the same thing but be different strings, e.g.
1318 // some of the lines can be serialized in different order.
1319 // However, a deserialized description can be compared field by field and has
1320 // no order. If deserializer has already been tested, serializing then
1321 // deserializing and comparing JsepSessionDescription will test
1322 // the serializer sufficiently.
1323 void TestSerialize(const JsepSessionDescription& jdesc) {
1324 std::string message = webrtc::SdpSerialize(jdesc);
1325 JsepSessionDescription jdesc_output_des(kDummyString);
1326 SdpParseError error;
1327 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1328 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1329 }
1330
1331 protected:
1332 SessionDescription desc_;
1333 AudioContentDescription* audio_desc_;
1334 VideoContentDescription* video_desc_;
1335 DataContentDescription* data_desc_;
1336 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001337 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 JsepSessionDescription jdesc_;
1339};
1340
1341void TestMismatch(const std::string& string1, const std::string& string2) {
1342 int position = 0;
1343 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1344 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001345 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 break;
1347 }
1348 }
1349 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1350 << " character\n"
1351 << " 1: " << string1.substr(position, 20) << "\n"
1352 << " 2: " << string2.substr(position, 20) << "\n";
1353}
1354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1356 // SessionDescription with desc and candidates.
1357 std::string message = webrtc::SdpSerialize(jdesc_);
1358 TestMismatch(std::string(kSdpFullString), message);
1359}
1360
1361TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1362 JsepSessionDescription jdesc_empty(kDummyString);
1363 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
1364}
1365
1366// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1367// the case in a DTLS offer.
1368TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1369 AddFingerprint();
1370 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1371 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1372 kSessionId, kSessionVersion));
1373 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1374
1375 std::string sdp_with_fingerprint = kSdpString;
1376 InjectAfter(kAttributeIcePwdVoice,
1377 kFingerprint, &sdp_with_fingerprint);
1378 InjectAfter(kAttributeIcePwdVideo,
1379 kFingerprint, &sdp_with_fingerprint);
1380
1381 EXPECT_EQ(sdp_with_fingerprint, message);
1382}
1383
1384// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1385// be the case in a DTLS answer.
1386TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1387 AddFingerprint();
1388 RemoveCryptos();
1389 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1390 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1391 kSessionId, kSessionVersion));
1392 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
1393
1394 std::string sdp_with_fingerprint = kSdpString;
1395 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1396 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1397 InjectAfter(kAttributeIcePwdVoice,
1398 kFingerprint, &sdp_with_fingerprint);
1399 InjectAfter(kAttributeIcePwdVideo,
1400 kFingerprint, &sdp_with_fingerprint);
1401
1402 EXPECT_EQ(sdp_with_fingerprint, message);
1403}
1404
1405TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1406 // JsepSessionDescription with desc but without candidates.
1407 JsepSessionDescription jdesc_no_candidates(kDummyString);
1408 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1409 kSessionId, kSessionVersion));
1410 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
1411 EXPECT_EQ(std::string(kSdpString), message);
1412}
1413
1414TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1415 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1416 group.AddContentName(kAudioContentName);
1417 group.AddContentName(kVideoContentName);
1418 desc_.AddGroup(group);
1419 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1420 jdesc_.session_id(),
1421 jdesc_.session_version()));
1422 std::string message = webrtc::SdpSerialize(jdesc_);
1423 std::string sdp_with_bundle = kSdpFullString;
1424 InjectAfter(kSessionTime,
1425 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1426 &sdp_with_bundle);
1427 EXPECT_EQ(sdp_with_bundle, message);
1428}
1429
1430TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1431 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1432 GetFirstVideoContent(&desc_)->description);
1433 vcd->set_bandwidth(100 * 1000);
1434 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1435 GetFirstAudioContent(&desc_)->description);
1436 acd->set_bandwidth(50 * 1000);
1437 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1438 jdesc_.session_id(),
1439 jdesc_.session_version()));
1440 std::string message = webrtc::SdpSerialize(jdesc_);
1441 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001442 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 "b=AS:100\r\n",
1444 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001445 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 "b=AS:50\r\n",
1447 &sdp_with_bandwidth);
1448 EXPECT_EQ(sdp_with_bandwidth, message);
1449}
1450
1451TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1452 std::vector<std::string> transport_options;
1453 transport_options.push_back(kIceOption1);
1454 transport_options.push_back(kIceOption3);
1455 AddIceOptions(kAudioContentName, transport_options);
1456 transport_options.clear();
1457 transport_options.push_back(kIceOption2);
1458 transport_options.push_back(kIceOption3);
1459 AddIceOptions(kVideoContentName, transport_options);
1460 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1461 jdesc_.session_id(),
1462 jdesc_.session_version()));
1463 std::string message = webrtc::SdpSerialize(jdesc_);
1464 std::string sdp_with_ice_options = kSdpFullString;
1465 InjectAfter(kAttributeIcePwdVoice,
1466 "a=ice-options:iceoption1 iceoption3\r\n",
1467 &sdp_with_ice_options);
1468 InjectAfter(kAttributeIcePwdVideo,
1469 "a=ice-options:iceoption2 iceoption3\r\n",
1470 &sdp_with_ice_options);
1471 EXPECT_EQ(sdp_with_ice_options, message);
1472}
1473
1474TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1475 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1476}
1477
1478TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1479 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1480}
1481
1482TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1483 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1484}
1485
1486TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1487 EXPECT_TRUE(TestSerializeRejected(true, false));
1488}
1489
1490TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1491 EXPECT_TRUE(TestSerializeRejected(false, true));
1492}
1493
1494TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1495 EXPECT_TRUE(TestSerializeRejected(true, true));
1496}
1497
1498TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1499 AddRtpDataChannel();
1500 JsepSessionDescription jsep_desc(kDummyString);
1501
1502 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1503 std::string message = webrtc::SdpSerialize(jsep_desc);
1504
1505 std::string expected_sdp = kSdpString;
1506 expected_sdp.append(kSdpRtpDataChannelString);
1507 EXPECT_EQ(expected_sdp, message);
1508}
1509
1510TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1511 AddSctpDataChannel();
1512 JsepSessionDescription jsep_desc(kDummyString);
1513
1514 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1515 std::string message = webrtc::SdpSerialize(jsep_desc);
1516
1517 std::string expected_sdp = kSdpString;
1518 expected_sdp.append(kSdpSctpDataChannelString);
1519 EXPECT_EQ(message, expected_sdp);
1520}
1521
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001522TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1523 AddSctpDataChannel();
1524 JsepSessionDescription jsep_desc(kDummyString);
1525
1526 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1527 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1528 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1529
1530 const int kNewPort = 1234;
1531 cricket::DataCodec codec(
1532 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1533 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1534 dcdesc->AddOrReplaceCodec(codec);
1535
1536 std::string message = webrtc::SdpSerialize(jsep_desc);
1537
1538 std::string expected_sdp = kSdpString;
1539 expected_sdp.append(kSdpSctpDataChannelString);
1540
1541 char default_portstr[16];
1542 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001543 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001544 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001545 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1546 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001547 new_portstr, strlen(new_portstr),
1548 &expected_sdp);
1549
1550 EXPECT_EQ(expected_sdp, message);
1551}
1552
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001553TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
1554 AddRtpDataChannel();
1555 data_desc_->set_bandwidth(100*1000);
1556 JsepSessionDescription jsep_desc(kDummyString);
1557
1558 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1559 std::string message = webrtc::SdpSerialize(jsep_desc);
1560
1561 std::string expected_sdp = kSdpString;
1562 expected_sdp.append(kSdpRtpDataChannelString);
1563 // We want to test that serializing data content ignores bandwidth
1564 // settings (it should always be the default). Thus, we don't do
1565 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001566 // TODO(pthatcher): We need to temporarily allow the SDP to control
1567 // this for backwards-compatibility. Once we don't need that any
1568 // more, remove this.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00001569 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 +00001570 "b=AS:100\r\n",
1571 &expected_sdp);
1572 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001573}
1574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
1576 AddExtmap();
1577 JsepSessionDescription desc_with_extmap("dummy");
1578 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
1579 kSessionId, kSessionVersion));
1580 std::string message = webrtc::SdpSerialize(desc_with_extmap);
1581
1582 std::string sdp_with_extmap = kSdpString;
1583 InjectAfter("a=mid:audio_content_name\r\n",
1584 kExtmap, &sdp_with_extmap);
1585 InjectAfter("a=mid:video_content_name\r\n",
1586 kExtmap, &sdp_with_extmap);
1587
1588 EXPECT_EQ(sdp_with_extmap, message);
1589}
1590
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001591TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBufferLatency) {
1592 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1593 GetFirstVideoContent(&desc_)->description);
1594 vcd->set_buffered_mode_latency(128);
1595
1596 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1597 jdesc_.session_id(),
1598 jdesc_.session_version()));
1599 std::string message = webrtc::SdpSerialize(jdesc_);
1600 std::string sdp_with_buffer_latency = kSdpFullString;
1601 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1602 "a=x-google-buffer-latency:128\r\n",
1603 &sdp_with_buffer_latency);
1604 EXPECT_EQ(sdp_with_buffer_latency, message);
1605}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606
1607TEST_F(WebRtcSdpTest, SerializeCandidates) {
1608 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00001609 EXPECT_EQ(std::string(kRawCandidate), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610}
1611
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001612// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
1613// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00001614TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001615 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001616 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1617 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1618 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001619 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
1620 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
1621 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1622
1623 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
1624 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
1625}
1626
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
1628 JsepSessionDescription jdesc(kDummyString);
1629 // Deserialize
1630 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
1631 // Verify
1632 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1633}
1634
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001635TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
1636 JsepSessionDescription jdesc(kDummyString);
1637 const char kSdpWithoutMline[] =
1638 "v=0\r\n"
1639 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1640 "s=-\r\n"
1641 "t=0 0\r\n"
1642 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
1643 // Deserialize
1644 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
1645 EXPECT_EQ(0u, jdesc.description()->contents().size());
1646}
1647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
1649 JsepSessionDescription jdesc(kDummyString);
1650 std::string sdp_without_carriage_return = kSdpFullString;
1651 Replace("\r\n", "\n", &sdp_without_carriage_return);
1652 // Deserialize
1653 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
1654 // Verify
1655 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1656}
1657
1658TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
1659 // SessionDescription with desc but without candidates.
1660 JsepSessionDescription jdesc_no_candidates(kDummyString);
1661 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
1662 kSessionId, kSessionVersion));
1663 JsepSessionDescription new_jdesc(kDummyString);
1664 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
1665 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1666}
1667
1668TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
1669 static const char kSdpNoRtpmapString[] =
1670 "v=0\r\n"
1671 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1672 "s=-\r\n"
1673 "t=0 0\r\n"
1674 "m=audio 49232 RTP/AVP 0 18 103\r\n"
1675 // Codec that doesn't appear in the m= line will be ignored.
1676 "a=rtpmap:104 CELT/32000/2\r\n"
1677 // The rtpmap line for static payload codec is optional.
1678 "a=rtpmap:18 G729/16000\r\n"
1679 "a=rtpmap:103 ISAC/16000\r\n";
1680
1681 JsepSessionDescription jdesc(kDummyString);
1682 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1683 cricket::AudioContentDescription* audio =
1684 static_cast<AudioContentDescription*>(
1685 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1686 AudioCodecs ref_codecs;
1687 // The codecs in the AudioContentDescription will be sorted by preference.
1688 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
1689 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
1690 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
1691 EXPECT_EQ(ref_codecs, audio->codecs());
1692}
1693
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001694TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
1695 static const char kSdpNoRtpmapString[] =
1696 "v=0\r\n"
1697 "o=- 11 22 IN IP4 127.0.0.1\r\n"
1698 "s=-\r\n"
1699 "t=0 0\r\n"
1700 "m=audio 49232 RTP/AVP 18 103\r\n"
1701 "a=fmtp:18 annexb=yes\r\n"
1702 "a=rtpmap:103 ISAC/16000\r\n";
1703
1704 JsepSessionDescription jdesc(kDummyString);
1705 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
1706 cricket::AudioContentDescription* audio =
1707 static_cast<AudioContentDescription*>(
1708 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
1709
1710 cricket::AudioCodec g729 = audio->codecs()[0];
1711 EXPECT_EQ("G729", g729.name);
1712 EXPECT_EQ(8000, g729.clockrate);
1713 EXPECT_EQ(18, g729.id);
1714 cricket::CodecParameterMap::iterator found =
1715 g729.params.find("annexb");
1716 ASSERT_TRUE(found != g729.params.end());
1717 EXPECT_EQ(found->second, "yes");
1718
1719 cricket::AudioCodec isac = audio->codecs()[1];
1720 EXPECT_EQ("ISAC", isac.name);
1721 EXPECT_EQ(103, isac.id);
1722 EXPECT_EQ(16000, isac.clockrate);
1723}
1724
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725// Ensure that we can deserialize SDP with a=fingerprint properly.
1726TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
1727 // Add a DTLS a=fingerprint attribute to our session description.
1728 AddFingerprint();
1729 JsepSessionDescription new_jdesc(kDummyString);
1730 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1731 jdesc_.session_id(),
1732 jdesc_.session_version()));
1733
1734 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1735 std::string sdp_with_fingerprint = kSdpString;
1736 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1737 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
1738 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
1739 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
1740}
1741
1742TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
1743 JsepSessionDescription jdesc_with_bundle(kDummyString);
1744 std::string sdp_with_bundle = kSdpFullString;
1745 InjectAfter(kSessionTime,
1746 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1747 &sdp_with_bundle);
1748 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
1749 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1750 group.AddContentName(kAudioContentName);
1751 group.AddContentName(kVideoContentName);
1752 desc_.AddGroup(group);
1753 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1754 jdesc_.session_id(),
1755 jdesc_.session_version()));
1756 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
1757}
1758
1759TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
1760 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
1761 std::string sdp_with_bandwidth = kSdpFullString;
1762 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
1763 "b=AS:100\r\n",
1764 &sdp_with_bandwidth);
1765 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
1766 "b=AS:50\r\n",
1767 &sdp_with_bandwidth);
1768 EXPECT_TRUE(
1769 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
1770 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1771 GetFirstVideoContent(&desc_)->description);
1772 vcd->set_bandwidth(100 * 1000);
1773 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1774 GetFirstAudioContent(&desc_)->description);
1775 acd->set_bandwidth(50 * 1000);
1776 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1777 jdesc_.session_id(),
1778 jdesc_.session_version()));
1779 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
1780}
1781
1782TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
1783 JsepSessionDescription jdesc_with_ice_options(kDummyString);
1784 std::string sdp_with_ice_options = kSdpFullString;
1785 InjectAfter(kSessionTime,
1786 "a=ice-options:iceoption3\r\n",
1787 &sdp_with_ice_options);
1788 InjectAfter(kAttributeIcePwdVoice,
1789 "a=ice-options:iceoption1\r\n",
1790 &sdp_with_ice_options);
1791 InjectAfter(kAttributeIcePwdVideo,
1792 "a=ice-options:iceoption2\r\n",
1793 &sdp_with_ice_options);
1794 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
1795 std::vector<std::string> transport_options;
1796 transport_options.push_back(kIceOption3);
1797 transport_options.push_back(kIceOption1);
1798 AddIceOptions(kAudioContentName, transport_options);
1799 transport_options.clear();
1800 transport_options.push_back(kIceOption3);
1801 transport_options.push_back(kIceOption2);
1802 AddIceOptions(kVideoContentName, transport_options);
1803 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1804 jdesc_.session_id(),
1805 jdesc_.session_version()));
1806 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
1807}
1808
1809TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
1810 // Remove the original ice-ufrag and ice-pwd
1811 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
1812 std::string sdp_with_ufrag_pwd = kSdpFullString;
1813 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
1814 // Add session level ufrag and pwd
1815 InjectAfter(kSessionTime,
1816 "a=ice-pwd:session+level+icepwd\r\n"
1817 "a=ice-ufrag:session+level+iceufrag\r\n",
1818 &sdp_with_ufrag_pwd);
1819 // Add media level ufrag and pwd for audio
1820 InjectAfter("a=mid:audio_content_name\r\n",
1821 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
1822 &sdp_with_ufrag_pwd);
1823 // Update the candidate ufrag and pwd to the expected ones.
1824 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
1825 "media+level+iceufrag", "media+level+icepwd"));
1826 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
1827 "session+level+iceufrag", "session+level+icepwd"));
1828 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
1829 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
1830}
1831
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001832TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBufferLatency) {
1833 JsepSessionDescription jdesc_with_buffer_latency(kDummyString);
1834 std::string sdp_with_buffer_latency = kSdpFullString;
1835 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
1836 "a=x-google-buffer-latency:128\r\n",
1837 &sdp_with_buffer_latency);
1838
1839 EXPECT_TRUE(
1840 SdpDeserialize(sdp_with_buffer_latency, &jdesc_with_buffer_latency));
1841 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1842 GetFirstVideoContent(&desc_)->description);
1843 vcd->set_buffered_mode_latency(128);
1844 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1845 jdesc_.session_id(),
1846 jdesc_.session_version()));
1847 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_buffer_latency));
1848}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849
1850TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
1851 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
1852}
1853
1854TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
1855 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
1856}
1857
1858TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
1859 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
1860}
1861
1862TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
1863 EXPECT_TRUE(TestDeserializeRejected(true, false));
1864}
1865
1866TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
1867 EXPECT_TRUE(TestDeserializeRejected(false, true));
1868}
1869
1870TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
1871 EXPECT_TRUE(TestDeserializeRejected(true, true));
1872}
1873
1874// Tests that we can still handle the sdp uses mslabel and label instead of
1875// msid for backward compatibility.
1876TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
1877 JsepSessionDescription jdesc(kDummyString);
1878 std::string sdp_without_msid = kSdpFullString;
1879 Replace("msid", "xmsid", &sdp_without_msid);
1880 // Deserialize
1881 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
1882 // Verify
1883 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
1884}
1885
1886TEST_F(WebRtcSdpTest, DeserializeCandidate) {
1887 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1888
1889 std::string sdp = kSdpOneCandidate;
1890 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1891 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1892 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1893 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1894
1895 // Candidate line without generation extension.
1896 sdp = kSdpOneCandidate;
1897 Replace(" generation 2", "", &sdp);
1898 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1899 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1900 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1901 Candidate expected = jcandidate_->candidate();
1902 expected.set_generation(0);
1903 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1904
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001905 sdp = kSdpTcpActiveCandidate;
1906 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1907 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001908 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001909 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
1910 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
1911 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00001912 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
1913 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
1914 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
1915 jcandidate_template->candidate()));
1916 sdp = kSdpTcpPassiveCandidate;
1917 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
1918 sdp = kSdpTcpSOCandidate;
1919 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920}
1921
1922// This test verifies the deserialization of candidate-attribute
1923// as per RFC 5245. Candiate-attribute will be of the format
1924// candidate:<blah>. This format will be used when candidates
1925// are trickled.
1926TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
1927 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1928
1929 std::string candidate_attribute = kRawCandidate;
1930 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1931 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1932 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1933 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
1934 EXPECT_EQ(2u, jcandidate.candidate().generation());
1935
1936 // Candidate line without generation extension.
1937 candidate_attribute = kRawCandidate;
1938 Replace(" generation 2", "", &candidate_attribute);
1939 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1940 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
1941 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
1942 Candidate expected = jcandidate_->candidate();
1943 expected.set_generation(0);
1944 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
1945
1946 // Candidate line without candidate:
1947 candidate_attribute = kRawCandidate;
1948 Replace("candidate:", "", &candidate_attribute);
1949 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1950
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001951 // Candidate line with IPV6 address.
1952 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
1953}
1954
1955// This test verifies that the deserialization of an invalid candidate string
1956// fails.
1957TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
1958 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
1959
1960 std::string candidate_attribute = kRawCandidate;
1961 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00001963
1964 candidate_attribute = kSdpOneCandidate;
1965 candidate_attribute.replace(0, 1, "x");
1966 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1967
1968 candidate_attribute = kRawCandidate;
1969 candidate_attribute.append("\r\n");
1970 candidate_attribute.append(kRawCandidate);
1971 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
1972
1973 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974}
1975
1976TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
1977 AddRtpDataChannel();
1978 JsepSessionDescription jdesc(kDummyString);
1979 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1980
1981 std::string sdp_with_data = kSdpString;
1982 sdp_with_data.append(kSdpRtpDataChannelString);
1983 JsepSessionDescription jdesc_output(kDummyString);
1984
1985 // Deserialize
1986 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
1987 // Verify
1988 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
1989}
1990
1991TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
1992 AddSctpDataChannel();
1993 JsepSessionDescription jdesc(kDummyString);
1994 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1995
1996 std::string sdp_with_data = kSdpString;
1997 sdp_with_data.append(kSdpSctpDataChannelString);
1998 JsepSessionDescription jdesc_output(kDummyString);
1999
2000 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2001 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2002}
2003
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002004TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2005 AddSctpDataChannel();
2006 JsepSessionDescription jdesc(kDummyString);
2007 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2008
2009 std::string sdp_with_data = kSdpString;
2010 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2011 JsepSessionDescription jdesc_output(kDummyString);
2012
2013 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2014 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2015}
2016
2017// Test to check the behaviour if sctp-port is specified
2018// on the m= line and in a=sctp-port.
2019TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2020 AddSctpDataChannel();
2021 JsepSessionDescription jdesc(kDummyString);
2022 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2023
2024 std::string sdp_with_data = kSdpString;
2025 // Append m= attributes
2026 sdp_with_data.append(kSdpSctpDataChannelString);
2027 // Append a=sctp-port attribute
2028 sdp_with_data.append("a=sctp-port 5000\r\n");
2029 JsepSessionDescription jdesc_output(kDummyString);
2030
2031 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2032}
2033
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002034// For crbug/344475.
2035TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2036 std::string sdp_with_data = kSdpString;
2037 sdp_with_data.append(kSdpSctpDataChannelString);
2038 // Remove the "\n" at the end.
2039 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2040 JsepSessionDescription jdesc_output(kDummyString);
2041
2042 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2043 // No crash is a pass.
2044}
2045
wu@webrtc.org78187522013-10-07 23:32:02 +00002046TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2047 AddSctpDataChannel();
2048 const uint16 kUnusualSctpPort = 9556;
2049 char default_portstr[16];
2050 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002051 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002052 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002053 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002054 kUnusualSctpPort);
2055
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002056 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002057 JsepSessionDescription jdesc(kDummyString);
2058 // take our pre-built session description and change the SCTP port.
2059 cricket::SessionDescription* mutant = desc_.Copy();
2060 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2061 mutant->GetContentDescriptionByName(kDataContentName));
2062 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2063 EXPECT_EQ(codecs.size(), 1UL);
2064 EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId);
2065 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002066 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002067
2068 // note: mutant's owned by jdesc now.
2069 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2070 mutant = NULL;
2071
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002072 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002073 std::string sdp_with_data = kSdpString;
2074 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002075 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002076 unusual_portstr, strlen(unusual_portstr),
2077 &sdp_with_data);
2078 JsepSessionDescription jdesc_output(kDummyString);
2079
2080 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2081 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002082
2083 // We need to test the deserialized JsepSessionDescription from
2084 // kSdpSctpDataChannelStringWithSctpPort for
2085 // draft-ietf-mmusic-sctp-sdp-07
2086 // a=sctp-port
2087 sdp_with_data = kSdpString;
2088 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2089 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2090 unusual_portstr, strlen(unusual_portstr),
2091 &sdp_with_data);
2092
2093 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2094 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002095}
2096
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002097TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2098 AddRtpDataChannel();
2099 JsepSessionDescription jdesc(kDummyString);
2100 // We want to test that deserializing data content ignores bandwidth
2101 // settings (it should always be the default). Thus, we don't do
2102 // the following:
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002103 // TODO(pthatcher): We need to temporarily allow the SDP to control
2104 // this for backwards-compatibility. Once we don't need that any
2105 // more, remove this.
2106 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2107 GetFirstDataContent(&desc_)->description);
2108 dcd->set_bandwidth(100 * 1000);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002109 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2110
2111 std::string sdp_with_bandwidth = kSdpString;
2112 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2113 InjectAfter("a=mid:data_content_name\r\n",
2114 "b=AS:100\r\n",
2115 &sdp_with_bandwidth);
2116 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2117
2118 EXPECT_TRUE(
2119 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2120 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2121}
2122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2124 TestDeserializeExtmap(true, false);
2125}
2126
2127TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2128 TestDeserializeExtmap(false, true);
2129}
2130
2131TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2132 TestDeserializeExtmap(true, true);
2133}
2134
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002135TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2136 JsepSessionDescription jdesc(kDummyString);
2137 std::string sdp = kSdpFullString;
2138 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2139 // Deserialize
2140 SdpParseError error;
2141 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2142 const std::string lastline = "a=ssrc:6 label:video_track_id_3";
2143 EXPECT_EQ(lastline, error.line);
2144 EXPECT_EQ("Invalid SDP line.", error.description);
2145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2148 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2149 std::string new_sdp = kSdpOneCandidate;
2150 Replace("udp", "unsupported_transport", &new_sdp);
2151 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2152 new_sdp = kSdpOneCandidate;
2153 Replace("udp", "uDP", &new_sdp);
2154 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2155 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2156 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2157 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2158}
2159
2160TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) {
2161 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2162 EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate));
2163 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2164 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2165 Candidate ref_candidate = jcandidate_->candidate();
2166 ref_candidate.set_username("user_rtp");
2167 ref_candidate.set_password("password_rtp");
2168 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2169}
2170
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002171TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2172 JsepSessionDescription jdesc(kDummyString);
2173
2174 // Deserialize
2175 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2176
2177 // Verify
2178 cricket::AudioContentDescription* audio =
2179 static_cast<AudioContentDescription*>(
2180 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2181 EXPECT_TRUE(audio->conference_mode());
2182
2183 cricket::VideoContentDescription* video =
2184 static_cast<VideoContentDescription*>(
2185 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2186 EXPECT_TRUE(video->conference_mode());
2187}
2188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2190 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002191 const char kSdpEmptyType[] = " =candidate";
2192 const char kSdpEqualAsPlus[] = "a+candidate";
2193 const char kSdpSpaceAfterEqual[] = "a= candidate";
2194 const char kSdpUpperType[] = "A=candidate";
2195 const char kSdpEmptyLine[] = "";
2196 const char kSdpMissingValue[] = "a=";
2197
2198 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002200 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002202 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 "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 +00002204 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002205 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002206 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207
2208 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002209 ExpectParseFailure("v=", kSdpDestroyer);
2210 ExpectParseFailure("o=", kSdpDestroyer);
2211 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002213 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214
2215 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002216 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2217 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218
2219 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002220 ExpectParseFailure("a=candidate", kSdpEmptyType);
2221 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2222 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2223 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224
2225 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2226 // because it's orthogonal to what we are replacing and hence
2227 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002228 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2229 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2230 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2231 ExpectParseFailure("a=sendrecv", kSdpMd5);
2232
2233 // Empty Line
2234 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2235 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002236}
2237
2238TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2239 // ssrc
2240 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
2241 ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6");
2242 // crypto
2243 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2244 // rtpmap
2245 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2246 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2247 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2248 // candidate
2249 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2250 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2251 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2252 ExpectParseFailure("rport 2346", "rport badvalue");
2253 ExpectParseFailure("rport 2346 generation 2",
2254 "rport 2346 generation badvalue");
2255 // m line
2256 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2257 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2258
2259 // bandwidth
2260 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2261 "b=AS:badvalue\r\n",
2262 "b=AS:badvalue");
2263 // rtcp-fb
2264 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2265 "a=rtcp-fb:badvalue nack\r\n",
2266 "a=rtcp-fb:badvalue nack");
2267 // extmap
2268 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2269 "a=extmap:badvalue http://example.com\r\n",
2270 "a=extmap:badvalue http://example.com");
2271 // x-google-buffer-latency
2272 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2273 "a=x-google-buffer-latency:badvalue\r\n",
2274 "a=x-google-buffer-latency:badvalue");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275}
2276
2277TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2278 JsepSessionDescription jdesc_output(kDummyString);
2279
2280 const char kSdpWithReorderedPlTypesString[] =
2281 "v=0\r\n"
2282 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2283 "s=-\r\n"
2284 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002285 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2287 // in the map.
2288 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
2289 "a=rtpmap:104 CELT/32000/2\r\n";
2290
2291 // Deserialize
2292 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2293
2294 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2295 ASSERT_TRUE(ac != NULL);
2296 const AudioContentDescription* acd =
2297 static_cast<const AudioContentDescription*>(ac->description);
2298 ASSERT_FALSE(acd->codecs().empty());
2299 EXPECT_EQ("CELT", acd->codecs()[0].name);
2300 EXPECT_EQ(104, acd->codecs()[0].id);
2301}
2302
2303TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2304 JsepSessionDescription jdesc_output(kDummyString);
2305 CodecParams params;
2306 params.max_ptime = 40;
2307 params.ptime = 30;
2308 params.min_ptime = 10;
2309 params.sprop_stereo = 1;
2310 params.stereo = 1;
2311 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002312 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 TestDeserializeCodecParams(params, &jdesc_output);
2314 TestSerialize(jdesc_output);
2315}
2316
2317TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2318 const bool kUseWildcard = false;
2319 JsepSessionDescription jdesc_output(kDummyString);
2320 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2321 TestSerialize(jdesc_output);
2322}
2323
2324TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2325 const bool kUseWildcard = true;
2326 JsepSessionDescription jdesc_output(kDummyString);
2327 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
2328 TestSerialize(jdesc_output);
2329}
2330
2331TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2332 JsepSessionDescription jdesc_output(kDummyString);
2333
2334 const char kSdpWithFmtpString[] =
2335 "v=0\r\n"
2336 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2337 "s=-\r\n"
2338 "t=0 0\r\n"
2339 "m=video 3457 RTP/SAVPF 120\r\n"
2340 "a=rtpmap:120 VP8/90000\r\n"
2341 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
2342
2343 // Deserialize
2344 SdpParseError error;
2345 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2346 &error));
2347
2348 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2349 ASSERT_TRUE(vc != NULL);
2350 const VideoContentDescription* vcd =
2351 static_cast<const VideoContentDescription*>(vc->description);
2352 ASSERT_FALSE(vcd->codecs().empty());
2353 cricket::VideoCodec vp8 = vcd->codecs()[0];
2354 EXPECT_EQ("VP8", vp8.name);
2355 EXPECT_EQ(120, vp8.id);
2356 cricket::CodecParameterMap::iterator found =
2357 vp8.params.find("x-google-min-bitrate");
2358 ASSERT_TRUE(found != vp8.params.end());
2359 EXPECT_EQ(found->second, "10");
2360 found = vp8.params.find("x-google-max-quantization");
2361 ASSERT_TRUE(found != vp8.params.end());
2362 EXPECT_EQ(found->second, "40");
2363}
2364
2365TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2366 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2367 GetFirstVideoContent(&desc_)->description);
2368
2369 cricket::VideoCodecs codecs = vcd->codecs();
2370 codecs[0].params["x-google-min-bitrate"] = "10";
2371 vcd->set_codecs(codecs);
2372
2373 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2374 jdesc_.session_id(),
2375 jdesc_.session_version()));
2376 std::string message = webrtc::SdpSerialize(jdesc_);
2377 std::string sdp_with_fmtp = kSdpFullString;
2378 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2379 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2380 &sdp_with_fmtp);
2381 EXPECT_EQ(sdp_with_fmtp, message);
2382}
2383
2384TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2385 JsepSessionDescription jdesc_with_icelite(kDummyString);
2386 std::string sdp_with_icelite = kSdpFullString;
2387 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2388 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2389 const cricket::TransportInfo* tinfo1 =
2390 desc->GetTransportInfoByName("audio_content_name");
2391 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2392 const cricket::TransportInfo* tinfo2 =
2393 desc->GetTransportInfoByName("video_content_name");
2394 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2395 InjectAfter(kSessionTime,
2396 "a=ice-lite\r\n",
2397 &sdp_with_icelite);
2398 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2399 desc = jdesc_with_icelite.description();
2400 const cricket::TransportInfo* atinfo =
2401 desc->GetTransportInfoByName("audio_content_name");
2402 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2403 const cricket::TransportInfo* vtinfo =
2404 desc->GetTransportInfoByName("video_content_name");
2405 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2406}
2407
2408// Verifies that the candidates in the input SDP are parsed and serialized
2409// correctly in the output SDP.
2410TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2411 std::string sdp_with_data = kSdpString;
2412 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2413 JsepSessionDescription jdesc_output(kDummyString);
2414
2415 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2416 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
2417}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002418
2419TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2420 AddFingerprint();
2421 TransportInfo audio_transport_info =
2422 *(desc_.GetTransportInfoByName(kAudioContentName));
2423 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2424 audio_transport_info.description.connection_role);
2425 audio_transport_info.description.connection_role =
2426 cricket::CONNECTIONROLE_ACTIVE;
2427
2428 TransportInfo video_transport_info =
2429 *(desc_.GetTransportInfoByName(kVideoContentName));
2430 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2431 video_transport_info.description.connection_role);
2432 video_transport_info.description.connection_role =
2433 cricket::CONNECTIONROLE_ACTIVE;
2434
2435 desc_.RemoveTransportInfoByName(kAudioContentName);
2436 desc_.RemoveTransportInfoByName(kVideoContentName);
2437
2438 desc_.AddTransportInfo(audio_transport_info);
2439 desc_.AddTransportInfo(video_transport_info);
2440
2441 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2442 jdesc_.session_id(),
2443 jdesc_.session_version()));
2444 std::string message = webrtc::SdpSerialize(jdesc_);
2445 std::string sdp_with_dtlssetup = kSdpFullString;
2446
2447 // Fingerprint attribute is necessary to add DTLS setup attribute.
2448 InjectAfter(kAttributeIcePwdVoice,
2449 kFingerprint, &sdp_with_dtlssetup);
2450 InjectAfter(kAttributeIcePwdVideo,
2451 kFingerprint, &sdp_with_dtlssetup);
2452 // Now adding |setup| attribute.
2453 InjectAfter(kFingerprint,
2454 "a=setup:active\r\n", &sdp_with_dtlssetup);
2455 EXPECT_EQ(sdp_with_dtlssetup, message);
2456}
2457
2458TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
2459 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
2460 std::string sdp_with_dtlssetup = kSdpFullString;
2461 InjectAfter(kSessionTime,
2462 "a=setup:actpass\r\n",
2463 &sdp_with_dtlssetup);
2464 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
2465 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
2466 const cricket::TransportInfo* atinfo =
2467 desc->GetTransportInfoByName("audio_content_name");
2468 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2469 atinfo->description.connection_role);
2470 const cricket::TransportInfo* vtinfo =
2471 desc->GetTransportInfoByName("video_content_name");
2472 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
2473 vtinfo->description.connection_role);
2474}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00002475
2476// Verifies that the order of the serialized m-lines follows the order of the
2477// ContentInfo in SessionDescription, and vise versa for deserialization.
2478TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
2479 JsepSessionDescription jdesc(kDummyString);
2480 const std::string media_content_sdps[3] = {
2481 kSdpAudioString,
2482 kSdpVideoString,
2483 kSdpSctpDataChannelString
2484 };
2485 const cricket::MediaType media_types[3] = {
2486 cricket::MEDIA_TYPE_AUDIO,
2487 cricket::MEDIA_TYPE_VIDEO,
2488 cricket::MEDIA_TYPE_DATA
2489 };
2490
2491 // Verifies all 6 permutations.
2492 for (size_t i = 0; i < 6; ++i) {
2493 size_t media_content_in_sdp[3];
2494 // The index of the first media content.
2495 media_content_in_sdp[0] = i / 2;
2496 // The index of the second media content.
2497 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
2498 // The index of the third media content.
2499 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
2500
2501 std::string sdp_string = kSdpSessionString;
2502 for (size_t i = 0; i < 3; ++i)
2503 sdp_string += media_content_sdps[media_content_in_sdp[i]];
2504
2505 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
2506 cricket::SessionDescription* desc = jdesc.description();
2507 EXPECT_EQ(3u, desc->contents().size());
2508
2509 for (size_t i = 0; i < 3; ++i) {
2510 const cricket::MediaContentDescription* mdesc =
2511 static_cast<const cricket::MediaContentDescription*>(
2512 desc->contents()[i].description);
2513 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
2514 }
2515
2516 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
2517 EXPECT_EQ(sdp_string, serialized_sdp);
2518 }
2519}