blob: c52720453b7021042760dabc688efd5768dc94fd [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
11#include <set>
12#include <string>
13#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/jsepsessiondescription.h"
16#ifdef WEBRTC_ANDROID
17#include "webrtc/api/test/androidtestinitializer.h"
18#endif
19#include "webrtc/api/webrtcsdp.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/gunit.h"
21#include "webrtc/base/logging.h"
22#include "webrtc/base/messagedigest.h"
23#include "webrtc/base/scoped_ptr.h"
24#include "webrtc/base/sslfingerprint.h"
25#include "webrtc/base/stringencode.h"
26#include "webrtc/base/stringutils.h"
kjellanderf4752772016-03-02 05:42:30 -080027#include "webrtc/media/base/mediaconstants.h"
28#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010029#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31using cricket::AudioCodec;
32using cricket::AudioContentDescription;
33using cricket::Candidate;
34using cricket::ContentInfo;
35using cricket::CryptoParams;
36using cricket::ContentGroup;
37using cricket::DataCodec;
38using cricket::DataContentDescription;
39using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
40using cricket::ICE_CANDIDATE_COMPONENT_RTP;
41using cricket::kFecSsrcGroupSemantics;
42using cricket::LOCAL_PORT_TYPE;
43using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044using cricket::NS_JINGLE_RTP;
45using cricket::RtpHeaderExtension;
46using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
48using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
58using webrtc::SdpParseError;
59using webrtc::SessionDescriptionInterface;
60
61typedef std::vector<AudioCodec> AudioCodecs;
62typedef std::vector<Candidate> Candidates;
63
Peter Boström0c4e06b2015-10-07 12:23:21 +020064static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020066static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080067static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080069static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020071static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kCandidateFoundation1[] = "a0+B/1";
73static const char kCandidateFoundation2[] = "a0+B/2";
74static const char kCandidateFoundation3[] = "a0+B/3";
75static const char kCandidateFoundation4[] = "a0+B/4";
76static const char kAttributeCryptoVoice[] =
77 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
78 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
79 "dummy_session_params\r\n";
80static const char kAttributeCryptoVideo[] =
81 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
82 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
83static const char kFingerprint[] = "a=fingerprint:sha-1 "
84 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
85static const int kExtmapId = 1;
86static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
87static const char kExtmap[] =
88 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
89static const char kExtmapWithDirectionAndAttribute[] =
90 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
91
Peter Boström0c4e06b2015-10-07 12:23:21 +020092static const uint8_t kIdentityDigest[] = {
93 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
94 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
lally@webrtc.org34807282015-02-24 20:19:39 +000096static const char kDtlsSctp[] = "DTLS/SCTP";
97static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
98static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +000099
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100struct CodecParams {
101 int max_ptime;
102 int ptime;
103 int min_ptime;
104 int sprop_stereo;
105 int stereo;
106 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000107 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108};
109
deadbeef9d3584c2016-02-16 17:54:10 -0800110// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
111// instead of "a=crypto", and have an explicit test for adding "a=crypto".
112// Currently it's the other way around.
113
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114// Reference sdp string
115static const char kSdpFullString[] =
116 "v=0\r\n"
117 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
118 "s=-\r\n"
119 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800120 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
122 "c=IN IP4 74.125.127.126\r\n"
123 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
124 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
125 "generation 2\r\n"
126 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
127 "generation 2\r\n"
128 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
129 "generation 2\r\n"
130 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
133 "raddr 192.168.1.5 rport 2346 "
134 "generation 2\r\n"
135 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
136 "raddr 192.168.1.5 rport 2348 "
137 "generation 2\r\n"
138 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
139 "a=mid:audio_content_name\r\n"
140 "a=sendrecv\r\n"
141 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800142 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
144 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
145 "dummy_session_params\r\n"
146 "a=rtpmap:111 opus/48000/2\r\n"
147 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000148 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 "a=ssrc:1 cname:stream_1_cname\r\n"
150 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
151 "a=ssrc:1 mslabel:local_stream_1\r\n"
152 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 "m=video 3457 RTP/SAVPF 120\r\n"
154 "c=IN IP4 74.125.224.39\r\n"
155 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
156 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
157 "generation 2\r\n"
158 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
165 "generation 2\r\n"
166 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
167 "generation 2\r\n"
168 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
169 "a=mid:video_content_name\r\n"
170 "a=sendrecv\r\n"
171 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
172 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
173 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800174 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 "a=ssrc:2 cname:stream_1_cname\r\n"
176 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
177 "a=ssrc:2 mslabel:local_stream_1\r\n"
178 "a=ssrc:2 label:video_track_id_1\r\n"
179 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800180 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800182 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183
184// SDP reference string without the candidates.
185static const char kSdpString[] =
186 "v=0\r\n"
187 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
188 "s=-\r\n"
189 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800190 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000191 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000192 "c=IN IP4 0.0.0.0\r\n"
193 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
195 "a=mid:audio_content_name\r\n"
196 "a=sendrecv\r\n"
197 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800198 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
200 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
201 "dummy_session_params\r\n"
202 "a=rtpmap:111 opus/48000/2\r\n"
203 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000204 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=ssrc:1 cname:stream_1_cname\r\n"
206 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
207 "a=ssrc:1 mslabel:local_stream_1\r\n"
208 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000209 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000210 "c=IN IP4 0.0.0.0\r\n"
211 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
213 "a=mid:video_content_name\r\n"
214 "a=sendrecv\r\n"
215 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
216 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
217 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800218 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 "a=ssrc:2 cname:stream_1_cname\r\n"
220 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
221 "a=ssrc:2 mslabel:local_stream_1\r\n"
222 "a=ssrc:2 label:video_track_id_1\r\n"
223 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800224 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800226 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227
228static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000229 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000230 "c=IN IP4 0.0.0.0\r\n"
231 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=ice-ufrag:ufrag_data\r\n"
233 "a=ice-pwd:pwd_data\r\n"
234 "a=mid:data_content_name\r\n"
235 "a=sendrecv\r\n"
236 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
237 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
238 "a=rtpmap:101 google-data/90000\r\n"
239 "a=ssrc:10 cname:data_channel_cname\r\n"
240 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
241 "a=ssrc:10 mslabel:data_channel\r\n"
242 "a=ssrc:10 label:data_channeld0\r\n";
243
244static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000245 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000246 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 "a=ice-ufrag:ufrag_data\r\n"
248 "a=ice-pwd:pwd_data\r\n"
249 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000252// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000253static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000254 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
255 "a=max-message-size=100000\r\n"
256 "a=sctp-port 5000\r\n"
257 "c=IN IP4 0.0.0.0\r\n"
258 "a=ice-ufrag:ufrag_data\r\n"
259 "a=ice-pwd:pwd_data\r\n"
260 "a=mid:data_content_name\r\n";
261
lally69f57602015-10-08 10:15:04 -0700262static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port:5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271static const char kSdpSctpDataChannelWithCandidatesString[] =
272 "m=application 2345 DTLS/SCTP 5000\r\n"
273 "c=IN IP4 74.125.127.126\r\n"
274 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
275 "generation 2\r\n"
276 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
277 "generation 2\r\n"
278 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
279 "raddr 192.168.1.5 rport 2346 "
280 "generation 2\r\n"
281 "a=ice-ufrag:ufrag_data\r\n"
282 "a=ice-pwd:pwd_data\r\n"
283 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000284 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000286static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000287 "v=0\r\n"
288 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
289 "s=-\r\n"
290 "t=0 0\r\n"
291 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000292 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000293 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000294 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000295 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000296 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000297 "a=x-google-flag:conference\r\n";
298
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000299static const char kSdpSessionString[] =
300 "v=0\r\n"
301 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
302 "s=-\r\n"
303 "t=0 0\r\n"
304 "a=msid-semantic: WMS local_stream\r\n";
305
306static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000307 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000308 "c=IN IP4 0.0.0.0\r\n"
309 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000310 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
311 "a=mid:audio_content_name\r\n"
312 "a=sendrecv\r\n"
313 "a=rtpmap:111 opus/48000/2\r\n"
314 "a=ssrc:1 cname:stream_1_cname\r\n"
315 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
316 "a=ssrc:1 mslabel:local_stream\r\n"
317 "a=ssrc:1 label:audio_track_id_1\r\n";
318
319static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000320 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000321 "c=IN IP4 0.0.0.0\r\n"
322 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000323 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
324 "a=mid:video_content_name\r\n"
325 "a=sendrecv\r\n"
326 "a=rtpmap:120 VP8/90000\r\n"
327 "a=ssrc:2 cname:stream_1_cname\r\n"
328 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
329 "a=ssrc:2 mslabel:local_stream\r\n"
330 "a=ssrc:2 label:video_track_id_1\r\n";
331
deadbeef9d3584c2016-02-16 17:54:10 -0800332// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
333// tracks.
334static const char kPlanBSdpFullString[] =
335 "v=0\r\n"
336 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
337 "s=-\r\n"
338 "t=0 0\r\n"
339 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
340 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
341 "c=IN IP4 74.125.127.126\r\n"
342 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
343 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
344 "generation 2\r\n"
345 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
346 "generation 2\r\n"
347 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
348 "generation 2\r\n"
349 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
352 "raddr 192.168.1.5 rport 2346 "
353 "generation 2\r\n"
354 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
355 "raddr 192.168.1.5 rport 2348 "
356 "generation 2\r\n"
357 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
358 "a=mid:audio_content_name\r\n"
359 "a=sendrecv\r\n"
360 "a=rtcp-mux\r\n"
361 "a=rtcp-rsize\r\n"
362 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
363 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
364 "dummy_session_params\r\n"
365 "a=rtpmap:111 opus/48000/2\r\n"
366 "a=rtpmap:103 ISAC/16000\r\n"
367 "a=rtpmap:104 ISAC/32000\r\n"
368 "a=ssrc:1 cname:stream_1_cname\r\n"
369 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
370 "a=ssrc:1 mslabel:local_stream_1\r\n"
371 "a=ssrc:1 label:audio_track_id_1\r\n"
372 "a=ssrc:4 cname:stream_2_cname\r\n"
373 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
374 "a=ssrc:4 mslabel:local_stream_2\r\n"
375 "a=ssrc:4 label:audio_track_id_2\r\n"
376 "m=video 3457 RTP/SAVPF 120\r\n"
377 "c=IN IP4 74.125.224.39\r\n"
378 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
379 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
380 "generation 2\r\n"
381 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
388 "generation 2\r\n"
389 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
390 "generation 2\r\n"
391 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
392 "a=mid:video_content_name\r\n"
393 "a=sendrecv\r\n"
394 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
395 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
396 "a=rtpmap:120 VP8/90000\r\n"
397 "a=ssrc-group:FEC 2 3\r\n"
398 "a=ssrc:2 cname:stream_1_cname\r\n"
399 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
400 "a=ssrc:2 mslabel:local_stream_1\r\n"
401 "a=ssrc:2 label:video_track_id_1\r\n"
402 "a=ssrc:3 cname:stream_1_cname\r\n"
403 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
404 "a=ssrc:3 mslabel:local_stream_1\r\n"
405 "a=ssrc:3 label:video_track_id_1\r\n"
406 "a=ssrc:5 cname:stream_2_cname\r\n"
407 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
408 "a=ssrc:5 mslabel:local_stream_2\r\n"
409 "a=ssrc:5 label:video_track_id_2\r\n"
410 "a=ssrc:6 cname:stream_2_cname\r\n"
411 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
412 "a=ssrc:6 mslabel:local_stream_2\r\n"
413 "a=ssrc:6 label:video_track_id_3\r\n";
414
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800415// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
416// tracks, but with the unified plan "a=msid" attribute.
417static const char kPlanBSdpFullStringWithMsid[] =
418 "v=0\r\n"
419 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
420 "s=-\r\n"
421 "t=0 0\r\n"
422 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
423 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
424 "c=IN IP4 74.125.127.126\r\n"
425 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
426 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
427 "generation 2\r\n"
428 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
435 "raddr 192.168.1.5 rport 2346 "
436 "generation 2\r\n"
437 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
438 "raddr 192.168.1.5 rport 2348 "
439 "generation 2\r\n"
440 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
441 "a=mid:audio_content_name\r\n"
442 "a=msid:local_stream_1 audio_track_id_1\r\n"
443 "a=sendrecv\r\n"
444 "a=rtcp-mux\r\n"
445 "a=rtcp-rsize\r\n"
446 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
447 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
448 "dummy_session_params\r\n"
449 "a=rtpmap:111 opus/48000/2\r\n"
450 "a=rtpmap:103 ISAC/16000\r\n"
451 "a=rtpmap:104 ISAC/32000\r\n"
452 "a=ssrc:1 cname:stream_1_cname\r\n"
453 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
454 "a=ssrc:1 mslabel:local_stream_1\r\n"
455 "a=ssrc:1 label:audio_track_id_1\r\n"
456 "a=ssrc:4 cname:stream_2_cname\r\n"
457 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
458 "a=ssrc:4 mslabel:local_stream_2\r\n"
459 "a=ssrc:4 label:audio_track_id_2\r\n"
460 "m=video 3457 RTP/SAVPF 120\r\n"
461 "c=IN IP4 74.125.224.39\r\n"
462 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
463 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
464 "generation 2\r\n"
465 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
466 "generation 2\r\n"
467 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
468 "generation 2\r\n"
469 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
470 "generation 2\r\n"
471 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
472 "generation 2\r\n"
473 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
474 "generation 2\r\n"
475 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
476 "a=mid:video_content_name\r\n"
477 "a=msid:local_stream_1 video_track_id_1\r\n"
478 "a=sendrecv\r\n"
479 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
480 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
481 "a=rtpmap:120 VP8/90000\r\n"
482 "a=ssrc-group:FEC 2 3\r\n"
483 "a=ssrc:2 cname:stream_1_cname\r\n"
484 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
485 "a=ssrc:2 mslabel:local_stream_1\r\n"
486 "a=ssrc:2 label:video_track_id_1\r\n"
487 "a=ssrc:3 cname:stream_1_cname\r\n"
488 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
489 "a=ssrc:3 mslabel:local_stream_1\r\n"
490 "a=ssrc:3 label:video_track_id_1\r\n"
491 "a=ssrc:5 cname:stream_2_cname\r\n"
492 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
493 "a=ssrc:5 mslabel:local_stream_2\r\n"
494 "a=ssrc:5 label:video_track_id_2\r\n"
495 "a=ssrc:6 cname:stream_2_cname\r\n"
496 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
497 "a=ssrc:6 mslabel:local_stream_2\r\n"
498 "a=ssrc:6 label:video_track_id_3\r\n";
499
deadbeef9d3584c2016-02-16 17:54:10 -0800500// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
501// tracks.
502static const char kUnifiedPlanSdpFullString[] =
503 "v=0\r\n"
504 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
505 "s=-\r\n"
506 "t=0 0\r\n"
507 "a=msid-semantic: WMS local_stream_1\r\n"
508 // Audio track 1, stream 1 (with candidates).
509 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
510 "c=IN IP4 74.125.127.126\r\n"
511 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
512 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
513 "generation 2\r\n"
514 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
515 "generation 2\r\n"
516 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
521 "raddr 192.168.1.5 rport 2346 "
522 "generation 2\r\n"
523 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
524 "raddr 192.168.1.5 rport 2348 "
525 "generation 2\r\n"
526 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
527 "a=mid:audio_content_name\r\n"
528 "a=msid:local_stream_1 audio_track_id_1\r\n"
529 "a=sendrecv\r\n"
530 "a=rtcp-mux\r\n"
531 "a=rtcp-rsize\r\n"
532 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
533 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
534 "dummy_session_params\r\n"
535 "a=rtpmap:111 opus/48000/2\r\n"
536 "a=rtpmap:103 ISAC/16000\r\n"
537 "a=rtpmap:104 ISAC/32000\r\n"
538 "a=ssrc:1 cname:stream_1_cname\r\n"
539 // Video track 1, stream 1 (with candidates).
540 "m=video 3457 RTP/SAVPF 120\r\n"
541 "c=IN IP4 74.125.224.39\r\n"
542 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
543 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
544 "generation 2\r\n"
545 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
546 "generation 2\r\n"
547 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
552 "generation 2\r\n"
553 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
554 "generation 2\r\n"
555 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
556 "a=mid:video_content_name\r\n"
557 "a=msid:local_stream_1 video_track_id_1\r\n"
558 "a=sendrecv\r\n"
559 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
560 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
561 "a=rtpmap:120 VP8/90000\r\n"
562 "a=ssrc-group:FEC 2 3\r\n"
563 "a=ssrc:2 cname:stream_1_cname\r\n"
564 "a=ssrc:3 cname:stream_1_cname\r\n"
565 // Audio track 2, stream 2.
566 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
567 "c=IN IP4 0.0.0.0\r\n"
568 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
569 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
570 "a=mid:audio_content_name_2\r\n"
571 "a=msid:local_stream_2 audio_track_id_2\r\n"
572 "a=sendrecv\r\n"
573 "a=rtcp-mux\r\n"
574 "a=rtcp-rsize\r\n"
575 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
576 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
577 "dummy_session_params\r\n"
578 "a=rtpmap:111 opus/48000/2\r\n"
579 "a=rtpmap:103 ISAC/16000\r\n"
580 "a=rtpmap:104 ISAC/32000\r\n"
581 "a=ssrc:4 cname:stream_2_cname\r\n"
582 // Video track 2, stream 2.
583 "m=video 9 RTP/SAVPF 120\r\n"
584 "c=IN IP4 0.0.0.0\r\n"
585 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
586 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
587 "a=mid:video_content_name_2\r\n"
588 "a=msid:local_stream_2 video_track_id_2\r\n"
589 "a=sendrecv\r\n"
590 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
591 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
592 "a=rtpmap:120 VP8/90000\r\n"
593 "a=ssrc:5 cname:stream_2_cname\r\n"
594 // Video track 3, stream 2.
595 "m=video 9 RTP/SAVPF 120\r\n"
596 "c=IN IP4 0.0.0.0\r\n"
597 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
598 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
599 "a=mid:video_content_name_3\r\n"
600 "a=msid:local_stream_2 video_track_id_3\r\n"
601 "a=sendrecv\r\n"
602 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
603 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
604 "a=rtpmap:120 VP8/90000\r\n"
605 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
607// One candidate reference string as per W3c spec.
608// candidate:<blah> not a=candidate:<blah>CRLF
609static const char kRawCandidate[] =
610 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
611// One candidate reference string.
612static const char kSdpOneCandidate[] =
613 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
614 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000615
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000616static const char kSdpTcpActiveCandidate[] =
617 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
618 "tcptype active generation 2";
619static const char kSdpTcpPassiveCandidate[] =
620 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
621 "tcptype passive generation 2";
622static const char kSdpTcpSOCandidate[] =
623 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
624 "tcptype so generation 2";
625static const char kSdpTcpInvalidCandidate[] =
626 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
627 "tcptype invalid generation 2";
628
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000629// One candidate reference string with IPV6 address.
630static const char kRawIPV6Candidate[] =
631 "candidate:a0+B/1 1 udp 2130706432 "
632 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800635static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800637 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638
639// Session id and version
640static const char kSessionId[] = "18446744069414584320";
641static const char kSessionVersion[] = "18446462598732840960";
642
deadbeef9d3584c2016-02-16 17:54:10 -0800643// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644static const char kIceOption1[] = "iceoption1";
645static const char kIceOption2[] = "iceoption2";
646static const char kIceOption3[] = "iceoption3";
647
deadbeef9d3584c2016-02-16 17:54:10 -0800648// ICE ufrags/passwords.
649static const char kUfragVoice[] = "ufrag_voice";
650static const char kPwdVoice[] = "pwd_voice";
651static const char kUfragVideo[] = "ufrag_video";
652static const char kPwdVideo[] = "pwd_video";
653static const char kUfragData[] = "ufrag_data";
654static const char kPwdData[] = "pwd_data";
655
656// Extra ufrags/passwords for extra unified plan m= sections.
657static const char kUfragVoice2[] = "ufrag_voice_2";
658static const char kPwdVoice2[] = "pwd_voice_2";
659static const char kUfragVideo2[] = "ufrag_video_2";
660static const char kPwdVideo2[] = "pwd_video_2";
661static const char kUfragVideo3[] = "ufrag_video_3";
662static const char kPwdVideo3[] = "pwd_video_3";
663
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664// Content name
665static const char kAudioContentName[] = "audio_content_name";
666static const char kVideoContentName[] = "video_content_name";
667static const char kDataContentName[] = "data_content_name";
668
deadbeef9d3584c2016-02-16 17:54:10 -0800669// Extra content names for extra unified plan m= sections.
670static const char kAudioContentName2[] = "audio_content_name_2";
671static const char kVideoContentName2[] = "video_content_name_2";
672static const char kVideoContentName3[] = "video_content_name_3";
673
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674// MediaStream 1
675static const char kStreamLabel1[] = "local_stream_1";
676static const char kStream1Cname[] = "stream_1_cname";
677static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200678static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800680static const uint32_t kVideoTrack1Ssrc1 = 2;
681static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682
683// MediaStream 2
684static const char kStreamLabel2[] = "local_stream_2";
685static const char kStream2Cname[] = "stream_2_cname";
686static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200687static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800688static const char kVideoTrackId2[] = "video_track_id_2";
689static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800691static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692
693// DataChannel
694static const char kDataChannelLabel[] = "data_channel";
695static const char kDataChannelMsid[] = "data_channeld0";
696static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200697static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698
699// Candidate
700static const char kDummyMid[] = "dummy_mid";
701static const int kDummyIndex = 123;
702
703// Misc
704static const char kDummyString[] = "dummy";
705
706// Helper functions
707
708static bool SdpDeserialize(const std::string& message,
709 JsepSessionDescription* jdesc) {
710 return webrtc::SdpDeserialize(message, jdesc, NULL);
711}
712
713static bool SdpDeserializeCandidate(const std::string& message,
714 JsepIceCandidate* candidate) {
715 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
716}
717
718// Add some extra |newlines| to the |message| after |line|.
719static void InjectAfter(const std::string& line,
720 const std::string& newlines,
721 std::string* message) {
722 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000723 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 tmp.c_str(), tmp.length(), message);
725}
726
727static void Replace(const std::string& line,
728 const std::string& newlines,
729 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000730 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 newlines.c_str(), newlines.length(), message);
732}
733
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000734// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
735// message.
736static void ExpectParseFailure(const std::string& bad_sdp,
737 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000740 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000742 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
743}
744
745// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
746static void ExpectParseFailure(const char* good_part, const char* bad_part) {
747 std::string bad_sdp = kSdpFullString;
748 Replace(good_part, bad_part, &bad_sdp);
749 ExpectParseFailure(bad_sdp, bad_part);
750}
751
752// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
753static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
754 const std::string& newlines,
755 const std::string& bad_part) {
756 std::string bad_sdp = kSdpFullString;
757 InjectAfter(injectpoint, newlines, &bad_sdp);
758 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759}
760
761static void ReplaceDirection(cricket::MediaContentDirection direction,
762 std::string* message) {
763 std::string new_direction;
764 switch (direction) {
765 case cricket::MD_INACTIVE:
766 new_direction = "a=inactive";
767 break;
768 case cricket::MD_SENDONLY:
769 new_direction = "a=sendonly";
770 break;
771 case cricket::MD_RECVONLY:
772 new_direction = "a=recvonly";
773 break;
774 case cricket::MD_SENDRECV:
775 default:
776 new_direction = "a=sendrecv";
777 break;
778 }
779 Replace("a=sendrecv", new_direction, message);
780}
781
782static void ReplaceRejected(bool audio_rejected, bool video_rejected,
783 std::string* message) {
784 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800785 Replace("m=audio 9", "m=audio 0", message);
786 Replace(kAttributeIceUfragVoice, "", message);
787 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
789 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800790 Replace("m=video 9", "m=video 0", message);
791 Replace(kAttributeIceUfragVideo, "", message);
792 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 }
794}
795
796// WebRtcSdpTest
797
798class WebRtcSdpTest : public testing::Test {
799 public:
800 WebRtcSdpTest()
801 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800802#ifdef WEBRTC_ANDROID
803 webrtc::InitializeAndroidObjects();
804#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 // AudioContentDescription
806 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800807 StreamParams audio_stream;
808 audio_stream.id = kAudioTrackId1;
809 audio_stream.cname = kStream1Cname;
810 audio_stream.sync_label = kStreamLabel1;
811 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
812 audio_desc_->AddStream(audio_stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
814
815 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800816 video_desc_ = CreateVideoContentDescription();
817 StreamParams video_stream;
818 video_stream.id = kVideoTrackId1;
819 video_stream.cname = kStream1Cname;
820 video_stream.sync_label = kStreamLabel1;
821 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
822 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
823 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
824 video_stream.ssrc_groups.push_back(ssrc_group);
825 video_desc_->AddStream(video_stream);
826 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827
828 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800829 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
830 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
831 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
832 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833
834 // v4 host
835 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000836 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000837 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000838 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
839 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000841 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000842 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
843 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000845 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000846 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
847 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000849 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000850 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
851 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852
853 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000854 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000855 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
856 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000857 cricket::LOCAL_PORT_TYPE,
858 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000860 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
861 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000862 cricket::LOCAL_PORT_TYPE,
863 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000865 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
866 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000867 cricket::LOCAL_PORT_TYPE,
868 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000870 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
871 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000872 cricket::LOCAL_PORT_TYPE,
873 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874
875 // stun
876 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000877 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
878 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000879 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
880 address_stun, kCandidatePriority, "", "",
881 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000882 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 candidate9.set_related_address(rel_address_stun);
884
885 address_stun.SetPort(port_stun++);
886 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000887 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
888 address_stun, kCandidatePriority, "", "",
889 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000890 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 candidate10.set_related_address(rel_address_stun);
892
893 // relay
894 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000895 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000896 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
897 address_relay, kCandidatePriority, "", "",
898 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000899 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000901 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
902 address_relay, kCandidatePriority, "", "",
903 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000904 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905
906 // voice
907 candidates_.push_back(candidate1);
908 candidates_.push_back(candidate2);
909 candidates_.push_back(candidate5);
910 candidates_.push_back(candidate6);
911 candidates_.push_back(candidate9);
912 candidates_.push_back(candidate10);
913
914 // video
915 candidates_.push_back(candidate3);
916 candidates_.push_back(candidate4);
917 candidates_.push_back(candidate7);
918 candidates_.push_back(candidate8);
919 candidates_.push_back(candidate11);
920 candidates_.push_back(candidate12);
921
922 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
923 0, candidate1));
924
925 // Set up JsepSessionDescription.
926 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
927 std::string mline_id;
928 int mline_index = 0;
929 for (size_t i = 0; i< candidates_.size(); ++i) {
930 // In this test, the audio m line index will be 0, and the video m line
931 // will be 1.
932 bool is_video = (i > 5);
933 mline_id = is_video ? "video_content_name" : "audio_content_name";
934 mline_index = is_video ? 1 : 0;
935 JsepIceCandidate jice(mline_id,
936 mline_index,
937 candidates_.at(i));
938 jdesc_.AddCandidate(&jice);
939 }
940 }
941
deadbeef9d3584c2016-02-16 17:54:10 -0800942 // Turns the existing reference description into a plan B description,
943 // with 2 audio tracks and 3 video tracks.
944 void MakePlanBDescription() {
945 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
946 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
947
948 StreamParams audio_track_2;
949 audio_track_2.id = kAudioTrackId2;
950 audio_track_2.cname = kStream2Cname;
951 audio_track_2.sync_label = kStreamLabel2;
952 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
953 audio_desc_->AddStream(audio_track_2);
954
955 StreamParams video_track_2;
956 video_track_2.id = kVideoTrackId2;
957 video_track_2.cname = kStream2Cname;
958 video_track_2.sync_label = kStreamLabel2;
959 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
960 video_desc_->AddStream(video_track_2);
961
962 StreamParams video_track_3;
963 video_track_3.id = kVideoTrackId3;
964 video_track_3.cname = kStream2Cname;
965 video_track_3.sync_label = kStreamLabel2;
966 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
967 video_desc_->AddStream(video_track_3);
968
969 desc_.RemoveContentByName(kAudioContentName);
970 desc_.RemoveContentByName(kVideoContentName);
971 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
972 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
973
974 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
975 jdesc_.session_version()));
976 }
977
978 // Turns the existing reference description into a unified plan description,
979 // with 2 audio tracks and 3 video tracks.
980 void MakeUnifiedPlanDescription() {
981 // Audio track 2.
982 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
983 StreamParams audio_track_2;
984 audio_track_2.id = kAudioTrackId2;
985 audio_track_2.cname = kStream2Cname;
986 audio_track_2.sync_label = kStreamLabel2;
987 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
988 audio_desc_2->AddStream(audio_track_2);
989 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
990 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
991 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
992
993 // Video track 2, in stream 2.
994 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
995 StreamParams video_track_2;
996 video_track_2.id = kVideoTrackId2;
997 video_track_2.cname = kStream2Cname;
998 video_track_2.sync_label = kStreamLabel2;
999 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1000 video_desc_2->AddStream(video_track_2);
1001 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1002 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1003 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1004
1005 // Video track 3, in stream 2.
1006 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1007 StreamParams video_track_3;
1008 video_track_3.id = kVideoTrackId3;
1009 video_track_3.cname = kStream2Cname;
1010 video_track_3.sync_label = kStreamLabel2;
1011 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1012 video_desc_3->AddStream(video_track_3);
1013 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1014 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1015 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1016
1017 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1018 jdesc_.session_version()));
1019 }
1020
1021 // Creates an audio content description with no streams, and some default
1022 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 AudioContentDescription* CreateAudioContentDescription() {
1024 AudioContentDescription* audio = new AudioContentDescription();
1025 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001026 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1028 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1029 "dummy_session_params"));
1030 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef9d3584c2016-02-16 17:54:10 -08001031 AudioCodec opus(111, "opus", 48000, 0, 2, 3);
1032 audio->AddCodec(opus);
1033 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2));
1034 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 return audio;
1036 }
1037
deadbeef9d3584c2016-02-16 17:54:10 -08001038 // Creates a video content description with no streams, and some default
1039 // configuration.
1040 VideoContentDescription* CreateVideoContentDescription() {
1041 VideoContentDescription* video = new VideoContentDescription();
1042 video->AddCrypto(CryptoParams(
1043 1, "AES_CM_128_HMAC_SHA1_80",
1044 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1045 video->set_protocol(cricket::kMediaProtocolSavpf);
1046 video->AddCodec(
1047 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName,
1048 JsepSessionDescription::kMaxVideoCodecWidth,
1049 JsepSessionDescription::kMaxVideoCodecHeight,
1050 JsepSessionDescription::kDefaultVideoCodecFramerate,
1051 JsepSessionDescription::kDefaultVideoCodecPreference));
1052 return video;
1053 }
1054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 template <class MCD>
1056 void CompareMediaContentDescription(const MCD* cd1,
1057 const MCD* cd2) {
1058 // type
1059 EXPECT_EQ(cd1->type(), cd1->type());
1060
1061 // content direction
1062 EXPECT_EQ(cd1->direction(), cd2->direction());
1063
1064 // rtcp_mux
1065 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1066
deadbeef13871492015-12-09 12:37:51 -08001067 // rtcp_reduced_size
1068 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1069
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 // cryptos
1071 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1072 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1073 ADD_FAILURE();
1074 return;
1075 }
1076 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1077 const CryptoParams c1 = cd1->cryptos().at(i);
1078 const CryptoParams c2 = cd2->cryptos().at(i);
1079 EXPECT_TRUE(c1.Matches(c2));
1080 EXPECT_EQ(c1.key_params, c2.key_params);
1081 EXPECT_EQ(c1.session_params, c2.session_params);
1082 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001085 // Use an equivalence class here, for old and new versions of the
1086 // protocol description.
1087 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001088 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1089 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1090 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001091 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001092 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1093 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1094 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001095 } else {
1096 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1097 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098
1099 // codecs
1100 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1101
1102 // bandwidth
1103 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1104
1105 // streams
1106 EXPECT_EQ(cd1->streams(), cd2->streams());
1107
1108 // extmap
1109 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1110 cd2->rtp_header_extensions().size());
1111 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1112 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
1113 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
1114 EXPECT_EQ(ext1.uri, ext2.uri);
1115 EXPECT_EQ(ext1.id, ext2.id);
1116 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 }
1118
1119
1120 void CompareSessionDescription(const SessionDescription& desc1,
1121 const SessionDescription& desc2) {
1122 // Compare content descriptions.
1123 if (desc1.contents().size() != desc2.contents().size()) {
1124 ADD_FAILURE();
1125 return;
1126 }
1127 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1128 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1129 const cricket::ContentInfo& c2 = desc2.contents().at(i);
1130 // content name
1131 EXPECT_EQ(c1.name, c2.name);
1132 // content type
1133 // Note, ASSERT will return from the function, but will not stop the test.
1134 ASSERT_EQ(c1.type, c2.type);
1135
1136 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1137 if (IsAudioContent(&c1)) {
1138 const AudioContentDescription* acd1 =
1139 static_cast<const AudioContentDescription*>(c1.description);
1140 const AudioContentDescription* acd2 =
1141 static_cast<const AudioContentDescription*>(c2.description);
1142 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1143 }
1144
1145 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1146 if (IsVideoContent(&c1)) {
1147 const VideoContentDescription* vcd1 =
1148 static_cast<const VideoContentDescription*>(c1.description);
1149 const VideoContentDescription* vcd2 =
1150 static_cast<const VideoContentDescription*>(c2.description);
1151 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1152 }
1153
1154 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1155 if (IsDataContent(&c1)) {
1156 const DataContentDescription* dcd1 =
1157 static_cast<const DataContentDescription*>(c1.description);
1158 const DataContentDescription* dcd2 =
1159 static_cast<const DataContentDescription*>(c2.description);
1160 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1161 }
1162 }
1163
1164 // group
1165 const cricket::ContentGroups groups1 = desc1.groups();
1166 const cricket::ContentGroups groups2 = desc2.groups();
1167 EXPECT_EQ(groups1.size(), groups1.size());
1168 if (groups1.size() != groups2.size()) {
1169 ADD_FAILURE();
1170 return;
1171 }
1172 for (size_t i = 0; i < groups1.size(); ++i) {
1173 const cricket::ContentGroup group1 = groups1.at(i);
1174 const cricket::ContentGroup group2 = groups2.at(i);
1175 EXPECT_EQ(group1.semantics(), group2.semantics());
1176 const cricket::ContentNames names1 = group1.content_names();
1177 const cricket::ContentNames names2 = group2.content_names();
1178 EXPECT_EQ(names1.size(), names2.size());
1179 if (names1.size() != names2.size()) {
1180 ADD_FAILURE();
1181 return;
1182 }
1183 cricket::ContentNames::const_iterator iter1 = names1.begin();
1184 cricket::ContentNames::const_iterator iter2 = names2.begin();
1185 while (iter1 != names1.end()) {
1186 EXPECT_EQ(*iter1++, *iter2++);
1187 }
1188 }
1189
1190 // transport info
1191 const cricket::TransportInfos transports1 = desc1.transport_infos();
1192 const cricket::TransportInfos transports2 = desc2.transport_infos();
1193 EXPECT_EQ(transports1.size(), transports2.size());
1194 if (transports1.size() != transports2.size()) {
1195 ADD_FAILURE();
1196 return;
1197 }
1198 for (size_t i = 0; i < transports1.size(); ++i) {
1199 const cricket::TransportInfo transport1 = transports1.at(i);
1200 const cricket::TransportInfo transport2 = transports2.at(i);
1201 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001202 EXPECT_EQ(transport1.description.ice_ufrag,
1203 transport2.description.ice_ufrag);
1204 EXPECT_EQ(transport1.description.ice_pwd,
1205 transport2.description.ice_pwd);
1206 if (transport1.description.identity_fingerprint) {
1207 EXPECT_EQ(*transport1.description.identity_fingerprint,
1208 *transport2.description.identity_fingerprint);
1209 } else {
1210 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1211 transport2.description.identity_fingerprint.get());
1212 }
1213 EXPECT_EQ(transport1.description.transport_options,
1214 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215 }
deadbeefc80741f2015-10-22 13:14:45 -07001216
1217 // global attributes
1218 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 }
1220
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 bool CompareSessionDescription(
1222 const JsepSessionDescription& desc1,
1223 const JsepSessionDescription& desc2) {
1224 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1225 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1226 CompareSessionDescription(*desc1.description(), *desc2.description());
1227 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1228 return false;
1229 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1230 const IceCandidateCollection* cc1 = desc1.candidates(i);
1231 const IceCandidateCollection* cc2 = desc2.candidates(i);
1232 if (cc1->count() != cc2->count())
1233 return false;
1234 for (size_t j = 0; j < cc1->count(); ++j) {
1235 const IceCandidateInterface* c1 = cc1->at(j);
1236 const IceCandidateInterface* c2 = cc2->at(j);
1237 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1238 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1239 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1240 }
1241 }
1242 return true;
1243 }
1244
1245 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1246 // them with invalid keywords so that the parser will just ignore them.
1247 bool RemoveCandidateUfragPwd(std::string* sdp) {
1248 const char ice_ufrag[] = "a=ice-ufrag";
1249 const char ice_ufragx[] = "a=xice-ufrag";
1250 const char ice_pwd[] = "a=ice-pwd";
1251 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001254 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 ice_pwdx, strlen(ice_pwdx), sdp);
1256 return true;
1257 }
1258
1259 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1260 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1261 const std::string& ufrag, const std::string& pwd) {
1262 std::string content_name;
1263 if (mline_index == 0) {
1264 content_name = kAudioContentName;
1265 } else if (mline_index == 1) {
1266 content_name = kVideoContentName;
1267 } else {
1268 ASSERT(false);
1269 }
1270 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001271 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 SessionDescription* desc =
1273 const_cast<SessionDescription*>(jdesc->description());
1274 desc->RemoveTransportInfoByName(content_name);
1275 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1276 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1277 const IceCandidateCollection* cc = jdesc_.candidates(i);
1278 for (size_t j = 0; j < cc->count(); ++j) {
1279 if (cc->at(j)->sdp_mline_index() == mline_index) {
1280 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1281 ufrag);
1282 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1283 pwd);
1284 }
1285 }
1286 }
1287 return true;
1288 }
1289
1290 void AddIceOptions(const std::string& content_name,
1291 const std::vector<std::string>& transport_options) {
1292 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1293 cricket::TransportInfo transport_info =
1294 *(desc_.GetTransportInfoByName(content_name));
1295 desc_.RemoveTransportInfoByName(content_name);
1296 transport_info.description.transport_options = transport_options;
1297 desc_.AddTransportInfo(transport_info);
1298 }
1299
deadbeef3f7219b2015-12-28 15:17:14 -08001300 void SetIceUfragPwd(const std::string& content_name,
1301 const std::string& ice_ufrag,
1302 const std::string& ice_pwd) {
1303 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1304 cricket::TransportInfo transport_info =
1305 *(desc_.GetTransportInfoByName(content_name));
1306 desc_.RemoveTransportInfoByName(content_name);
1307 transport_info.description.ice_ufrag = ice_ufrag;
1308 transport_info.description.ice_pwd = ice_pwd;
1309 desc_.AddTransportInfo(transport_info);
1310 }
1311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 void AddFingerprint() {
1313 desc_.RemoveTransportInfoByName(kAudioContentName);
1314 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001315 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 kIdentityDigest,
1317 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001318 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1319 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001320 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1321 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001322 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1323 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1324 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001325 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1326 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001327 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 }
1329
1330 void AddExtmap() {
1331 audio_desc_ = static_cast<AudioContentDescription*>(
1332 audio_desc_->Copy());
1333 video_desc_ = static_cast<VideoContentDescription*>(
1334 video_desc_->Copy());
1335 audio_desc_->AddRtpHeaderExtension(
1336 RtpHeaderExtension(kExtmapUri, kExtmapId));
1337 video_desc_->AddRtpHeaderExtension(
1338 RtpHeaderExtension(kExtmapUri, kExtmapId));
1339 desc_.RemoveContentByName(kAudioContentName);
1340 desc_.RemoveContentByName(kVideoContentName);
1341 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1342 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1343 }
1344
1345 void RemoveCryptos() {
1346 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1347 video_desc_->set_cryptos(std::vector<CryptoParams>());
1348 }
1349
1350 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1351 audio_desc_->set_direction(direction);
1352 video_desc_->set_direction(direction);
1353 std::string new_sdp = kSdpFullString;
1354 ReplaceDirection(direction, &new_sdp);
1355
1356 if (!jdesc_.Initialize(desc_.Copy(),
1357 jdesc_.session_id(),
1358 jdesc_.session_version())) {
1359 return false;
1360 }
deadbeef9d3584c2016-02-16 17:54:10 -08001361 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 EXPECT_EQ(new_sdp, message);
1363 return true;
1364 }
1365
1366 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1367 audio_desc_ = static_cast<AudioContentDescription*>(
1368 audio_desc_->Copy());
1369 video_desc_ = static_cast<VideoContentDescription*>(
1370 video_desc_->Copy());
1371 desc_.RemoveContentByName(kAudioContentName);
1372 desc_.RemoveContentByName(kVideoContentName);
1373 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1374 audio_desc_);
1375 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1376 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001377 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1378 audio_rejected ? "" : kPwdVoice);
1379 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1380 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001381
1382 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1384
deadbeef3f7219b2015-12-28 15:17:14 -08001385 JsepSessionDescription jdesc_no_candidates(kDummyString);
1386 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1387 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 return false;
1389 }
deadbeef9d3584c2016-02-16 17:54:10 -08001390 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 EXPECT_EQ(new_sdp, message);
1392 return true;
1393 }
1394
1395 void AddSctpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001396 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 new DataContentDescription());
1398 data_desc_ = data.get();
1399 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:02 +00001400 DataCodec codec(cricket::kGoogleSctpDataCodecId,
1401 cricket::kGoogleSctpDataCodecName, 0);
1402 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1403 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001405 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1406 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 }
1408
1409 void AddRtpDataChannel() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001410 rtc::scoped_ptr<DataContentDescription> data(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 new DataContentDescription());
1412 data_desc_ = data.get();
1413
1414 data_desc_->AddCodec(DataCodec(101, "google-data", 1));
1415 StreamParams data_stream;
1416 data_stream.id = kDataChannelMsid;
1417 data_stream.cname = kDataChannelCname;
1418 data_stream.sync_label = kDataChannelLabel;
1419 data_stream.ssrcs.push_back(kDataChannelSsrc);
1420 data_desc_->AddStream(data_stream);
1421 data_desc_->AddCrypto(CryptoParams(
1422 1, "AES_CM_128_HMAC_SHA1_80",
1423 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1424 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1425 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001426 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1427 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 }
1429
1430 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1431 std::string new_sdp = kSdpFullString;
1432 ReplaceDirection(direction, &new_sdp);
1433 JsepSessionDescription new_jdesc(kDummyString);
1434
1435 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1436
1437 audio_desc_->set_direction(direction);
1438 video_desc_->set_direction(direction);
1439 if (!jdesc_.Initialize(desc_.Copy(),
1440 jdesc_.session_id(),
1441 jdesc_.session_version())) {
1442 return false;
1443 }
1444 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1445 return true;
1446 }
1447
1448 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001449 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1451 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001453
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 audio_desc_ = static_cast<AudioContentDescription*>(
1455 audio_desc_->Copy());
1456 video_desc_ = static_cast<VideoContentDescription*>(
1457 video_desc_->Copy());
1458 desc_.RemoveContentByName(kAudioContentName);
1459 desc_.RemoveContentByName(kVideoContentName);
1460 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1461 audio_desc_);
1462 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1463 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001464 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1465 audio_rejected ? "" : kPwdVoice);
1466 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1467 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001468 JsepSessionDescription jdesc_no_candidates(kDummyString);
1469 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1470 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 return false;
1472 }
deadbeef3f7219b2015-12-28 15:17:14 -08001473 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 return true;
1475 }
1476
1477 void TestDeserializeExtmap(bool session_level, bool media_level) {
1478 AddExtmap();
1479 JsepSessionDescription new_jdesc("dummy");
1480 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1481 jdesc_.session_id(),
1482 jdesc_.session_version()));
1483 JsepSessionDescription jdesc_with_extmap("dummy");
1484 std::string sdp_with_extmap = kSdpString;
1485 if (session_level) {
1486 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1487 &sdp_with_extmap);
1488 }
1489 if (media_level) {
1490 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1491 &sdp_with_extmap);
1492 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1493 &sdp_with_extmap);
1494 }
1495 // The extmap can't be present at the same time in both session level and
1496 // media level.
1497 if (session_level && media_level) {
1498 SdpParseError error;
1499 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1500 &jdesc_with_extmap, &error));
1501 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1502 } else {
1503 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1504 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1505 }
1506 }
1507
1508 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1509 const std::string& name, int expected_value) {
1510 cricket::CodecParameterMap::const_iterator found = params.find(name);
1511 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001512 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 }
1514
1515 void TestDeserializeCodecParams(const CodecParams& params,
1516 JsepSessionDescription* jdesc_output) {
1517 std::string sdp =
1518 "v=0\r\n"
1519 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1520 "s=-\r\n"
1521 "t=0 0\r\n"
1522 // Include semantics for WebRTC Media Streams since it is supported by
1523 // this parser, and will be added to the SDP when serializing a session
1524 // description.
1525 "a=msid-semantic: WMS\r\n"
1526 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001527 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 // Pltype 111 listed before 103 and 104 in the map.
1529 "a=rtpmap:111 opus/48000/2\r\n"
1530 // Pltype 103 listed before 104.
1531 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001532 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001533 "a=fmtp:111 0-15,66,70\r\n"
1534 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001536 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001537 << "; sprop-stereo=" << params.sprop_stereo
1538 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001539 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 << "a=ptime:" << params.ptime << "\r\n"
1541 << "a=maxptime:" << params.max_ptime << "\r\n";
1542 sdp += os.str();
1543
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001544 os.clear();
1545 os.str("");
1546 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001547 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001548 << "a=rtpmap:99 VP8/90000\r\n"
1549 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001550 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001551 sdp += os.str();
1552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 // Deserialize
1554 SdpParseError error;
1555 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1556
1557 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1558 ASSERT_TRUE(ac != NULL);
1559 const AudioContentDescription* acd =
1560 static_cast<const AudioContentDescription*>(ac->description);
1561 ASSERT_FALSE(acd->codecs().empty());
1562 cricket::AudioCodec opus = acd->codecs()[0];
1563 EXPECT_EQ("opus", opus.name);
1564 EXPECT_EQ(111, opus.id);
1565 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1566 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1567 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1568 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001569 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1570 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1572 cricket::AudioCodec codec = acd->codecs()[i];
1573 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1574 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1575 if (codec.name == "ISAC") {
1576 if (codec.clockrate == 16000) {
1577 EXPECT_EQ(32000, codec.bitrate);
1578 } else {
1579 EXPECT_EQ(56000, codec.bitrate);
1580 }
1581 }
1582 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001583
1584 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1585 ASSERT_TRUE(vc != NULL);
1586 const VideoContentDescription* vcd =
1587 static_cast<const VideoContentDescription*>(vc->description);
1588 ASSERT_FALSE(vcd->codecs().empty());
1589 cricket::VideoCodec vp8 = vcd->codecs()[0];
1590 EXPECT_EQ("VP8", vp8.name);
1591 EXPECT_EQ(99, vp8.id);
1592 cricket::VideoCodec rtx = vcd->codecs()[1];
1593 EXPECT_EQ("RTX", rtx.name);
1594 EXPECT_EQ(95, rtx.id);
1595 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 }
1597
1598 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1599 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001600 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 "v=0\r\n"
1602 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1603 "s=-\r\n"
1604 "t=0 0\r\n"
1605 // Include semantics for WebRTC Media Streams since it is supported by
1606 // this parser, and will be added to the SDP when serializing a session
1607 // description.
1608 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001609 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001610 "a=rtpmap:111 opus/48000/2\r\n";
1611 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 "m=video 3457 RTP/SAVPF 101\r\n"
1613 "a=rtpmap:101 VP8/90000\r\n"
1614 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001615 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001616 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001618 os << sdp_session_and_audio;
1619 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1620 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001622 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 // Deserialize
1624 SdpParseError error;
1625 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1626 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1627 ASSERT_TRUE(ac != NULL);
1628 const AudioContentDescription* acd =
1629 static_cast<const AudioContentDescription*>(ac->description);
1630 ASSERT_FALSE(acd->codecs().empty());
1631 cricket::AudioCodec opus = acd->codecs()[0];
1632 EXPECT_EQ(111, opus.id);
1633 EXPECT_TRUE(opus.HasFeedbackParam(
1634 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1635 cricket::kParamValueEmpty)));
1636
1637 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1638 ASSERT_TRUE(vc != NULL);
1639 const VideoContentDescription* vcd =
1640 static_cast<const VideoContentDescription*>(vc->description);
1641 ASSERT_FALSE(vcd->codecs().empty());
1642 cricket::VideoCodec vp8 = vcd->codecs()[0];
1643 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1644 vp8.name.c_str());
1645 EXPECT_EQ(101, vp8.id);
1646 EXPECT_TRUE(vp8.HasFeedbackParam(
1647 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1648 cricket::kParamValueEmpty)));
1649 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001650 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1651 cricket::kRtcpFbNackParamPli)));
1652 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1654 cricket::kParamValueEmpty)));
1655 EXPECT_TRUE(vp8.HasFeedbackParam(
1656 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1657 cricket::kRtcpFbCcmParamFir)));
1658 }
1659
1660 // Two SDP messages can mean the same thing but be different strings, e.g.
1661 // some of the lines can be serialized in different order.
1662 // However, a deserialized description can be compared field by field and has
1663 // no order. If deserializer has already been tested, serializing then
1664 // deserializing and comparing JsepSessionDescription will test
1665 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001666 void TestSerialize(const JsepSessionDescription& jdesc,
1667 bool unified_plan_sdp) {
1668 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 JsepSessionDescription jdesc_output_des(kDummyString);
1670 SdpParseError error;
1671 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1672 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1673 }
1674
1675 protected:
1676 SessionDescription desc_;
1677 AudioContentDescription* audio_desc_;
1678 VideoContentDescription* video_desc_;
1679 DataContentDescription* data_desc_;
1680 Candidates candidates_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001681 rtc::scoped_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 JsepSessionDescription jdesc_;
1683};
1684
1685void TestMismatch(const std::string& string1, const std::string& string2) {
1686 int position = 0;
1687 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1688 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001689 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 break;
1691 }
1692 }
1693 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1694 << " character\n"
1695 << " 1: " << string1.substr(position, 20) << "\n"
1696 << " 2: " << string2.substr(position, 20) << "\n";
1697}
1698
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1700 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001701 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 TestMismatch(std::string(kSdpFullString), message);
1703}
1704
1705TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1706 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001707 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708}
1709
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001710// This tests serialization of SDP with only IPv6 candidates and verifies that
1711// IPv6 is used as default address in c line according to preference.
1712TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1713 // Only test 1 m line.
1714 desc_.RemoveContentByName("video_content_name");
1715 // Stun has a high preference than local host.
1716 cricket::Candidate candidate1(
1717 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1718 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1719 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1720 cricket::Candidate candidate2(
1721 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1722 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1723 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1724 JsepSessionDescription jdesc(kDummyString);
1725 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1726
1727 // Only add the candidates to audio m line.
1728 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1729 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1730 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1731 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001732 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001733
1734 // Audio line should have a c line like this one.
1735 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1736 // Shouldn't have a IP4 c line.
1737 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1738}
1739
1740// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1741// verifies that IPv4 is used as default address in c line even if the
1742// preference of IPv4 is lower.
1743TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1744 // Only test 1 m line.
1745 desc_.RemoveContentByName("video_content_name");
1746 cricket::Candidate candidate_v4(
1747 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1748 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1749 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1750 cricket::Candidate candidate_v6(
1751 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1752 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1753 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1754 JsepSessionDescription jdesc(kDummyString);
1755 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1756
1757 // Only add the candidates to audio m line.
1758 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1759 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1760 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1761 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
deadbeef9d3584c2016-02-16 17:54:10 -08001762 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001763
1764 // Audio line should have a c line like this one.
1765 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1766 // Shouldn't have a IP6 c line.
1767 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1768}
1769
1770// This tests serialization of SDP with both UDP and TCP candidates and
1771// verifies that UDP is used as default address in c line even if the
1772// preference of UDP is lower.
1773TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1774 // Only test 1 m line.
1775 desc_.RemoveContentByName("video_content_name");
1776 // Stun has a high preference than local host.
1777 cricket::Candidate candidate1(
1778 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1779 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1780 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1781 cricket::Candidate candidate2(
1782 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1783 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1784 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1785 kCandidateFoundation1);
1786 JsepSessionDescription jdesc(kDummyString);
1787 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1788
1789 // Only add the candidates to audio m line.
1790 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1791 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1792 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1793 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001794 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001795
1796 // Audio line should have a c line like this one.
1797 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1798 std::string::npos);
1799 // Shouldn't have a IP4 c line.
1800 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1801}
1802
1803// This tests serialization of SDP with only TCP candidates and verifies that
1804// null IPv4 is used as default address in c line.
1805TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1806 // Only test 1 m line.
1807 desc_.RemoveContentByName("video_content_name");
1808 // Stun has a high preference than local host.
1809 cricket::Candidate candidate1(
1810 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1811 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1812 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1813 cricket::Candidate candidate2(
1814 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1815 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1816 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1817 JsepSessionDescription jdesc(kDummyString);
1818 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1819
1820 // Only add the candidates to audio m line.
1821 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1822 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1823 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1824 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-16 17:54:10 -08001825 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:13 +00001826
1827 // Audio line should have a c line like this one when no any default exists.
1828 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1829}
1830
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1832// the case in a DTLS offer.
1833TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1834 AddFingerprint();
1835 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1836 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1837 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001838 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839
1840 std::string sdp_with_fingerprint = kSdpString;
1841 InjectAfter(kAttributeIcePwdVoice,
1842 kFingerprint, &sdp_with_fingerprint);
1843 InjectAfter(kAttributeIcePwdVideo,
1844 kFingerprint, &sdp_with_fingerprint);
1845
1846 EXPECT_EQ(sdp_with_fingerprint, message);
1847}
1848
1849// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1850// be the case in a DTLS answer.
1851TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1852 AddFingerprint();
1853 RemoveCryptos();
1854 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1855 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1856 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001857 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858
1859 std::string sdp_with_fingerprint = kSdpString;
1860 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1861 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1862 InjectAfter(kAttributeIcePwdVoice,
1863 kFingerprint, &sdp_with_fingerprint);
1864 InjectAfter(kAttributeIcePwdVideo,
1865 kFingerprint, &sdp_with_fingerprint);
1866
1867 EXPECT_EQ(sdp_with_fingerprint, message);
1868}
1869
1870TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1871 // JsepSessionDescription with desc but without candidates.
1872 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 15:17:14 -08001873 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1874 kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001875 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 EXPECT_EQ(std::string(kSdpString), message);
1877}
1878
1879TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1880 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1881 group.AddContentName(kAudioContentName);
1882 group.AddContentName(kVideoContentName);
1883 desc_.AddGroup(group);
1884 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1885 jdesc_.session_id(),
1886 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001887 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 std::string sdp_with_bundle = kSdpFullString;
1889 InjectAfter(kSessionTime,
1890 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1891 &sdp_with_bundle);
1892 EXPECT_EQ(sdp_with_bundle, message);
1893}
1894
1895TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1896 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1897 GetFirstVideoContent(&desc_)->description);
1898 vcd->set_bandwidth(100 * 1000);
1899 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1900 GetFirstAudioContent(&desc_)->description);
1901 acd->set_bandwidth(50 * 1000);
1902 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1903 jdesc_.session_id(),
1904 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001905 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001907 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 "b=AS:100\r\n",
1909 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001910 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 "b=AS:50\r\n",
1912 &sdp_with_bandwidth);
1913 EXPECT_EQ(sdp_with_bandwidth, message);
1914}
1915
1916TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1917 std::vector<std::string> transport_options;
1918 transport_options.push_back(kIceOption1);
1919 transport_options.push_back(kIceOption3);
1920 AddIceOptions(kAudioContentName, transport_options);
1921 transport_options.clear();
1922 transport_options.push_back(kIceOption2);
1923 transport_options.push_back(kIceOption3);
1924 AddIceOptions(kVideoContentName, transport_options);
1925 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1926 jdesc_.session_id(),
1927 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001928 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 std::string sdp_with_ice_options = kSdpFullString;
1930 InjectAfter(kAttributeIcePwdVoice,
1931 "a=ice-options:iceoption1 iceoption3\r\n",
1932 &sdp_with_ice_options);
1933 InjectAfter(kAttributeIcePwdVideo,
1934 "a=ice-options:iceoption2 iceoption3\r\n",
1935 &sdp_with_ice_options);
1936 EXPECT_EQ(sdp_with_ice_options, message);
1937}
1938
1939TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1940 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1941}
1942
1943TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1944 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1945}
1946
1947TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1948 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1949}
1950
1951TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1952 EXPECT_TRUE(TestSerializeRejected(true, false));
1953}
1954
1955TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1956 EXPECT_TRUE(TestSerializeRejected(false, true));
1957}
1958
1959TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1960 EXPECT_TRUE(TestSerializeRejected(true, true));
1961}
1962
1963TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1964 AddRtpDataChannel();
1965 JsepSessionDescription jsep_desc(kDummyString);
1966
1967 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001968 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969
1970 std::string expected_sdp = kSdpString;
1971 expected_sdp.append(kSdpRtpDataChannelString);
1972 EXPECT_EQ(expected_sdp, message);
1973}
1974
1975TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1976 AddSctpDataChannel();
1977 JsepSessionDescription jsep_desc(kDummyString);
1978
1979 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08001980 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981
1982 std::string expected_sdp = kSdpString;
1983 expected_sdp.append(kSdpSctpDataChannelString);
1984 EXPECT_EQ(message, expected_sdp);
1985}
1986
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001987TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1988 AddSctpDataChannel();
1989 JsepSessionDescription jsep_desc(kDummyString);
1990
1991 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1992 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1993 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1994
1995 const int kNewPort = 1234;
1996 cricket::DataCodec codec(
1997 cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0);
1998 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1999 dcdesc->AddOrReplaceCodec(codec);
2000
deadbeef9d3584c2016-02-16 17:54:10 -08002001 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002002
2003 std::string expected_sdp = kSdpString;
2004 expected_sdp.append(kSdpSctpDataChannelString);
2005
2006 char default_portstr[16];
2007 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002008 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002009 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002010 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2011 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002012 new_portstr, strlen(new_portstr),
2013 &expected_sdp);
2014
2015 EXPECT_EQ(expected_sdp, message);
2016}
2017
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002018TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
2019 AddRtpDataChannel();
2020 data_desc_->set_bandwidth(100*1000);
2021 JsepSessionDescription jsep_desc(kDummyString);
2022
2023 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002024 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002025
2026 std::string expected_sdp = kSdpString;
2027 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002028 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002029 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 +00002030 "b=AS:100\r\n",
2031 &expected_sdp);
2032 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002033}
2034
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2036 AddExtmap();
2037 JsepSessionDescription desc_with_extmap("dummy");
2038 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2039 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-16 17:54:10 -08002040 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
2042 std::string sdp_with_extmap = kSdpString;
2043 InjectAfter("a=mid:audio_content_name\r\n",
2044 kExtmap, &sdp_with_extmap);
2045 InjectAfter("a=mid:video_content_name\r\n",
2046 kExtmap, &sdp_with_extmap);
2047
2048 EXPECT_EQ(sdp_with_extmap, message);
2049}
2050
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051TEST_F(WebRtcSdpTest, SerializeCandidates) {
2052 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002053 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002054
2055 Candidate candidate_with_ufrag(candidates_.front());
2056 candidate_with_ufrag.set_username("ABC");
2057 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2058 candidate_with_ufrag));
2059 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2060 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002061
2062 Candidate candidate_with_network_info(candidates_.front());
2063 candidate_with_network_info.set_network_id(1);
2064 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2065 candidate_with_network_info));
2066 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2067 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2068 candidate_with_network_info.set_network_cost(999);
2069 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2070 candidate_with_network_info));
2071 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2072 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2073 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074}
2075
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002076// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2077// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002078TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002079 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002080 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2081 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2082 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002083 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
2084 rtc::scoped_ptr<IceCandidateInterface> jcandidate(
2085 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2086
2087 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2088 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2089}
2090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2092 JsepSessionDescription jdesc(kDummyString);
2093 // Deserialize
2094 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2095 // Verify
2096 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2097}
2098
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002099TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2100 JsepSessionDescription jdesc(kDummyString);
2101 const char kSdpWithoutMline[] =
2102 "v=0\r\n"
2103 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2104 "s=-\r\n"
2105 "t=0 0\r\n"
2106 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2107 // Deserialize
2108 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2109 EXPECT_EQ(0u, jdesc.description()->contents().size());
2110}
2111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2113 JsepSessionDescription jdesc(kDummyString);
2114 std::string sdp_without_carriage_return = kSdpFullString;
2115 Replace("\r\n", "\n", &sdp_without_carriage_return);
2116 // Deserialize
2117 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2118 // Verify
2119 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2120}
2121
2122TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2123 // SessionDescription with desc but without candidates.
2124 JsepSessionDescription jdesc_no_candidates(kDummyString);
2125 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2126 kSessionId, kSessionVersion));
2127 JsepSessionDescription new_jdesc(kDummyString);
2128 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2129 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2130}
2131
2132TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2133 static const char kSdpNoRtpmapString[] =
2134 "v=0\r\n"
2135 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2136 "s=-\r\n"
2137 "t=0 0\r\n"
2138 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2139 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002140 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 // The rtpmap line for static payload codec is optional.
2142 "a=rtpmap:18 G729/16000\r\n"
2143 "a=rtpmap:103 ISAC/16000\r\n";
2144
2145 JsepSessionDescription jdesc(kDummyString);
2146 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2147 cricket::AudioContentDescription* audio =
2148 static_cast<AudioContentDescription*>(
2149 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2150 AudioCodecs ref_codecs;
2151 // The codecs in the AudioContentDescription will be sorted by preference.
2152 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3));
2153 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2));
2154 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1));
2155 EXPECT_EQ(ref_codecs, audio->codecs());
2156}
2157
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002158TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2159 static const char kSdpNoRtpmapString[] =
2160 "v=0\r\n"
2161 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2162 "s=-\r\n"
2163 "t=0 0\r\n"
2164 "m=audio 49232 RTP/AVP 18 103\r\n"
2165 "a=fmtp:18 annexb=yes\r\n"
2166 "a=rtpmap:103 ISAC/16000\r\n";
2167
2168 JsepSessionDescription jdesc(kDummyString);
2169 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2170 cricket::AudioContentDescription* audio =
2171 static_cast<AudioContentDescription*>(
2172 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2173
2174 cricket::AudioCodec g729 = audio->codecs()[0];
2175 EXPECT_EQ("G729", g729.name);
2176 EXPECT_EQ(8000, g729.clockrate);
2177 EXPECT_EQ(18, g729.id);
2178 cricket::CodecParameterMap::iterator found =
2179 g729.params.find("annexb");
2180 ASSERT_TRUE(found != g729.params.end());
2181 EXPECT_EQ(found->second, "yes");
2182
2183 cricket::AudioCodec isac = audio->codecs()[1];
2184 EXPECT_EQ("ISAC", isac.name);
2185 EXPECT_EQ(103, isac.id);
2186 EXPECT_EQ(16000, isac.clockrate);
2187}
2188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189// Ensure that we can deserialize SDP with a=fingerprint properly.
2190TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2191 // Add a DTLS a=fingerprint attribute to our session description.
2192 AddFingerprint();
2193 JsepSessionDescription new_jdesc(kDummyString);
2194 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2195 jdesc_.session_id(),
2196 jdesc_.session_version()));
2197
2198 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2199 std::string sdp_with_fingerprint = kSdpString;
2200 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2201 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2202 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2203 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2204}
2205
2206TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2207 JsepSessionDescription jdesc_with_bundle(kDummyString);
2208 std::string sdp_with_bundle = kSdpFullString;
2209 InjectAfter(kSessionTime,
2210 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2211 &sdp_with_bundle);
2212 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2213 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2214 group.AddContentName(kAudioContentName);
2215 group.AddContentName(kVideoContentName);
2216 desc_.AddGroup(group);
2217 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2218 jdesc_.session_id(),
2219 jdesc_.session_version()));
2220 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2221}
2222
2223TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2224 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2225 std::string sdp_with_bandwidth = kSdpFullString;
2226 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2227 "b=AS:100\r\n",
2228 &sdp_with_bandwidth);
2229 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2230 "b=AS:50\r\n",
2231 &sdp_with_bandwidth);
2232 EXPECT_TRUE(
2233 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2234 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2235 GetFirstVideoContent(&desc_)->description);
2236 vcd->set_bandwidth(100 * 1000);
2237 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2238 GetFirstAudioContent(&desc_)->description);
2239 acd->set_bandwidth(50 * 1000);
2240 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2241 jdesc_.session_id(),
2242 jdesc_.session_version()));
2243 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2244}
2245
2246TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2247 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2248 std::string sdp_with_ice_options = kSdpFullString;
2249 InjectAfter(kSessionTime,
2250 "a=ice-options:iceoption3\r\n",
2251 &sdp_with_ice_options);
2252 InjectAfter(kAttributeIcePwdVoice,
2253 "a=ice-options:iceoption1\r\n",
2254 &sdp_with_ice_options);
2255 InjectAfter(kAttributeIcePwdVideo,
2256 "a=ice-options:iceoption2\r\n",
2257 &sdp_with_ice_options);
2258 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2259 std::vector<std::string> transport_options;
2260 transport_options.push_back(kIceOption3);
2261 transport_options.push_back(kIceOption1);
2262 AddIceOptions(kAudioContentName, transport_options);
2263 transport_options.clear();
2264 transport_options.push_back(kIceOption3);
2265 transport_options.push_back(kIceOption2);
2266 AddIceOptions(kVideoContentName, transport_options);
2267 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2268 jdesc_.session_id(),
2269 jdesc_.session_version()));
2270 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2271}
2272
2273TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2274 // Remove the original ice-ufrag and ice-pwd
2275 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2276 std::string sdp_with_ufrag_pwd = kSdpFullString;
2277 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2278 // Add session level ufrag and pwd
2279 InjectAfter(kSessionTime,
2280 "a=ice-pwd:session+level+icepwd\r\n"
2281 "a=ice-ufrag:session+level+iceufrag\r\n",
2282 &sdp_with_ufrag_pwd);
2283 // Add media level ufrag and pwd for audio
2284 InjectAfter("a=mid:audio_content_name\r\n",
2285 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2286 &sdp_with_ufrag_pwd);
2287 // Update the candidate ufrag and pwd to the expected ones.
2288 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2289 "media+level+iceufrag", "media+level+icepwd"));
2290 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2291 "session+level+iceufrag", "session+level+icepwd"));
2292 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2293 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2294}
2295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2297 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2298}
2299
2300TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2301 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2302}
2303
2304TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2305 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2306}
2307
2308TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2309 EXPECT_TRUE(TestDeserializeRejected(true, false));
2310}
2311
2312TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2313 EXPECT_TRUE(TestDeserializeRejected(false, true));
2314}
2315
2316TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2317 EXPECT_TRUE(TestDeserializeRejected(true, true));
2318}
2319
2320// Tests that we can still handle the sdp uses mslabel and label instead of
2321// msid for backward compatibility.
2322TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002323 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 JsepSessionDescription jdesc(kDummyString);
2325 std::string sdp_without_msid = kSdpFullString;
2326 Replace("msid", "xmsid", &sdp_without_msid);
2327 // Deserialize
2328 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2329 // Verify
2330 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2331}
2332
2333TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2334 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2335
2336 std::string sdp = kSdpOneCandidate;
2337 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2338 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2339 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2340 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002341 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342
2343 // Candidate line without generation extension.
2344 sdp = kSdpOneCandidate;
2345 Replace(" generation 2", "", &sdp);
2346 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2347 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2348 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2349 Candidate expected = jcandidate_->candidate();
2350 expected.set_generation(0);
2351 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2352
honghaiza0c44ea2016-03-23 16:07:48 -07002353 // Candidate with network id and/or cost.
2354 sdp = kSdpOneCandidate;
2355 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2356 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2357 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2358 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2359 expected = jcandidate_->candidate();
2360 expected.set_network_id(2);
2361 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2362 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2363 // Add network cost
2364 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2365 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2366 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2367 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2368
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002369 sdp = kSdpTcpActiveCandidate;
2370 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2371 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002372 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002373 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2374 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2375 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002376 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template(
2377 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
2378 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2379 jcandidate_template->candidate()));
2380 sdp = kSdpTcpPassiveCandidate;
2381 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2382 sdp = kSdpTcpSOCandidate;
2383 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384}
2385
2386// This test verifies the deserialization of candidate-attribute
2387// as per RFC 5245. Candiate-attribute will be of the format
2388// candidate:<blah>. This format will be used when candidates
2389// are trickled.
2390TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2391 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2392
2393 std::string candidate_attribute = kRawCandidate;
2394 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2395 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2396 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2397 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2398 EXPECT_EQ(2u, jcandidate.candidate().generation());
2399
2400 // Candidate line without generation extension.
2401 candidate_attribute = kRawCandidate;
2402 Replace(" generation 2", "", &candidate_attribute);
2403 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2404 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2405 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2406 Candidate expected = jcandidate_->candidate();
2407 expected.set_generation(0);
2408 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2409
2410 // Candidate line without candidate:
2411 candidate_attribute = kRawCandidate;
2412 Replace("candidate:", "", &candidate_attribute);
2413 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2414
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002415 // Candidate line with IPV6 address.
2416 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2417}
2418
2419// This test verifies that the deserialization of an invalid candidate string
2420// fails.
2421TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2422 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2423
2424 std::string candidate_attribute = kRawCandidate;
2425 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002427
2428 candidate_attribute = kSdpOneCandidate;
2429 candidate_attribute.replace(0, 1, "x");
2430 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2431
2432 candidate_attribute = kRawCandidate;
2433 candidate_attribute.append("\r\n");
2434 candidate_attribute.append(kRawCandidate);
2435 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2436
2437 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438}
2439
2440TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2441 AddRtpDataChannel();
2442 JsepSessionDescription jdesc(kDummyString);
2443 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2444
2445 std::string sdp_with_data = kSdpString;
2446 sdp_with_data.append(kSdpRtpDataChannelString);
2447 JsepSessionDescription jdesc_output(kDummyString);
2448
2449 // Deserialize
2450 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2451 // Verify
2452 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2453}
2454
2455TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2456 AddSctpDataChannel();
2457 JsepSessionDescription jdesc(kDummyString);
2458 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2459
2460 std::string sdp_with_data = kSdpString;
2461 sdp_with_data.append(kSdpSctpDataChannelString);
2462 JsepSessionDescription jdesc_output(kDummyString);
2463
lally@webrtc.org36300852015-02-24 20:19:35 +00002464 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2465 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2466 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2467
2468 // Verify with UDP/DTLS/SCTP.
2469 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2470 strlen(kDtlsSctp), kUdpDtlsSctp);
2471 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2472 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2473
2474 // Verify with TCP/DTLS/SCTP.
2475 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2476 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2478 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2479}
2480
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002481TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2482 AddSctpDataChannel();
2483 JsepSessionDescription jdesc(kDummyString);
2484 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2485
2486 std::string sdp_with_data = kSdpString;
2487 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2488 JsepSessionDescription jdesc_output(kDummyString);
2489
lally@webrtc.org36300852015-02-24 20:19:35 +00002490 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002491 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2492 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002493
lally@webrtc.org36300852015-02-24 20:19:35 +00002494 // Verify with UDP/DTLS/SCTP.
2495 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2496 strlen(kDtlsSctp), kUdpDtlsSctp);
2497 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2498 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002499
lally@webrtc.org36300852015-02-24 20:19:35 +00002500 // Verify with TCP/DTLS/SCTP.
2501 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2502 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002503 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2505}
2506
lally69f57602015-10-08 10:15:04 -07002507TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2508 AddSctpDataChannel();
2509 JsepSessionDescription jdesc(kDummyString);
2510 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2511
2512 std::string sdp_with_data = kSdpString;
2513 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2514 JsepSessionDescription jdesc_output(kDummyString);
2515
2516 // Verify with DTLS/SCTP.
2517 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2518 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2519
2520 // Verify with UDP/DTLS/SCTP.
2521 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2522 strlen(kDtlsSctp), kUdpDtlsSctp);
2523 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2524 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2525
2526 // Verify with TCP/DTLS/SCTP.
2527 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2528 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2529 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2530 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2531}
2532
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002533// Test to check the behaviour if sctp-port is specified
2534// on the m= line and in a=sctp-port.
2535TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2536 AddSctpDataChannel();
2537 JsepSessionDescription jdesc(kDummyString);
2538 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2539
2540 std::string sdp_with_data = kSdpString;
2541 // Append m= attributes
2542 sdp_with_data.append(kSdpSctpDataChannelString);
2543 // Append a=sctp-port attribute
2544 sdp_with_data.append("a=sctp-port 5000\r\n");
2545 JsepSessionDescription jdesc_output(kDummyString);
2546
2547 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2548}
2549
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002550// For crbug/344475.
2551TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2552 std::string sdp_with_data = kSdpString;
2553 sdp_with_data.append(kSdpSctpDataChannelString);
2554 // Remove the "\n" at the end.
2555 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2556 JsepSessionDescription jdesc_output(kDummyString);
2557
2558 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2559 // No crash is a pass.
2560}
2561
wu@webrtc.org78187522013-10-07 23:32:02 +00002562TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2563 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 12:23:21 +02002564 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:02 +00002565 char default_portstr[16];
2566 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002567 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002568 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002569 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:02 +00002570 kUnusualSctpPort);
2571
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002572 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002573 JsepSessionDescription jdesc(kDummyString);
2574 // take our pre-built session description and change the SCTP port.
2575 cricket::SessionDescription* mutant = desc_.Copy();
2576 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2577 mutant->GetContentDescriptionByName(kDataContentName));
2578 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002579 EXPECT_EQ(1U, codecs.size());
2580 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002581 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002582 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002583
2584 // note: mutant's owned by jdesc now.
2585 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2586 mutant = NULL;
2587
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002588 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002589 std::string sdp_with_data = kSdpString;
2590 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002591 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:02 +00002592 unusual_portstr, strlen(unusual_portstr),
2593 &sdp_with_data);
2594 JsepSessionDescription jdesc_output(kDummyString);
2595
2596 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2597 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002598
2599 // We need to test the deserialized JsepSessionDescription from
2600 // kSdpSctpDataChannelStringWithSctpPort for
2601 // draft-ietf-mmusic-sctp-sdp-07
2602 // a=sctp-port
2603 sdp_with_data = kSdpString;
2604 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2605 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2606 unusual_portstr, strlen(unusual_portstr),
2607 &sdp_with_data);
2608
2609 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2610 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002611}
2612
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002613TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002614 // We want to test that deserializing data content limits bandwidth
2615 // settings (it should never be greater than the default).
2616 // This should prevent someone from using unlimited data bandwidth through
2617 // JS and "breaking the Internet".
2618 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002619 std::string sdp_with_bandwidth = kSdpString;
2620 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2621 InjectAfter("a=mid:data_content_name\r\n",
2622 "b=AS:100\r\n",
2623 &sdp_with_bandwidth);
2624 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2625
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002626 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2627}
2628
2629TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2630 AddSctpDataChannel();
2631 JsepSessionDescription jdesc(kDummyString);
2632 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2633 GetFirstDataContent(&desc_)->description);
2634 dcd->set_bandwidth(100 * 1000);
2635 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2636
2637 std::string sdp_with_bandwidth = kSdpString;
2638 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2639 InjectAfter("a=mid:data_content_name\r\n",
2640 "b=AS:100\r\n",
2641 &sdp_with_bandwidth);
2642 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2643
2644 // SCTP has congestion control, so we shouldn't limit the bandwidth
2645 // as we do for RTP.
2646 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002647 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2648}
2649
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2651 TestDeserializeExtmap(true, false);
2652}
2653
2654TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2655 TestDeserializeExtmap(false, true);
2656}
2657
2658TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2659 TestDeserializeExtmap(true, true);
2660}
2661
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002662TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2663 JsepSessionDescription jdesc(kDummyString);
2664 std::string sdp = kSdpFullString;
2665 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2666 // Deserialize
2667 SdpParseError error;
2668 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002669 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002670 EXPECT_EQ(lastline, error.line);
2671 EXPECT_EQ("Invalid SDP line.", error.description);
2672}
2673
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2675 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2676 std::string new_sdp = kSdpOneCandidate;
2677 Replace("udp", "unsupported_transport", &new_sdp);
2678 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2679 new_sdp = kSdpOneCandidate;
2680 Replace("udp", "uDP", &new_sdp);
2681 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2682 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2683 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2684 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2685}
2686
honghaiza54a0802015-12-16 18:37:23 -08002687TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002689 EXPECT_TRUE(
2690 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2692 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2693 Candidate ref_candidate = jcandidate_->candidate();
2694 ref_candidate.set_username("user_rtp");
2695 ref_candidate.set_password("password_rtp");
2696 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2697}
2698
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002699TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2700 JsepSessionDescription jdesc(kDummyString);
2701
2702 // Deserialize
2703 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2704
2705 // Verify
2706 cricket::AudioContentDescription* audio =
2707 static_cast<AudioContentDescription*>(
2708 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2709 EXPECT_TRUE(audio->conference_mode());
2710
2711 cricket::VideoContentDescription* video =
2712 static_cast<VideoContentDescription*>(
2713 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2714 EXPECT_TRUE(video->conference_mode());
2715}
2716
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2718 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002719 const char kSdpEmptyType[] = " =candidate";
2720 const char kSdpEqualAsPlus[] = "a+candidate";
2721 const char kSdpSpaceAfterEqual[] = "a= candidate";
2722 const char kSdpUpperType[] = "A=candidate";
2723 const char kSdpEmptyLine[] = "";
2724 const char kSdpMissingValue[] = "a=";
2725
2726 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727 "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 +00002728 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 "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 +00002730 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731 "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 +00002732 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002733 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002734 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
2736 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002737 ExpectParseFailure("v=", kSdpDestroyer);
2738 ExpectParseFailure("o=", kSdpDestroyer);
2739 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002741 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742
2743 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002744 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2745 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746
2747 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002748 ExpectParseFailure("a=candidate", kSdpEmptyType);
2749 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2750 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2751 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752
2753 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2754 // because it's orthogonal to what we are replacing and hence
2755 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002756 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2757 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2758 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2759 ExpectParseFailure("a=sendrecv", kSdpMd5);
2760
2761 // Empty Line
2762 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2763 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002764}
2765
2766TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2767 // ssrc
2768 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002769 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002770 // crypto
2771 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2772 // rtpmap
2773 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2774 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2775 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2776 // candidate
2777 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2778 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2779 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2780 ExpectParseFailure("rport 2346", "rport badvalue");
2781 ExpectParseFailure("rport 2346 generation 2",
2782 "rport 2346 generation badvalue");
2783 // m line
2784 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2785 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2786
2787 // bandwidth
2788 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2789 "b=AS:badvalue\r\n",
2790 "b=AS:badvalue");
2791 // rtcp-fb
2792 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2793 "a=rtcp-fb:badvalue nack\r\n",
2794 "a=rtcp-fb:badvalue nack");
2795 // extmap
2796 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2797 "a=extmap:badvalue http://example.com\r\n",
2798 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799}
2800
2801TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2802 JsepSessionDescription jdesc_output(kDummyString);
2803
2804 const char kSdpWithReorderedPlTypesString[] =
2805 "v=0\r\n"
2806 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2807 "s=-\r\n"
2808 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002809 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2811 // in the map.
2812 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002813 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814
2815 // Deserialize
2816 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2817
2818 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2819 ASSERT_TRUE(ac != NULL);
2820 const AudioContentDescription* acd =
2821 static_cast<const AudioContentDescription*>(ac->description);
2822 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002823 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2824 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002825 EXPECT_EQ(104, acd->codecs()[0].id);
2826}
2827
2828TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2829 JsepSessionDescription jdesc_output(kDummyString);
2830 CodecParams params;
2831 params.max_ptime = 40;
2832 params.ptime = 30;
2833 params.min_ptime = 10;
2834 params.sprop_stereo = 1;
2835 params.stereo = 1;
2836 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002837 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002839 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840}
2841
2842TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2843 const bool kUseWildcard = false;
2844 JsepSessionDescription jdesc_output(kDummyString);
2845 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002846 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847}
2848
2849TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2850 const bool kUseWildcard = true;
2851 JsepSessionDescription jdesc_output(kDummyString);
2852 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002853 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002854}
2855
2856TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2857 JsepSessionDescription jdesc_output(kDummyString);
2858
2859 const char kSdpWithFmtpString[] =
2860 "v=0\r\n"
2861 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2862 "s=-\r\n"
2863 "t=0 0\r\n"
2864 "m=video 3457 RTP/SAVPF 120\r\n"
2865 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002866 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2867
2868 // Deserialize
2869 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002870 EXPECT_TRUE(
2871 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002872
2873 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2874 ASSERT_TRUE(vc != NULL);
2875 const VideoContentDescription* vcd =
2876 static_cast<const VideoContentDescription*>(vc->description);
2877 ASSERT_FALSE(vcd->codecs().empty());
2878 cricket::VideoCodec vp8 = vcd->codecs()[0];
2879 EXPECT_EQ("VP8", vp8.name);
2880 EXPECT_EQ(120, vp8.id);
2881 cricket::CodecParameterMap::iterator found =
2882 vp8.params.find("x-google-min-bitrate");
2883 ASSERT_TRUE(found != vp8.params.end());
2884 EXPECT_EQ(found->second, "10");
2885 found = vp8.params.find("x-google-max-quantization");
2886 ASSERT_TRUE(found != vp8.params.end());
2887 EXPECT_EQ(found->second, "40");
2888}
2889
2890TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2891 JsepSessionDescription jdesc_output(kDummyString);
2892
2893 const char kSdpWithFmtpString[] =
2894 "v=0\r\n"
2895 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2896 "s=-\r\n"
2897 "t=0 0\r\n"
2898 "m=video 3457 RTP/SAVPF 120\r\n"
2899 "a=rtpmap:120 VP8/90000\r\n"
2900 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901
2902 // Deserialize
2903 SdpParseError error;
2904 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2905 &error));
2906
2907 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2908 ASSERT_TRUE(vc != NULL);
2909 const VideoContentDescription* vcd =
2910 static_cast<const VideoContentDescription*>(vc->description);
2911 ASSERT_FALSE(vcd->codecs().empty());
2912 cricket::VideoCodec vp8 = vcd->codecs()[0];
2913 EXPECT_EQ("VP8", vp8.name);
2914 EXPECT_EQ(120, vp8.id);
2915 cricket::CodecParameterMap::iterator found =
2916 vp8.params.find("x-google-min-bitrate");
2917 ASSERT_TRUE(found != vp8.params.end());
2918 EXPECT_EQ(found->second, "10");
2919 found = vp8.params.find("x-google-max-quantization");
2920 ASSERT_TRUE(found != vp8.params.end());
2921 EXPECT_EQ(found->second, "40");
2922}
2923
2924TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2925 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2926 GetFirstVideoContent(&desc_)->description);
2927
2928 cricket::VideoCodecs codecs = vcd->codecs();
2929 codecs[0].params["x-google-min-bitrate"] = "10";
2930 vcd->set_codecs(codecs);
2931
2932 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2933 jdesc_.session_id(),
2934 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08002935 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 std::string sdp_with_fmtp = kSdpFullString;
2937 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2938 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2939 &sdp_with_fmtp);
2940 EXPECT_EQ(sdp_with_fmtp, message);
2941}
2942
2943TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2944 JsepSessionDescription jdesc_with_icelite(kDummyString);
2945 std::string sdp_with_icelite = kSdpFullString;
2946 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2947 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2948 const cricket::TransportInfo* tinfo1 =
2949 desc->GetTransportInfoByName("audio_content_name");
2950 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2951 const cricket::TransportInfo* tinfo2 =
2952 desc->GetTransportInfoByName("video_content_name");
2953 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2954 InjectAfter(kSessionTime,
2955 "a=ice-lite\r\n",
2956 &sdp_with_icelite);
2957 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2958 desc = jdesc_with_icelite.description();
2959 const cricket::TransportInfo* atinfo =
2960 desc->GetTransportInfoByName("audio_content_name");
2961 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2962 const cricket::TransportInfo* vtinfo =
2963 desc->GetTransportInfoByName("video_content_name");
2964 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2965}
2966
2967// Verifies that the candidates in the input SDP are parsed and serialized
2968// correctly in the output SDP.
2969TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
2970 std::string sdp_with_data = kSdpString;
2971 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
2972 JsepSessionDescription jdesc_output(kDummyString);
2973
2974 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08002975 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00002977
2978TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
2979 AddFingerprint();
2980 TransportInfo audio_transport_info =
2981 *(desc_.GetTransportInfoByName(kAudioContentName));
2982 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2983 audio_transport_info.description.connection_role);
2984 audio_transport_info.description.connection_role =
2985 cricket::CONNECTIONROLE_ACTIVE;
2986
2987 TransportInfo video_transport_info =
2988 *(desc_.GetTransportInfoByName(kVideoContentName));
2989 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
2990 video_transport_info.description.connection_role);
2991 video_transport_info.description.connection_role =
2992 cricket::CONNECTIONROLE_ACTIVE;
2993
2994 desc_.RemoveTransportInfoByName(kAudioContentName);
2995 desc_.RemoveTransportInfoByName(kVideoContentName);
2996
2997 desc_.AddTransportInfo(audio_transport_info);
2998 desc_.AddTransportInfo(video_transport_info);
2999
3000 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3001 jdesc_.session_id(),
3002 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003003 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003004 std::string sdp_with_dtlssetup = kSdpFullString;
3005
3006 // Fingerprint attribute is necessary to add DTLS setup attribute.
3007 InjectAfter(kAttributeIcePwdVoice,
3008 kFingerprint, &sdp_with_dtlssetup);
3009 InjectAfter(kAttributeIcePwdVideo,
3010 kFingerprint, &sdp_with_dtlssetup);
3011 // Now adding |setup| attribute.
3012 InjectAfter(kFingerprint,
3013 "a=setup:active\r\n", &sdp_with_dtlssetup);
3014 EXPECT_EQ(sdp_with_dtlssetup, message);
3015}
3016
3017TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3018 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3019 std::string sdp_with_dtlssetup = kSdpFullString;
3020 InjectAfter(kSessionTime,
3021 "a=setup:actpass\r\n",
3022 &sdp_with_dtlssetup);
3023 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3024 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3025 const cricket::TransportInfo* atinfo =
3026 desc->GetTransportInfoByName("audio_content_name");
3027 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3028 atinfo->description.connection_role);
3029 const cricket::TransportInfo* vtinfo =
3030 desc->GetTransportInfoByName("video_content_name");
3031 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3032 vtinfo->description.connection_role);
3033}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003034
3035// Verifies that the order of the serialized m-lines follows the order of the
3036// ContentInfo in SessionDescription, and vise versa for deserialization.
3037TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3038 JsepSessionDescription jdesc(kDummyString);
3039 const std::string media_content_sdps[3] = {
3040 kSdpAudioString,
3041 kSdpVideoString,
3042 kSdpSctpDataChannelString
3043 };
3044 const cricket::MediaType media_types[3] = {
3045 cricket::MEDIA_TYPE_AUDIO,
3046 cricket::MEDIA_TYPE_VIDEO,
3047 cricket::MEDIA_TYPE_DATA
3048 };
3049
3050 // Verifies all 6 permutations.
3051 for (size_t i = 0; i < 6; ++i) {
3052 size_t media_content_in_sdp[3];
3053 // The index of the first media content.
3054 media_content_in_sdp[0] = i / 2;
3055 // The index of the second media content.
3056 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3057 // The index of the third media content.
3058 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3059
3060 std::string sdp_string = kSdpSessionString;
3061 for (size_t i = 0; i < 3; ++i)
3062 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3063
3064 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3065 cricket::SessionDescription* desc = jdesc.description();
3066 EXPECT_EQ(3u, desc->contents().size());
3067
3068 for (size_t i = 0; i < 3; ++i) {
3069 const cricket::MediaContentDescription* mdesc =
3070 static_cast<const cricket::MediaContentDescription*>(
3071 desc->contents()[i].description);
3072 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3073 }
3074
deadbeef9d3584c2016-02-16 17:54:10 -08003075 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003076 EXPECT_EQ(sdp_string, serialized_sdp);
3077 }
3078}
deadbeef9d3584c2016-02-16 17:54:10 -08003079
3080TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3081 MakePlanBDescription();
3082
3083 JsepSessionDescription deserialized_description(kDummyString);
3084 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3085
3086 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3087}
3088
3089TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3090 MakePlanBDescription();
3091 TestSerialize(jdesc_, false);
3092}
3093
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003094// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3095// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3096// some extent). If we parse this, the Plan B msid attribute (which is more
3097// specific, since it's at the SSRC level) should take priority.
3098TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3099 MakePlanBDescription();
3100
3101 JsepSessionDescription deserialized_description(kDummyString);
3102 EXPECT_TRUE(
3103 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3104
3105 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3106}
3107
deadbeef9d3584c2016-02-16 17:54:10 -08003108TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3109 MakeUnifiedPlanDescription();
3110
3111 JsepSessionDescription deserialized_description(kDummyString);
3112 EXPECT_TRUE(
3113 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3114
3115 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3116}
3117
3118TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3119 MakeUnifiedPlanDescription();
3120 TestSerialize(jdesc_, true);
3121}