blob: 57a7bdb0c05117a3cece735704172c3a49641456 [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
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080017#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018#include "webrtc/base/gunit.h"
19#include "webrtc/base/logging.h"
20#include "webrtc/base/messagedigest.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000021#include "webrtc/base/sslfingerprint.h"
22#include "webrtc/base/stringencode.h"
23#include "webrtc/base/stringutils.h"
kjellanderf4752772016-03-02 05:42:30 -080024#include "webrtc/media/base/mediaconstants.h"
eladalonf1841382017-06-12 01:16:46 -070025#include "webrtc/media/engine/webrtcvideoengine.h"
htaa6b99442016-04-12 10:29:17 -070026#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
kjellanderf4752772016-03-02 05:42:30 -080027#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010028#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
30#include "webrtc/pc/test/androidtestinitializer.h"
31#endif
32#include "webrtc/pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
46using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048using cricket::RELAY_PORT_TYPE;
49using cricket::SessionDescription;
50using cricket::StreamParams;
51using cricket::STUN_PORT_TYPE;
52using cricket::TransportDescription;
53using cricket::TransportInfo;
54using cricket::VideoCodec;
55using cricket::VideoContentDescription;
56using webrtc::IceCandidateCollection;
57using webrtc::IceCandidateInterface;
58using webrtc::JsepIceCandidate;
59using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070060using webrtc::RtpExtension;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
62using webrtc::SessionDescriptionInterface;
63
64typedef std::vector<AudioCodec> AudioCodecs;
65typedef std::vector<Candidate> Candidates;
66
Peter Boström0c4e06b2015-10-07 12:23:21 +020067static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080068static const char kDefaultSctpPortStr[] = "5000";
69static const uint16_t kUnusualSctpPort = 9556;
70static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020072static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080073static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080075static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020077static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078static const char kCandidateFoundation1[] = "a0+B/1";
79static const char kCandidateFoundation2[] = "a0+B/2";
80static const char kCandidateFoundation3[] = "a0+B/3";
81static const char kCandidateFoundation4[] = "a0+B/4";
82static const char kAttributeCryptoVoice[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
84 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
85 "dummy_session_params\r\n";
86static const char kAttributeCryptoVideo[] =
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
89static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91static const int kExtmapId = 1;
92static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97
Peter Boström0c4e06b2015-10-07 12:23:21 +020098static const uint8_t kIdentityDigest[] = {
99 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
100 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
lally@webrtc.org34807282015-02-24 20:19:39 +0000102static const char kDtlsSctp[] = "DTLS/SCTP";
103static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
104static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106struct CodecParams {
107 int max_ptime;
108 int ptime;
109 int min_ptime;
110 int sprop_stereo;
111 int stereo;
112 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000113 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114};
115
deadbeef9d3584c2016-02-16 17:54:10 -0800116// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
117// instead of "a=crypto", and have an explicit test for adding "a=crypto".
118// Currently it's the other way around.
119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120// Reference sdp string
121static const char kSdpFullString[] =
122 "v=0\r\n"
123 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
124 "s=-\r\n"
125 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800126 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
128 "c=IN IP4 74.125.127.126\r\n"
129 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
130 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
135 "generation 2\r\n"
136 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
137 "generation 2\r\n"
138 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
139 "raddr 192.168.1.5 rport 2346 "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
142 "raddr 192.168.1.5 rport 2348 "
143 "generation 2\r\n"
144 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
145 "a=mid:audio_content_name\r\n"
146 "a=sendrecv\r\n"
147 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800148 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
150 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
151 "dummy_session_params\r\n"
152 "a=rtpmap:111 opus/48000/2\r\n"
153 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000154 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 "a=ssrc:1 cname:stream_1_cname\r\n"
156 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
157 "a=ssrc:1 mslabel:local_stream_1\r\n"
158 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 "m=video 3457 RTP/SAVPF 120\r\n"
160 "c=IN IP4 74.125.224.39\r\n"
161 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
169 "generation 2\r\n"
170 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
171 "generation 2\r\n"
172 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
175 "a=mid:video_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
178 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800180 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 "a=ssrc:2 cname:stream_1_cname\r\n"
182 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
183 "a=ssrc:2 mslabel:local_stream_1\r\n"
184 "a=ssrc:2 label:video_track_id_1\r\n"
185 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800186 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800188 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189
190// SDP reference string without the candidates.
191static const char kSdpString[] =
192 "v=0\r\n"
193 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
194 "s=-\r\n"
195 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800196 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000197 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000198 "c=IN IP4 0.0.0.0\r\n"
199 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
201 "a=mid:audio_content_name\r\n"
202 "a=sendrecv\r\n"
203 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800204 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
206 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
207 "dummy_session_params\r\n"
208 "a=rtpmap:111 opus/48000/2\r\n"
209 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000210 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 "a=ssrc:1 cname:stream_1_cname\r\n"
212 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
213 "a=ssrc:1 mslabel:local_stream_1\r\n"
214 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000215 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000216 "c=IN IP4 0.0.0.0\r\n"
217 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
219 "a=mid:video_content_name\r\n"
220 "a=sendrecv\r\n"
221 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
222 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
223 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800224 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 "a=ssrc:2 cname:stream_1_cname\r\n"
226 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
227 "a=ssrc:2 mslabel:local_stream_1\r\n"
228 "a=ssrc:2 label:video_track_id_1\r\n"
229 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800230 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800232 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233
234static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000235 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000236 "c=IN IP4 0.0.0.0\r\n"
237 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 "a=ice-ufrag:ufrag_data\r\n"
239 "a=ice-pwd:pwd_data\r\n"
240 "a=mid:data_content_name\r\n"
241 "a=sendrecv\r\n"
242 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
243 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
244 "a=rtpmap:101 google-data/90000\r\n"
245 "a=ssrc:10 cname:data_channel_cname\r\n"
246 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
247 "a=ssrc:10 mslabel:data_channel\r\n"
248 "a=ssrc:10 label:data_channeld0\r\n";
249
250static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000251 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000252 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 "a=ice-ufrag:ufrag_data\r\n"
254 "a=ice-pwd:pwd_data\r\n"
255 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000256 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000258// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000259static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000260 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
261 "a=max-message-size=100000\r\n"
262 "a=sctp-port 5000\r\n"
263 "c=IN IP4 0.0.0.0\r\n"
264 "a=ice-ufrag:ufrag_data\r\n"
265 "a=ice-pwd:pwd_data\r\n"
266 "a=mid:data_content_name\r\n";
267
lally69f57602015-10-08 10:15:04 -0700268static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
269 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
270 "a=max-message-size=100000\r\n"
271 "a=sctp-port:5000\r\n"
272 "c=IN IP4 0.0.0.0\r\n"
273 "a=ice-ufrag:ufrag_data\r\n"
274 "a=ice-pwd:pwd_data\r\n"
275 "a=mid:data_content_name\r\n";
276
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277static const char kSdpSctpDataChannelWithCandidatesString[] =
278 "m=application 2345 DTLS/SCTP 5000\r\n"
279 "c=IN IP4 74.125.127.126\r\n"
280 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
281 "generation 2\r\n"
282 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
283 "generation 2\r\n"
284 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
285 "raddr 192.168.1.5 rport 2346 "
286 "generation 2\r\n"
287 "a=ice-ufrag:ufrag_data\r\n"
288 "a=ice-pwd:pwd_data\r\n"
289 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000290 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000292static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000293 "v=0\r\n"
294 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
295 "s=-\r\n"
296 "t=0 0\r\n"
297 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000298 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000299 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000300 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000301 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000302 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000303 "a=x-google-flag:conference\r\n";
304
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000305static const char kSdpSessionString[] =
306 "v=0\r\n"
307 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
308 "s=-\r\n"
309 "t=0 0\r\n"
310 "a=msid-semantic: WMS local_stream\r\n";
311
312static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000313 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000314 "c=IN IP4 0.0.0.0\r\n"
315 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000316 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
317 "a=mid:audio_content_name\r\n"
318 "a=sendrecv\r\n"
319 "a=rtpmap:111 opus/48000/2\r\n"
320 "a=ssrc:1 cname:stream_1_cname\r\n"
321 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
322 "a=ssrc:1 mslabel:local_stream\r\n"
323 "a=ssrc:1 label:audio_track_id_1\r\n";
324
325static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000326 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000327 "c=IN IP4 0.0.0.0\r\n"
328 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000329 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
330 "a=mid:video_content_name\r\n"
331 "a=sendrecv\r\n"
332 "a=rtpmap:120 VP8/90000\r\n"
333 "a=ssrc:2 cname:stream_1_cname\r\n"
334 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
335 "a=ssrc:2 mslabel:local_stream\r\n"
336 "a=ssrc:2 label:video_track_id_1\r\n";
337
deadbeef25ed4352016-12-12 18:37:36 -0800338// Reference sdp string using bundle-only.
339static const char kBundleOnlySdpFullString[] =
340 "v=0\r\n"
341 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
342 "s=-\r\n"
343 "t=0 0\r\n"
344 "a=group:BUNDLE audio_content_name video_content_name\r\n"
345 "a=msid-semantic: WMS local_stream_1\r\n"
346 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
347 "c=IN IP4 74.125.127.126\r\n"
348 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
349 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
352 "generation 2\r\n"
353 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
354 "generation 2\r\n"
355 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
356 "generation 2\r\n"
357 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
358 "raddr 192.168.1.5 rport 2346 "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
361 "raddr 192.168.1.5 rport 2348 "
362 "generation 2\r\n"
363 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
364 "a=mid:audio_content_name\r\n"
365 "a=sendrecv\r\n"
366 "a=rtcp-mux\r\n"
367 "a=rtcp-rsize\r\n"
368 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
369 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
370 "dummy_session_params\r\n"
371 "a=rtpmap:111 opus/48000/2\r\n"
372 "a=rtpmap:103 ISAC/16000\r\n"
373 "a=rtpmap:104 ISAC/32000\r\n"
374 "a=ssrc:1 cname:stream_1_cname\r\n"
375 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
376 "a=ssrc:1 mslabel:local_stream_1\r\n"
377 "a=ssrc:1 label:audio_track_id_1\r\n"
378 "m=video 0 RTP/SAVPF 120\r\n"
379 "c=IN IP4 0.0.0.0\r\n"
380 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
381 "a=bundle-only\r\n"
382 "a=mid:video_content_name\r\n"
383 "a=sendrecv\r\n"
384 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
385 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
386 "a=rtpmap:120 VP8/90000\r\n"
387 "a=ssrc-group:FEC 2 3\r\n"
388 "a=ssrc:2 cname:stream_1_cname\r\n"
389 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
390 "a=ssrc:2 mslabel:local_stream_1\r\n"
391 "a=ssrc:2 label:video_track_id_1\r\n"
392 "a=ssrc:3 cname:stream_1_cname\r\n"
393 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
394 "a=ssrc:3 mslabel:local_stream_1\r\n"
395 "a=ssrc:3 label:video_track_id_1\r\n";
396
deadbeef9d3584c2016-02-16 17:54:10 -0800397// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
398// tracks.
399static const char kPlanBSdpFullString[] =
400 "v=0\r\n"
401 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
402 "s=-\r\n"
403 "t=0 0\r\n"
404 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
405 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
406 "c=IN IP4 74.125.127.126\r\n"
407 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
408 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
409 "generation 2\r\n"
410 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
411 "generation 2\r\n"
412 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
413 "generation 2\r\n"
414 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
415 "generation 2\r\n"
416 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
417 "raddr 192.168.1.5 rport 2346 "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
420 "raddr 192.168.1.5 rport 2348 "
421 "generation 2\r\n"
422 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
423 "a=mid:audio_content_name\r\n"
424 "a=sendrecv\r\n"
425 "a=rtcp-mux\r\n"
426 "a=rtcp-rsize\r\n"
427 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
428 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
429 "dummy_session_params\r\n"
430 "a=rtpmap:111 opus/48000/2\r\n"
431 "a=rtpmap:103 ISAC/16000\r\n"
432 "a=rtpmap:104 ISAC/32000\r\n"
433 "a=ssrc:1 cname:stream_1_cname\r\n"
434 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
435 "a=ssrc:1 mslabel:local_stream_1\r\n"
436 "a=ssrc:1 label:audio_track_id_1\r\n"
437 "a=ssrc:4 cname:stream_2_cname\r\n"
438 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
439 "a=ssrc:4 mslabel:local_stream_2\r\n"
440 "a=ssrc:4 label:audio_track_id_2\r\n"
441 "m=video 3457 RTP/SAVPF 120\r\n"
442 "c=IN IP4 74.125.224.39\r\n"
443 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
444 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
449 "generation 2\r\n"
450 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
451 "generation 2\r\n"
452 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
453 "generation 2\r\n"
454 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
455 "generation 2\r\n"
456 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
457 "a=mid:video_content_name\r\n"
458 "a=sendrecv\r\n"
459 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
460 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
461 "a=rtpmap:120 VP8/90000\r\n"
462 "a=ssrc-group:FEC 2 3\r\n"
463 "a=ssrc:2 cname:stream_1_cname\r\n"
464 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
465 "a=ssrc:2 mslabel:local_stream_1\r\n"
466 "a=ssrc:2 label:video_track_id_1\r\n"
467 "a=ssrc:3 cname:stream_1_cname\r\n"
468 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
469 "a=ssrc:3 mslabel:local_stream_1\r\n"
470 "a=ssrc:3 label:video_track_id_1\r\n"
471 "a=ssrc:5 cname:stream_2_cname\r\n"
472 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
473 "a=ssrc:5 mslabel:local_stream_2\r\n"
474 "a=ssrc:5 label:video_track_id_2\r\n"
475 "a=ssrc:6 cname:stream_2_cname\r\n"
476 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
477 "a=ssrc:6 mslabel:local_stream_2\r\n"
478 "a=ssrc:6 label:video_track_id_3\r\n";
479
Taylor Brandstetter5de6b752016-03-09 17:02:30 -0800480// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
481// tracks, but with the unified plan "a=msid" attribute.
482static const char kPlanBSdpFullStringWithMsid[] =
483 "v=0\r\n"
484 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
485 "s=-\r\n"
486 "t=0 0\r\n"
487 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
488 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
489 "c=IN IP4 74.125.127.126\r\n"
490 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
491 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
492 "generation 2\r\n"
493 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
494 "generation 2\r\n"
495 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
496 "generation 2\r\n"
497 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
498 "generation 2\r\n"
499 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
500 "raddr 192.168.1.5 rport 2346 "
501 "generation 2\r\n"
502 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
503 "raddr 192.168.1.5 rport 2348 "
504 "generation 2\r\n"
505 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
506 "a=mid:audio_content_name\r\n"
507 "a=msid:local_stream_1 audio_track_id_1\r\n"
508 "a=sendrecv\r\n"
509 "a=rtcp-mux\r\n"
510 "a=rtcp-rsize\r\n"
511 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
512 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
513 "dummy_session_params\r\n"
514 "a=rtpmap:111 opus/48000/2\r\n"
515 "a=rtpmap:103 ISAC/16000\r\n"
516 "a=rtpmap:104 ISAC/32000\r\n"
517 "a=ssrc:1 cname:stream_1_cname\r\n"
518 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
519 "a=ssrc:1 mslabel:local_stream_1\r\n"
520 "a=ssrc:1 label:audio_track_id_1\r\n"
521 "a=ssrc:4 cname:stream_2_cname\r\n"
522 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
523 "a=ssrc:4 mslabel:local_stream_2\r\n"
524 "a=ssrc:4 label:audio_track_id_2\r\n"
525 "m=video 3457 RTP/SAVPF 120\r\n"
526 "c=IN IP4 74.125.224.39\r\n"
527 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
528 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
533 "generation 2\r\n"
534 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
535 "generation 2\r\n"
536 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
537 "generation 2\r\n"
538 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
539 "generation 2\r\n"
540 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
541 "a=mid:video_content_name\r\n"
542 "a=msid:local_stream_1 video_track_id_1\r\n"
543 "a=sendrecv\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
545 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
546 "a=rtpmap:120 VP8/90000\r\n"
547 "a=ssrc-group:FEC 2 3\r\n"
548 "a=ssrc:2 cname:stream_1_cname\r\n"
549 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
550 "a=ssrc:2 mslabel:local_stream_1\r\n"
551 "a=ssrc:2 label:video_track_id_1\r\n"
552 "a=ssrc:3 cname:stream_1_cname\r\n"
553 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
554 "a=ssrc:3 mslabel:local_stream_1\r\n"
555 "a=ssrc:3 label:video_track_id_1\r\n"
556 "a=ssrc:5 cname:stream_2_cname\r\n"
557 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
558 "a=ssrc:5 mslabel:local_stream_2\r\n"
559 "a=ssrc:5 label:video_track_id_2\r\n"
560 "a=ssrc:6 cname:stream_2_cname\r\n"
561 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
562 "a=ssrc:6 mslabel:local_stream_2\r\n"
563 "a=ssrc:6 label:video_track_id_3\r\n";
564
deadbeef9d3584c2016-02-16 17:54:10 -0800565// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
566// tracks.
567static const char kUnifiedPlanSdpFullString[] =
568 "v=0\r\n"
569 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
570 "s=-\r\n"
571 "t=0 0\r\n"
572 "a=msid-semantic: WMS local_stream_1\r\n"
573 // Audio track 1, stream 1 (with candidates).
574 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
575 "c=IN IP4 74.125.127.126\r\n"
576 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
577 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
578 "generation 2\r\n"
579 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
580 "generation 2\r\n"
581 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
582 "generation 2\r\n"
583 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
584 "generation 2\r\n"
585 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
586 "raddr 192.168.1.5 rport 2346 "
587 "generation 2\r\n"
588 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
589 "raddr 192.168.1.5 rport 2348 "
590 "generation 2\r\n"
591 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
592 "a=mid:audio_content_name\r\n"
593 "a=msid:local_stream_1 audio_track_id_1\r\n"
594 "a=sendrecv\r\n"
595 "a=rtcp-mux\r\n"
596 "a=rtcp-rsize\r\n"
597 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
598 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
599 "dummy_session_params\r\n"
600 "a=rtpmap:111 opus/48000/2\r\n"
601 "a=rtpmap:103 ISAC/16000\r\n"
602 "a=rtpmap:104 ISAC/32000\r\n"
603 "a=ssrc:1 cname:stream_1_cname\r\n"
604 // Video track 1, stream 1 (with candidates).
605 "m=video 3457 RTP/SAVPF 120\r\n"
606 "c=IN IP4 74.125.224.39\r\n"
607 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
608 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
609 "generation 2\r\n"
610 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
611 "generation 2\r\n"
612 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
613 "generation 2\r\n"
614 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
615 "generation 2\r\n"
616 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
617 "generation 2\r\n"
618 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
619 "generation 2\r\n"
620 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
621 "a=mid:video_content_name\r\n"
622 "a=msid:local_stream_1 video_track_id_1\r\n"
623 "a=sendrecv\r\n"
624 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
625 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
626 "a=rtpmap:120 VP8/90000\r\n"
627 "a=ssrc-group:FEC 2 3\r\n"
628 "a=ssrc:2 cname:stream_1_cname\r\n"
629 "a=ssrc:3 cname:stream_1_cname\r\n"
630 // Audio track 2, stream 2.
631 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
632 "c=IN IP4 0.0.0.0\r\n"
633 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
634 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
635 "a=mid:audio_content_name_2\r\n"
636 "a=msid:local_stream_2 audio_track_id_2\r\n"
637 "a=sendrecv\r\n"
638 "a=rtcp-mux\r\n"
639 "a=rtcp-rsize\r\n"
640 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
641 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
642 "dummy_session_params\r\n"
643 "a=rtpmap:111 opus/48000/2\r\n"
644 "a=rtpmap:103 ISAC/16000\r\n"
645 "a=rtpmap:104 ISAC/32000\r\n"
646 "a=ssrc:4 cname:stream_2_cname\r\n"
647 // Video track 2, stream 2.
648 "m=video 9 RTP/SAVPF 120\r\n"
649 "c=IN IP4 0.0.0.0\r\n"
650 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
651 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
652 "a=mid:video_content_name_2\r\n"
653 "a=msid:local_stream_2 video_track_id_2\r\n"
654 "a=sendrecv\r\n"
655 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
656 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
657 "a=rtpmap:120 VP8/90000\r\n"
658 "a=ssrc:5 cname:stream_2_cname\r\n"
659 // Video track 3, stream 2.
660 "m=video 9 RTP/SAVPF 120\r\n"
661 "c=IN IP4 0.0.0.0\r\n"
662 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
663 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
664 "a=mid:video_content_name_3\r\n"
665 "a=msid:local_stream_2 video_track_id_3\r\n"
666 "a=sendrecv\r\n"
667 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
668 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
669 "a=rtpmap:120 VP8/90000\r\n"
670 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671
672// One candidate reference string as per W3c spec.
673// candidate:<blah> not a=candidate:<blah>CRLF
674static const char kRawCandidate[] =
675 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
676// One candidate reference string.
677static const char kSdpOneCandidate[] =
678 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
679 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000680
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000681static const char kSdpTcpActiveCandidate[] =
682 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
683 "tcptype active generation 2";
684static const char kSdpTcpPassiveCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype passive generation 2";
687static const char kSdpTcpSOCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype so generation 2";
690static const char kSdpTcpInvalidCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype invalid generation 2";
693
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000694// One candidate reference string with IPV6 address.
695static const char kRawIPV6Candidate[] =
696 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700697 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698
699// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800700static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800702 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703
704// Session id and version
705static const char kSessionId[] = "18446744069414584320";
706static const char kSessionVersion[] = "18446462598732840960";
707
deadbeef9d3584c2016-02-16 17:54:10 -0800708// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709static const char kIceOption1[] = "iceoption1";
710static const char kIceOption2[] = "iceoption2";
711static const char kIceOption3[] = "iceoption3";
712
deadbeef9d3584c2016-02-16 17:54:10 -0800713// ICE ufrags/passwords.
714static const char kUfragVoice[] = "ufrag_voice";
715static const char kPwdVoice[] = "pwd_voice";
716static const char kUfragVideo[] = "ufrag_video";
717static const char kPwdVideo[] = "pwd_video";
718static const char kUfragData[] = "ufrag_data";
719static const char kPwdData[] = "pwd_data";
720
721// Extra ufrags/passwords for extra unified plan m= sections.
722static const char kUfragVoice2[] = "ufrag_voice_2";
723static const char kPwdVoice2[] = "pwd_voice_2";
724static const char kUfragVideo2[] = "ufrag_video_2";
725static const char kPwdVideo2[] = "pwd_video_2";
726static const char kUfragVideo3[] = "ufrag_video_3";
727static const char kPwdVideo3[] = "pwd_video_3";
728
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729// Content name
730static const char kAudioContentName[] = "audio_content_name";
731static const char kVideoContentName[] = "video_content_name";
732static const char kDataContentName[] = "data_content_name";
733
deadbeef9d3584c2016-02-16 17:54:10 -0800734// Extra content names for extra unified plan m= sections.
735static const char kAudioContentName2[] = "audio_content_name_2";
736static const char kVideoContentName2[] = "video_content_name_2";
737static const char kVideoContentName3[] = "video_content_name_3";
738
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739// MediaStream 1
740static const char kStreamLabel1[] = "local_stream_1";
741static const char kStream1Cname[] = "stream_1_cname";
742static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200743static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800745static const uint32_t kVideoTrack1Ssrc1 = 2;
746static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747
748// MediaStream 2
749static const char kStreamLabel2[] = "local_stream_2";
750static const char kStream2Cname[] = "stream_2_cname";
751static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200752static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800753static const char kVideoTrackId2[] = "video_track_id_2";
754static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800756static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757
758// DataChannel
759static const char kDataChannelLabel[] = "data_channel";
760static const char kDataChannelMsid[] = "data_channeld0";
761static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200762static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764// Candidate
765static const char kDummyMid[] = "dummy_mid";
766static const int kDummyIndex = 123;
767
768// Misc
769static const char kDummyString[] = "dummy";
770
771// Helper functions
772
773static bool SdpDeserialize(const std::string& message,
774 JsepSessionDescription* jdesc) {
775 return webrtc::SdpDeserialize(message, jdesc, NULL);
776}
777
778static bool SdpDeserializeCandidate(const std::string& message,
779 JsepIceCandidate* candidate) {
780 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
781}
782
783// Add some extra |newlines| to the |message| after |line|.
784static void InjectAfter(const std::string& line,
785 const std::string& newlines,
786 std::string* message) {
787 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000788 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 tmp.c_str(), tmp.length(), message);
790}
791
792static void Replace(const std::string& line,
793 const std::string& newlines,
794 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000795 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 newlines.c_str(), newlines.length(), message);
797}
798
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000799// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
800// message.
801static void ExpectParseFailure(const std::string& bad_sdp,
802 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000805 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000807 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
808}
809
810// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
811static void ExpectParseFailure(const char* good_part, const char* bad_part) {
812 std::string bad_sdp = kSdpFullString;
813 Replace(good_part, bad_part, &bad_sdp);
814 ExpectParseFailure(bad_sdp, bad_part);
815}
816
817// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
818static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
819 const std::string& newlines,
820 const std::string& bad_part) {
821 std::string bad_sdp = kSdpFullString;
822 InjectAfter(injectpoint, newlines, &bad_sdp);
823 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824}
825
826static void ReplaceDirection(cricket::MediaContentDirection direction,
827 std::string* message) {
828 std::string new_direction;
829 switch (direction) {
830 case cricket::MD_INACTIVE:
831 new_direction = "a=inactive";
832 break;
833 case cricket::MD_SENDONLY:
834 new_direction = "a=sendonly";
835 break;
836 case cricket::MD_RECVONLY:
837 new_direction = "a=recvonly";
838 break;
839 case cricket::MD_SENDRECV:
840 default:
841 new_direction = "a=sendrecv";
842 break;
843 }
844 Replace("a=sendrecv", new_direction, message);
845}
846
847static void ReplaceRejected(bool audio_rejected, bool video_rejected,
848 std::string* message) {
849 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800850 Replace("m=audio 9", "m=audio 0", message);
851 Replace(kAttributeIceUfragVoice, "", message);
852 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 }
854 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800855 Replace("m=video 9", "m=video 0", message);
856 Replace(kAttributeIceUfragVideo, "", message);
857 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 }
859}
860
861// WebRtcSdpTest
862
863class WebRtcSdpTest : public testing::Test {
864 public:
865 WebRtcSdpTest()
866 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 05:04:57 -0800867#ifdef WEBRTC_ANDROID
868 webrtc::InitializeAndroidObjects();
869#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 // AudioContentDescription
871 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800872 StreamParams audio_stream;
873 audio_stream.id = kAudioTrackId1;
874 audio_stream.cname = kStream1Cname;
875 audio_stream.sync_label = kStreamLabel1;
876 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
877 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700878 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
879 audio_desc_->set_connection_address(audio_addr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
881
882 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800883 video_desc_ = CreateVideoContentDescription();
884 StreamParams video_stream;
885 video_stream.id = kVideoTrackId1;
886 video_stream.cname = kStream1Cname;
887 video_stream.sync_label = kStreamLabel1;
888 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
889 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
890 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
891 video_stream.ssrc_groups.push_back(ssrc_group);
892 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700893 rtc::SocketAddress video_addr("74.125.224.39", 3457);
894 video_desc_->set_connection_address(video_addr);
deadbeef9d3584c2016-02-16 17:54:10 -0800895 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800898 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
899 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
900 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
901 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
903 // v4 host
904 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000905 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000906 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000907 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
908 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000910 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000911 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
912 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000914 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000915 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
916 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000918 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000919 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
920 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921
922 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000923 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000924 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
925 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000926 cricket::LOCAL_PORT_TYPE,
927 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000929 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
930 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000931 cricket::LOCAL_PORT_TYPE,
932 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000934 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
935 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000936 cricket::LOCAL_PORT_TYPE,
937 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000939 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
940 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000941 cricket::LOCAL_PORT_TYPE,
942 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943
944 // stun
945 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
947 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000948 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
949 address_stun, kCandidatePriority, "", "",
950 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000951 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 candidate9.set_related_address(rel_address_stun);
953
954 address_stun.SetPort(port_stun++);
955 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000956 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
957 address_stun, kCandidatePriority, "", "",
958 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000959 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 candidate10.set_related_address(rel_address_stun);
961
962 // relay
963 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000965 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
966 address_relay, kCandidatePriority, "", "",
967 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000968 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000970 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
971 address_relay, kCandidatePriority, "", "",
972 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000973 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974
975 // voice
976 candidates_.push_back(candidate1);
977 candidates_.push_back(candidate2);
978 candidates_.push_back(candidate5);
979 candidates_.push_back(candidate6);
980 candidates_.push_back(candidate9);
981 candidates_.push_back(candidate10);
982
983 // video
984 candidates_.push_back(candidate3);
985 candidates_.push_back(candidate4);
986 candidates_.push_back(candidate7);
987 candidates_.push_back(candidate8);
988 candidates_.push_back(candidate11);
989 candidates_.push_back(candidate12);
990
991 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
992 0, candidate1));
993
994 // Set up JsepSessionDescription.
995 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
996 std::string mline_id;
997 int mline_index = 0;
998 for (size_t i = 0; i< candidates_.size(); ++i) {
999 // In this test, the audio m line index will be 0, and the video m line
1000 // will be 1.
1001 bool is_video = (i > 5);
1002 mline_id = is_video ? "video_content_name" : "audio_content_name";
1003 mline_index = is_video ? 1 : 0;
1004 JsepIceCandidate jice(mline_id,
1005 mline_index,
1006 candidates_.at(i));
1007 jdesc_.AddCandidate(&jice);
1008 }
1009 }
1010
deadbeef25ed4352016-12-12 18:37:36 -08001011 // Turns the existing reference description into a description using
1012 // a=bundle-only. This means no transport attributes and a 0 port value on
1013 // the m= sections not associated with the BUNDLE-tag.
1014 void MakeBundleOnlyDescription() {
1015 // Remove video candidates. JsepSessionDescription doesn't make it
1016 // simple.
1017 const IceCandidateCollection* video_candidates_collection =
1018 jdesc_.candidates(1);
1019 ASSERT_NE(nullptr, video_candidates_collection);
1020 std::vector<cricket::Candidate> video_candidates;
1021 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1022 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1023 c.set_transport_name("video_content_name");
1024 video_candidates.push_back(c);
1025 }
1026 jdesc_.RemoveCandidates(video_candidates);
1027
1028 // And the rest of the transport attributes.
1029 desc_.transport_infos()[1].description.ice_ufrag.clear();
1030 desc_.transport_infos()[1].description.ice_pwd.clear();
1031 desc_.transport_infos()[1].description.connection_role =
1032 cricket::CONNECTIONROLE_NONE;
1033
1034 // Set bundle-only flag.
1035 desc_.contents()[1].bundle_only = true;
1036
1037 // Add BUNDLE group.
1038 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1039 group.AddContentName(kAudioContentName);
1040 group.AddContentName(kVideoContentName);
1041 desc_.AddGroup(group);
1042
1043 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1044 jdesc_.session_version()));
1045 }
1046
deadbeef9d3584c2016-02-16 17:54:10 -08001047 // Turns the existing reference description into a plan B description,
1048 // with 2 audio tracks and 3 video tracks.
1049 void MakePlanBDescription() {
1050 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1051 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1052
1053 StreamParams audio_track_2;
1054 audio_track_2.id = kAudioTrackId2;
1055 audio_track_2.cname = kStream2Cname;
1056 audio_track_2.sync_label = kStreamLabel2;
1057 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1058 audio_desc_->AddStream(audio_track_2);
1059
1060 StreamParams video_track_2;
1061 video_track_2.id = kVideoTrackId2;
1062 video_track_2.cname = kStream2Cname;
1063 video_track_2.sync_label = kStreamLabel2;
1064 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1065 video_desc_->AddStream(video_track_2);
1066
1067 StreamParams video_track_3;
1068 video_track_3.id = kVideoTrackId3;
1069 video_track_3.cname = kStream2Cname;
1070 video_track_3.sync_label = kStreamLabel2;
1071 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1072 video_desc_->AddStream(video_track_3);
1073
1074 desc_.RemoveContentByName(kAudioContentName);
1075 desc_.RemoveContentByName(kVideoContentName);
1076 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1077 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1078
1079 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1080 jdesc_.session_version()));
1081 }
1082
1083 // Turns the existing reference description into a unified plan description,
1084 // with 2 audio tracks and 3 video tracks.
1085 void MakeUnifiedPlanDescription() {
1086 // Audio track 2.
1087 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1088 StreamParams audio_track_2;
1089 audio_track_2.id = kAudioTrackId2;
1090 audio_track_2.cname = kStream2Cname;
1091 audio_track_2.sync_label = kStreamLabel2;
1092 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1093 audio_desc_2->AddStream(audio_track_2);
1094 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1095 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1096 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001097 // Video track 2, in stream 2.
1098 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1099 StreamParams video_track_2;
1100 video_track_2.id = kVideoTrackId2;
1101 video_track_2.cname = kStream2Cname;
1102 video_track_2.sync_label = kStreamLabel2;
1103 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1104 video_desc_2->AddStream(video_track_2);
1105 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1106 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1107 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1108
1109 // Video track 3, in stream 2.
1110 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1111 StreamParams video_track_3;
1112 video_track_3.id = kVideoTrackId3;
1113 video_track_3.cname = kStream2Cname;
1114 video_track_3.sync_label = kStreamLabel2;
1115 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1116 video_desc_3->AddStream(video_track_3);
1117 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1118 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1119 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1120
1121 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1122 jdesc_.session_version()));
1123 }
1124
1125 // Creates an audio content description with no streams, and some default
1126 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 AudioContentDescription* CreateAudioContentDescription() {
1128 AudioContentDescription* audio = new AudioContentDescription();
1129 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001130 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1132 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1133 "dummy_session_params"));
1134 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001135 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001136 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001137 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1138 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 return audio;
1140 }
1141
deadbeef9d3584c2016-02-16 17:54:10 -08001142 // Creates a video content description with no streams, and some default
1143 // configuration.
1144 VideoContentDescription* CreateVideoContentDescription() {
1145 VideoContentDescription* video = new VideoContentDescription();
1146 video->AddCrypto(CryptoParams(
1147 1, "AES_CM_128_HMAC_SHA1_80",
1148 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1149 video->set_protocol(cricket::kMediaProtocolSavpf);
1150 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001151 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001152 return video;
1153 }
1154
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 template <class MCD>
1156 void CompareMediaContentDescription(const MCD* cd1,
1157 const MCD* cd2) {
1158 // type
1159 EXPECT_EQ(cd1->type(), cd1->type());
1160
1161 // content direction
1162 EXPECT_EQ(cd1->direction(), cd2->direction());
1163
1164 // rtcp_mux
1165 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1166
deadbeef13871492015-12-09 12:37:51 -08001167 // rtcp_reduced_size
1168 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 // cryptos
1171 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1172 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1173 ADD_FAILURE();
1174 return;
1175 }
1176 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1177 const CryptoParams c1 = cd1->cryptos().at(i);
1178 const CryptoParams c2 = cd2->cryptos().at(i);
1179 EXPECT_TRUE(c1.Matches(c2));
1180 EXPECT_EQ(c1.key_params, c2.key_params);
1181 EXPECT_EQ(c1.session_params, c2.session_params);
1182 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001185 // Use an equivalence class here, for old and new versions of the
1186 // protocol description.
1187 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001188 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1189 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1190 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001191 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:35 +00001192 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1193 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1194 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001195 } else {
1196 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1197 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198
1199 // codecs
1200 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1201
1202 // bandwidth
1203 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1204
1205 // streams
1206 EXPECT_EQ(cd1->streams(), cd2->streams());
1207
1208 // extmap
1209 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1210 cd2->rtp_header_extensions().size());
1211 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001212 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1213 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 EXPECT_EQ(ext1.uri, ext2.uri);
1215 EXPECT_EQ(ext1.id, ext2.id);
1216 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 }
1218
zstein4b2e0822017-02-17 19:48:38 -08001219 void CompareDataContentDescription(const DataContentDescription* dcd1,
1220 const DataContentDescription* dcd2) {
1221 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1222 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1223 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224
1225 void CompareSessionDescription(const SessionDescription& desc1,
1226 const SessionDescription& desc2) {
1227 // Compare content descriptions.
1228 if (desc1.contents().size() != desc2.contents().size()) {
1229 ADD_FAILURE();
1230 return;
1231 }
1232 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1233 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1234 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001235 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001237 EXPECT_EQ(c1.type, c2.type);
1238 EXPECT_EQ(c1.rejected, c2.rejected);
1239 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240
1241 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1242 if (IsAudioContent(&c1)) {
1243 const AudioContentDescription* acd1 =
1244 static_cast<const AudioContentDescription*>(c1.description);
1245 const AudioContentDescription* acd2 =
1246 static_cast<const AudioContentDescription*>(c2.description);
1247 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1248 }
1249
1250 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1251 if (IsVideoContent(&c1)) {
1252 const VideoContentDescription* vcd1 =
1253 static_cast<const VideoContentDescription*>(c1.description);
1254 const VideoContentDescription* vcd2 =
1255 static_cast<const VideoContentDescription*>(c2.description);
1256 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1257 }
1258
1259 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1260 if (IsDataContent(&c1)) {
1261 const DataContentDescription* dcd1 =
1262 static_cast<const DataContentDescription*>(c1.description);
1263 const DataContentDescription* dcd2 =
1264 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-17 19:48:38 -08001265 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 }
1267 }
1268
1269 // group
1270 const cricket::ContentGroups groups1 = desc1.groups();
1271 const cricket::ContentGroups groups2 = desc2.groups();
1272 EXPECT_EQ(groups1.size(), groups1.size());
1273 if (groups1.size() != groups2.size()) {
1274 ADD_FAILURE();
1275 return;
1276 }
1277 for (size_t i = 0; i < groups1.size(); ++i) {
1278 const cricket::ContentGroup group1 = groups1.at(i);
1279 const cricket::ContentGroup group2 = groups2.at(i);
1280 EXPECT_EQ(group1.semantics(), group2.semantics());
1281 const cricket::ContentNames names1 = group1.content_names();
1282 const cricket::ContentNames names2 = group2.content_names();
1283 EXPECT_EQ(names1.size(), names2.size());
1284 if (names1.size() != names2.size()) {
1285 ADD_FAILURE();
1286 return;
1287 }
1288 cricket::ContentNames::const_iterator iter1 = names1.begin();
1289 cricket::ContentNames::const_iterator iter2 = names2.begin();
1290 while (iter1 != names1.end()) {
1291 EXPECT_EQ(*iter1++, *iter2++);
1292 }
1293 }
1294
1295 // transport info
1296 const cricket::TransportInfos transports1 = desc1.transport_infos();
1297 const cricket::TransportInfos transports2 = desc2.transport_infos();
1298 EXPECT_EQ(transports1.size(), transports2.size());
1299 if (transports1.size() != transports2.size()) {
1300 ADD_FAILURE();
1301 return;
1302 }
1303 for (size_t i = 0; i < transports1.size(); ++i) {
1304 const cricket::TransportInfo transport1 = transports1.at(i);
1305 const cricket::TransportInfo transport2 = transports2.at(i);
1306 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 EXPECT_EQ(transport1.description.ice_ufrag,
1308 transport2.description.ice_ufrag);
1309 EXPECT_EQ(transport1.description.ice_pwd,
1310 transport2.description.ice_pwd);
1311 if (transport1.description.identity_fingerprint) {
1312 EXPECT_EQ(*transport1.description.identity_fingerprint,
1313 *transport2.description.identity_fingerprint);
1314 } else {
1315 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1316 transport2.description.identity_fingerprint.get());
1317 }
1318 EXPECT_EQ(transport1.description.transport_options,
1319 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 }
deadbeefc80741f2015-10-22 13:14:45 -07001321
1322 // global attributes
1323 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 }
1325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 bool CompareSessionDescription(
1327 const JsepSessionDescription& desc1,
1328 const JsepSessionDescription& desc2) {
1329 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1330 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1331 CompareSessionDescription(*desc1.description(), *desc2.description());
1332 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1333 return false;
1334 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1335 const IceCandidateCollection* cc1 = desc1.candidates(i);
1336 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001337 if (cc1->count() != cc2->count()) {
1338 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001340 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 for (size_t j = 0; j < cc1->count(); ++j) {
1342 const IceCandidateInterface* c1 = cc1->at(j);
1343 const IceCandidateInterface* c2 = cc2->at(j);
1344 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1345 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1346 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1347 }
1348 }
1349 return true;
1350 }
1351
1352 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1353 // them with invalid keywords so that the parser will just ignore them.
1354 bool RemoveCandidateUfragPwd(std::string* sdp) {
1355 const char ice_ufrag[] = "a=ice-ufrag";
1356 const char ice_ufragx[] = "a=xice-ufrag";
1357 const char ice_pwd[] = "a=ice-pwd";
1358 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001359 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001361 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 ice_pwdx, strlen(ice_pwdx), sdp);
1363 return true;
1364 }
1365
1366 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1367 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1368 const std::string& ufrag, const std::string& pwd) {
1369 std::string content_name;
1370 if (mline_index == 0) {
1371 content_name = kAudioContentName;
1372 } else if (mline_index == 1) {
1373 content_name = kVideoContentName;
1374 } else {
nissec80e7412017-01-11 05:56:46 -08001375 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 }
1377 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001378 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 SessionDescription* desc =
1380 const_cast<SessionDescription*>(jdesc->description());
1381 desc->RemoveTransportInfoByName(content_name);
1382 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1383 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1384 const IceCandidateCollection* cc = jdesc_.candidates(i);
1385 for (size_t j = 0; j < cc->count(); ++j) {
1386 if (cc->at(j)->sdp_mline_index() == mline_index) {
1387 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1388 ufrag);
1389 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1390 pwd);
1391 }
1392 }
1393 }
1394 return true;
1395 }
1396
1397 void AddIceOptions(const std::string& content_name,
1398 const std::vector<std::string>& transport_options) {
1399 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1400 cricket::TransportInfo transport_info =
1401 *(desc_.GetTransportInfoByName(content_name));
1402 desc_.RemoveTransportInfoByName(content_name);
1403 transport_info.description.transport_options = transport_options;
1404 desc_.AddTransportInfo(transport_info);
1405 }
1406
deadbeef3f7219b2015-12-28 15:17:14 -08001407 void SetIceUfragPwd(const std::string& content_name,
1408 const std::string& ice_ufrag,
1409 const std::string& ice_pwd) {
1410 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1411 cricket::TransportInfo transport_info =
1412 *(desc_.GetTransportInfoByName(content_name));
1413 desc_.RemoveTransportInfoByName(content_name);
1414 transport_info.description.ice_ufrag = ice_ufrag;
1415 transport_info.description.ice_pwd = ice_pwd;
1416 desc_.AddTransportInfo(transport_info);
1417 }
1418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 void AddFingerprint() {
1420 desc_.RemoveTransportInfoByName(kAudioContentName);
1421 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001422 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 kIdentityDigest,
1424 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001425 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1426 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001427 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1428 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001429 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1430 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1431 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001432 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1433 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001434 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 }
1436
1437 void AddExtmap() {
1438 audio_desc_ = static_cast<AudioContentDescription*>(
1439 audio_desc_->Copy());
1440 video_desc_ = static_cast<VideoContentDescription*>(
1441 video_desc_->Copy());
isheriff6f8d6862016-05-26 11:24:55 -07001442 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
1443 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 desc_.RemoveContentByName(kAudioContentName);
1445 desc_.RemoveContentByName(kVideoContentName);
1446 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1447 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1448 }
1449
1450 void RemoveCryptos() {
1451 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1452 video_desc_->set_cryptos(std::vector<CryptoParams>());
1453 }
1454
1455 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1456 audio_desc_->set_direction(direction);
1457 video_desc_->set_direction(direction);
1458 std::string new_sdp = kSdpFullString;
1459 ReplaceDirection(direction, &new_sdp);
1460
1461 if (!jdesc_.Initialize(desc_.Copy(),
1462 jdesc_.session_id(),
1463 jdesc_.session_version())) {
1464 return false;
1465 }
deadbeef9d3584c2016-02-16 17:54:10 -08001466 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 EXPECT_EQ(new_sdp, message);
1468 return true;
1469 }
1470
1471 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1472 audio_desc_ = static_cast<AudioContentDescription*>(
1473 audio_desc_->Copy());
1474 video_desc_ = static_cast<VideoContentDescription*>(
1475 video_desc_->Copy());
zhihuang38989e52017-03-21 11:04:53 -07001476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 desc_.RemoveContentByName(kAudioContentName);
1478 desc_.RemoveContentByName(kVideoContentName);
1479 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1480 audio_desc_);
1481 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1482 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001483 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1484 audio_rejected ? "" : kPwdVoice);
1485 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1486 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001487
1488 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1490
deadbeef3f7219b2015-12-28 15:17:14 -08001491 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001492 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001493 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_EQ(new_sdp, message);
1495 return true;
1496 }
1497
zstein4b2e0822017-02-17 19:48:38 -08001498 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001499 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001501 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001503 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001504 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001505 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1506 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001508 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1509 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 }
1511
1512 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001513 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514 data_desc_ = data.get();
1515
deadbeef67cf2c12016-04-13 10:07:16 -07001516 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 StreamParams data_stream;
1518 data_stream.id = kDataChannelMsid;
1519 data_stream.cname = kDataChannelCname;
1520 data_stream.sync_label = kDataChannelLabel;
1521 data_stream.ssrcs.push_back(kDataChannelSsrc);
1522 data_desc_->AddStream(data_stream);
1523 data_desc_->AddCrypto(CryptoParams(
1524 1, "AES_CM_128_HMAC_SHA1_80",
1525 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1526 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1527 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001528 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1529 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 }
1531
1532 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1533 std::string new_sdp = kSdpFullString;
1534 ReplaceDirection(direction, &new_sdp);
1535 JsepSessionDescription new_jdesc(kDummyString);
1536
1537 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1538
1539 audio_desc_->set_direction(direction);
1540 video_desc_->set_direction(direction);
1541 if (!jdesc_.Initialize(desc_.Copy(),
1542 jdesc_.session_id(),
1543 jdesc_.session_version())) {
1544 return false;
1545 }
1546 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1547 return true;
1548 }
1549
1550 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001551 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1553 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001555
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 audio_desc_ = static_cast<AudioContentDescription*>(
1557 audio_desc_->Copy());
1558 video_desc_ = static_cast<VideoContentDescription*>(
1559 video_desc_->Copy());
1560 desc_.RemoveContentByName(kAudioContentName);
1561 desc_.RemoveContentByName(kVideoContentName);
1562 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1563 audio_desc_);
1564 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1565 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001566 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1567 audio_rejected ? "" : kPwdVoice);
1568 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1569 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001570 JsepSessionDescription jdesc_no_candidates(kDummyString);
1571 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1572 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 return false;
1574 }
deadbeef3f7219b2015-12-28 15:17:14 -08001575 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 return true;
1577 }
1578
1579 void TestDeserializeExtmap(bool session_level, bool media_level) {
1580 AddExtmap();
1581 JsepSessionDescription new_jdesc("dummy");
1582 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1583 jdesc_.session_id(),
1584 jdesc_.session_version()));
1585 JsepSessionDescription jdesc_with_extmap("dummy");
1586 std::string sdp_with_extmap = kSdpString;
1587 if (session_level) {
1588 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1589 &sdp_with_extmap);
1590 }
1591 if (media_level) {
1592 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1593 &sdp_with_extmap);
1594 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1595 &sdp_with_extmap);
1596 }
1597 // The extmap can't be present at the same time in both session level and
1598 // media level.
1599 if (session_level && media_level) {
1600 SdpParseError error;
1601 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1602 &jdesc_with_extmap, &error));
1603 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1604 } else {
1605 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1606 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1607 }
1608 }
1609
1610 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1611 const std::string& name, int expected_value) {
1612 cricket::CodecParameterMap::const_iterator found = params.find(name);
1613 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001614 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 }
1616
1617 void TestDeserializeCodecParams(const CodecParams& params,
1618 JsepSessionDescription* jdesc_output) {
1619 std::string sdp =
1620 "v=0\r\n"
1621 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1622 "s=-\r\n"
1623 "t=0 0\r\n"
1624 // Include semantics for WebRTC Media Streams since it is supported by
1625 // this parser, and will be added to the SDP when serializing a session
1626 // description.
1627 "a=msid-semantic: WMS\r\n"
1628 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001629 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 // Pltype 111 listed before 103 and 104 in the map.
1631 "a=rtpmap:111 opus/48000/2\r\n"
1632 // Pltype 103 listed before 104.
1633 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001634 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001635 "a=fmtp:111 0-15,66,70\r\n"
1636 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001638 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001639 << "; sprop-stereo=" << params.sprop_stereo
1640 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001641 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 << "a=ptime:" << params.ptime << "\r\n"
1643 << "a=maxptime:" << params.max_ptime << "\r\n";
1644 sdp += os.str();
1645
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001646 os.clear();
1647 os.str("");
1648 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001649 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001650 << "a=rtpmap:99 VP8/90000\r\n"
1651 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001652 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001653 sdp += os.str();
1654
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 // Deserialize
1656 SdpParseError error;
1657 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1658
1659 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1660 ASSERT_TRUE(ac != NULL);
1661 const AudioContentDescription* acd =
1662 static_cast<const AudioContentDescription*>(ac->description);
1663 ASSERT_FALSE(acd->codecs().empty());
1664 cricket::AudioCodec opus = acd->codecs()[0];
1665 EXPECT_EQ("opus", opus.name);
1666 EXPECT_EQ(111, opus.id);
1667 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1668 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1669 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1670 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001671 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1672 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1674 cricket::AudioCodec codec = acd->codecs()[i];
1675 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1676 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001678
1679 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1680 ASSERT_TRUE(vc != NULL);
1681 const VideoContentDescription* vcd =
1682 static_cast<const VideoContentDescription*>(vc->description);
1683 ASSERT_FALSE(vcd->codecs().empty());
1684 cricket::VideoCodec vp8 = vcd->codecs()[0];
1685 EXPECT_EQ("VP8", vp8.name);
1686 EXPECT_EQ(99, vp8.id);
1687 cricket::VideoCodec rtx = vcd->codecs()[1];
1688 EXPECT_EQ("RTX", rtx.name);
1689 EXPECT_EQ(95, rtx.id);
1690 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 }
1692
1693 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1694 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001695 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 "v=0\r\n"
1697 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1698 "s=-\r\n"
1699 "t=0 0\r\n"
1700 // Include semantics for WebRTC Media Streams since it is supported by
1701 // this parser, and will be added to the SDP when serializing a session
1702 // description.
1703 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001704 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001705 "a=rtpmap:111 opus/48000/2\r\n";
1706 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 "m=video 3457 RTP/SAVPF 101\r\n"
1708 "a=rtpmap:101 VP8/90000\r\n"
1709 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001710 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001711 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001713 os << sdp_session_and_audio;
1714 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1715 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001717 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 // Deserialize
1719 SdpParseError error;
1720 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1721 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1722 ASSERT_TRUE(ac != NULL);
1723 const AudioContentDescription* acd =
1724 static_cast<const AudioContentDescription*>(ac->description);
1725 ASSERT_FALSE(acd->codecs().empty());
1726 cricket::AudioCodec opus = acd->codecs()[0];
1727 EXPECT_EQ(111, opus.id);
1728 EXPECT_TRUE(opus.HasFeedbackParam(
1729 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1730 cricket::kParamValueEmpty)));
1731
1732 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1733 ASSERT_TRUE(vc != NULL);
1734 const VideoContentDescription* vcd =
1735 static_cast<const VideoContentDescription*>(vc->description);
1736 ASSERT_FALSE(vcd->codecs().empty());
1737 cricket::VideoCodec vp8 = vcd->codecs()[0];
1738 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1739 vp8.name.c_str());
1740 EXPECT_EQ(101, vp8.id);
1741 EXPECT_TRUE(vp8.HasFeedbackParam(
1742 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1743 cricket::kParamValueEmpty)));
1744 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001745 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1746 cricket::kRtcpFbNackParamPli)));
1747 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1749 cricket::kParamValueEmpty)));
1750 EXPECT_TRUE(vp8.HasFeedbackParam(
1751 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1752 cricket::kRtcpFbCcmParamFir)));
1753 }
1754
1755 // Two SDP messages can mean the same thing but be different strings, e.g.
1756 // some of the lines can be serialized in different order.
1757 // However, a deserialized description can be compared field by field and has
1758 // no order. If deserializer has already been tested, serializing then
1759 // deserializing and comparing JsepSessionDescription will test
1760 // the serializer sufficiently.
deadbeef9d3584c2016-02-16 17:54:10 -08001761 void TestSerialize(const JsepSessionDescription& jdesc,
1762 bool unified_plan_sdp) {
1763 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 JsepSessionDescription jdesc_output_des(kDummyString);
1765 SdpParseError error;
1766 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1767 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1768 }
1769
zhihuang38989e52017-03-21 11:04:53 -07001770 // Calling 'Initialize' with a copy of the inner SessionDescription will
1771 // create a copy of the JsepSessionDescription without candidates. The
1772 // 'connection address' field, previously set from the candidates, must also
1773 // be reset.
1774 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1775 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1776 rtc::SocketAddress video_addr("0.0.0.0", 9);
1777 audio_desc_->set_connection_address(audio_addr);
1778 video_desc_->set_connection_address(video_addr);
1779 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1780 }
1781
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 protected:
1783 SessionDescription desc_;
1784 AudioContentDescription* audio_desc_;
1785 VideoContentDescription* video_desc_;
1786 DataContentDescription* data_desc_;
1787 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001788 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 JsepSessionDescription jdesc_;
1790};
1791
1792void TestMismatch(const std::string& string1, const std::string& string2) {
1793 int position = 0;
1794 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1795 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001796 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 break;
1798 }
1799 }
1800 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1801 << " character\n"
1802 << " 1: " << string1.substr(position, 20) << "\n"
1803 << " 2: " << string2.substr(position, 20) << "\n";
1804}
1805
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1807 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-16 17:54:10 -08001808 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 TestMismatch(std::string(kSdpFullString), message);
1810}
1811
1812TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1813 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-16 17:54:10 -08001814 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815}
1816
1817// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1818// the case in a DTLS offer.
1819TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1820 AddFingerprint();
1821 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001822 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001823 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824
1825 std::string sdp_with_fingerprint = kSdpString;
1826 InjectAfter(kAttributeIcePwdVoice,
1827 kFingerprint, &sdp_with_fingerprint);
1828 InjectAfter(kAttributeIcePwdVideo,
1829 kFingerprint, &sdp_with_fingerprint);
1830
1831 EXPECT_EQ(sdp_with_fingerprint, message);
1832}
1833
1834// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1835// be the case in a DTLS answer.
1836TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1837 AddFingerprint();
1838 RemoveCryptos();
1839 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001840 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-16 17:54:10 -08001841 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842
1843 std::string sdp_with_fingerprint = kSdpString;
1844 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1845 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1846 InjectAfter(kAttributeIcePwdVoice,
1847 kFingerprint, &sdp_with_fingerprint);
1848 InjectAfter(kAttributeIcePwdVideo,
1849 kFingerprint, &sdp_with_fingerprint);
1850
1851 EXPECT_EQ(sdp_with_fingerprint, message);
1852}
1853
1854TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1855 // JsepSessionDescription with desc but without candidates.
1856 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001857 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-16 17:54:10 -08001858 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 EXPECT_EQ(std::string(kSdpString), message);
1860}
1861
1862TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1863 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1864 group.AddContentName(kAudioContentName);
1865 group.AddContentName(kVideoContentName);
1866 desc_.AddGroup(group);
1867 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1868 jdesc_.session_id(),
1869 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001870 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 std::string sdp_with_bundle = kSdpFullString;
1872 InjectAfter(kSessionTime,
1873 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1874 &sdp_with_bundle);
1875 EXPECT_EQ(sdp_with_bundle, message);
1876}
1877
1878TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1879 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1880 GetFirstVideoContent(&desc_)->description);
1881 vcd->set_bandwidth(100 * 1000);
1882 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1883 GetFirstAudioContent(&desc_)->description);
1884 acd->set_bandwidth(50 * 1000);
1885 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1886 jdesc_.session_id(),
1887 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001888 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001890 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891 "b=AS:100\r\n",
1892 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:13 +00001893 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 "b=AS:50\r\n",
1895 &sdp_with_bandwidth);
1896 EXPECT_EQ(sdp_with_bandwidth, message);
1897}
1898
1899TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1900 std::vector<std::string> transport_options;
1901 transport_options.push_back(kIceOption1);
1902 transport_options.push_back(kIceOption3);
1903 AddIceOptions(kAudioContentName, transport_options);
1904 transport_options.clear();
1905 transport_options.push_back(kIceOption2);
1906 transport_options.push_back(kIceOption3);
1907 AddIceOptions(kVideoContentName, transport_options);
1908 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1909 jdesc_.session_id(),
1910 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08001911 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 std::string sdp_with_ice_options = kSdpFullString;
1913 InjectAfter(kAttributeIcePwdVoice,
1914 "a=ice-options:iceoption1 iceoption3\r\n",
1915 &sdp_with_ice_options);
1916 InjectAfter(kAttributeIcePwdVideo,
1917 "a=ice-options:iceoption2 iceoption3\r\n",
1918 &sdp_with_ice_options);
1919 EXPECT_EQ(sdp_with_ice_options, message);
1920}
1921
1922TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1923 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1924}
1925
1926TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1927 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1928}
1929
1930TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1931 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1932}
1933
1934TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1935 EXPECT_TRUE(TestSerializeRejected(true, false));
1936}
1937
1938TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1939 EXPECT_TRUE(TestSerializeRejected(false, true));
1940}
1941
1942TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1943 EXPECT_TRUE(TestSerializeRejected(true, true));
1944}
1945
1946TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1947 AddRtpDataChannel();
1948 JsepSessionDescription jsep_desc(kDummyString);
1949
zhihuang38989e52017-03-21 11:04:53 -07001950 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001951 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952
1953 std::string expected_sdp = kSdpString;
1954 expected_sdp.append(kSdpRtpDataChannelString);
1955 EXPECT_EQ(expected_sdp, message);
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08001959 bool use_sctpmap = true;
1960 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 JsepSessionDescription jsep_desc(kDummyString);
1962
zhihuang38989e52017-03-21 11:04:53 -07001963 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08001964 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
1966 std::string expected_sdp = kSdpString;
1967 expected_sdp.append(kSdpSctpDataChannelString);
1968 EXPECT_EQ(message, expected_sdp);
1969}
1970
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001971TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08001972 bool use_sctpmap = true;
1973 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001974 JsepSessionDescription jsep_desc(kDummyString);
zhihuang38989e52017-03-21 11:04:53 -07001975 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001976 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1977 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1978
1979 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07001980 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001981 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001982 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1983 dcdesc->AddOrReplaceCodec(codec);
1984
deadbeef9d3584c2016-02-16 17:54:10 -08001985 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001986
1987 std::string expected_sdp = kSdpString;
1988 expected_sdp.append(kSdpSctpDataChannelString);
1989
1990 char default_portstr[16];
1991 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001992 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001993 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001994 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1995 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001996 new_portstr, strlen(new_portstr),
1997 &expected_sdp);
1998
1999 EXPECT_EQ(expected_sdp, message);
2000}
2001
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002002TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
zhihuang38989e52017-03-21 11:04:53 -07002003 JsepSessionDescription jsep_desc(kDummyString);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002004 AddRtpDataChannel();
2005 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 11:04:53 -07002006 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-16 17:54:10 -08002007 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002008
2009 std::string expected_sdp = kSdpString;
2010 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002011 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002012 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 +00002013 "b=AS:100\r\n",
2014 &expected_sdp);
2015 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002016}
2017
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2019 AddExtmap();
2020 JsepSessionDescription desc_with_extmap("dummy");
zhihuang38989e52017-03-21 11:04:53 -07002021 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-16 17:54:10 -08002022 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023
2024 std::string sdp_with_extmap = kSdpString;
2025 InjectAfter("a=mid:audio_content_name\r\n",
2026 kExtmap, &sdp_with_extmap);
2027 InjectAfter("a=mid:video_content_name\r\n",
2028 kExtmap, &sdp_with_extmap);
2029
2030 EXPECT_EQ(sdp_with_extmap, message);
2031}
2032
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033TEST_F(WebRtcSdpTest, SerializeCandidates) {
2034 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002035 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002036
2037 Candidate candidate_with_ufrag(candidates_.front());
2038 candidate_with_ufrag.set_username("ABC");
2039 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2040 candidate_with_ufrag));
2041 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2042 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002043
2044 Candidate candidate_with_network_info(candidates_.front());
2045 candidate_with_network_info.set_network_id(1);
2046 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2047 candidate_with_network_info));
2048 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2049 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2050 candidate_with_network_info.set_network_cost(999);
2051 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2052 candidate_with_network_info));
2053 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2054 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2055 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056}
2057
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002058// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2059// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002060TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002061 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002062 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2063 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2064 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002065 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002066 std::unique_ptr<IceCandidateInterface> jcandidate(
2067 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002068
2069 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2070 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2071}
2072
htaa6b99442016-04-12 10:29:17 -07002073TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002074 cricket::VideoCodec h264_codec("H264");
2075 h264_codec.SetParam("profile-level-id", "42e01f");
2076 h264_codec.SetParam("level-asymmetry-allowed", "1");
2077 h264_codec.SetParam("packetization-mode", "1");
2078 video_desc_->AddCodec(h264_codec);
2079
htaa6b99442016-04-12 10:29:17 -07002080 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2081
2082 std::string message = webrtc::SdpSerialize(jdesc_, false);
2083 size_t after_pt = message.find(" H264/90000");
2084 ASSERT_NE(after_pt, std::string::npos);
2085 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2086 ASSERT_NE(before_pt, std::string::npos);
2087 before_pt += strlen("a=rtpmap:");
2088 std::string pt = message.substr(before_pt, after_pt - before_pt);
2089 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2090 std::string to_find = "a=fmtp:" + pt + " ";
2091 size_t fmtp_pos = message.find(to_find);
2092 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2093 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2094 ASSERT_NE(std::string::npos, fmtp_endpos);
2095 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2096 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2097 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2098 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002099 // Check that there are no spaces after semicolons.
2100 // https://bugs.webrtc.org/5793
2101 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002102}
2103
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2105 JsepSessionDescription jdesc(kDummyString);
2106 // Deserialize
2107 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2108 // Verify
2109 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2110}
2111
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002112TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2113 JsepSessionDescription jdesc(kDummyString);
2114 const char kSdpWithoutMline[] =
2115 "v=0\r\n"
2116 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2117 "s=-\r\n"
2118 "t=0 0\r\n"
2119 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2120 // Deserialize
2121 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2122 EXPECT_EQ(0u, jdesc.description()->contents().size());
2123}
2124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2126 JsepSessionDescription jdesc(kDummyString);
2127 std::string sdp_without_carriage_return = kSdpFullString;
2128 Replace("\r\n", "\n", &sdp_without_carriage_return);
2129 // Deserialize
2130 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2131 // Verify
2132 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2133}
2134
2135TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2136 // SessionDescription with desc but without candidates.
2137 JsepSessionDescription jdesc_no_candidates(kDummyString);
2138 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2139 kSessionId, kSessionVersion));
2140 JsepSessionDescription new_jdesc(kDummyString);
2141 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2142 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2143}
2144
2145TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2146 static const char kSdpNoRtpmapString[] =
2147 "v=0\r\n"
2148 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2149 "s=-\r\n"
2150 "t=0 0\r\n"
2151 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2152 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002153 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 // The rtpmap line for static payload codec is optional.
2155 "a=rtpmap:18 G729/16000\r\n"
2156 "a=rtpmap:103 ISAC/16000\r\n";
2157
2158 JsepSessionDescription jdesc(kDummyString);
2159 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2160 cricket::AudioContentDescription* audio =
2161 static_cast<AudioContentDescription*>(
2162 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2163 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002164 // The codecs in the AudioContentDescription should be in the same order as
2165 // the payload types (<fmt>s) on the m= line.
2166 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2167 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002168 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 EXPECT_EQ(ref_codecs, audio->codecs());
2170}
2171
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002172TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2173 static const char kSdpNoRtpmapString[] =
2174 "v=0\r\n"
2175 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2176 "s=-\r\n"
2177 "t=0 0\r\n"
2178 "m=audio 49232 RTP/AVP 18 103\r\n"
2179 "a=fmtp:18 annexb=yes\r\n"
2180 "a=rtpmap:103 ISAC/16000\r\n";
2181
2182 JsepSessionDescription jdesc(kDummyString);
2183 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2184 cricket::AudioContentDescription* audio =
2185 static_cast<AudioContentDescription*>(
2186 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2187
2188 cricket::AudioCodec g729 = audio->codecs()[0];
2189 EXPECT_EQ("G729", g729.name);
2190 EXPECT_EQ(8000, g729.clockrate);
2191 EXPECT_EQ(18, g729.id);
2192 cricket::CodecParameterMap::iterator found =
2193 g729.params.find("annexb");
2194 ASSERT_TRUE(found != g729.params.end());
2195 EXPECT_EQ(found->second, "yes");
2196
2197 cricket::AudioCodec isac = audio->codecs()[1];
2198 EXPECT_EQ("ISAC", isac.name);
2199 EXPECT_EQ(103, isac.id);
2200 EXPECT_EQ(16000, isac.clockrate);
2201}
2202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203// Ensure that we can deserialize SDP with a=fingerprint properly.
2204TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2205 // Add a DTLS a=fingerprint attribute to our session description.
2206 AddFingerprint();
2207 JsepSessionDescription new_jdesc(kDummyString);
2208 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2209 jdesc_.session_id(),
2210 jdesc_.session_version()));
2211
2212 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2213 std::string sdp_with_fingerprint = kSdpString;
2214 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2215 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2216 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2217 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2218}
2219
2220TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2221 JsepSessionDescription jdesc_with_bundle(kDummyString);
2222 std::string sdp_with_bundle = kSdpFullString;
2223 InjectAfter(kSessionTime,
2224 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2225 &sdp_with_bundle);
2226 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2227 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2228 group.AddContentName(kAudioContentName);
2229 group.AddContentName(kVideoContentName);
2230 desc_.AddGroup(group);
2231 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2232 jdesc_.session_id(),
2233 jdesc_.session_version()));
2234 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2235}
2236
2237TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2238 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2239 std::string sdp_with_bandwidth = kSdpFullString;
2240 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2241 "b=AS:100\r\n",
2242 &sdp_with_bandwidth);
2243 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2244 "b=AS:50\r\n",
2245 &sdp_with_bandwidth);
2246 EXPECT_TRUE(
2247 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2248 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2249 GetFirstVideoContent(&desc_)->description);
2250 vcd->set_bandwidth(100 * 1000);
2251 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2252 GetFirstAudioContent(&desc_)->description);
2253 acd->set_bandwidth(50 * 1000);
2254 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2255 jdesc_.session_id(),
2256 jdesc_.session_version()));
2257 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2258}
2259
2260TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2261 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2262 std::string sdp_with_ice_options = kSdpFullString;
2263 InjectAfter(kSessionTime,
2264 "a=ice-options:iceoption3\r\n",
2265 &sdp_with_ice_options);
2266 InjectAfter(kAttributeIcePwdVoice,
2267 "a=ice-options:iceoption1\r\n",
2268 &sdp_with_ice_options);
2269 InjectAfter(kAttributeIcePwdVideo,
2270 "a=ice-options:iceoption2\r\n",
2271 &sdp_with_ice_options);
2272 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2273 std::vector<std::string> transport_options;
2274 transport_options.push_back(kIceOption3);
2275 transport_options.push_back(kIceOption1);
2276 AddIceOptions(kAudioContentName, transport_options);
2277 transport_options.clear();
2278 transport_options.push_back(kIceOption3);
2279 transport_options.push_back(kIceOption2);
2280 AddIceOptions(kVideoContentName, transport_options);
2281 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2282 jdesc_.session_id(),
2283 jdesc_.session_version()));
2284 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2285}
2286
2287TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2288 // Remove the original ice-ufrag and ice-pwd
2289 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2290 std::string sdp_with_ufrag_pwd = kSdpFullString;
2291 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2292 // Add session level ufrag and pwd
2293 InjectAfter(kSessionTime,
2294 "a=ice-pwd:session+level+icepwd\r\n"
2295 "a=ice-ufrag:session+level+iceufrag\r\n",
2296 &sdp_with_ufrag_pwd);
2297 // Add media level ufrag and pwd for audio
2298 InjectAfter("a=mid:audio_content_name\r\n",
2299 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2300 &sdp_with_ufrag_pwd);
2301 // Update the candidate ufrag and pwd to the expected ones.
2302 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2303 "media+level+iceufrag", "media+level+icepwd"));
2304 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2305 "session+level+iceufrag", "session+level+icepwd"));
2306 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2307 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2308}
2309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2311 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2312}
2313
2314TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2315 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2316}
2317
2318TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2319 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2320}
2321
2322TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2323 EXPECT_TRUE(TestDeserializeRejected(true, false));
2324}
2325
2326TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2327 EXPECT_TRUE(TestDeserializeRejected(false, true));
2328}
2329
2330TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2331 EXPECT_TRUE(TestDeserializeRejected(true, true));
2332}
2333
2334// Tests that we can still handle the sdp uses mslabel and label instead of
2335// msid for backward compatibility.
2336TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002337 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 JsepSessionDescription jdesc(kDummyString);
2339 std::string sdp_without_msid = kSdpFullString;
2340 Replace("msid", "xmsid", &sdp_without_msid);
2341 // Deserialize
2342 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2343 // Verify
2344 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2345}
2346
2347TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2348 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2349
2350 std::string sdp = kSdpOneCandidate;
2351 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2352 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2353 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2354 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002355 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356
2357 // Candidate line without generation extension.
2358 sdp = kSdpOneCandidate;
2359 Replace(" generation 2", "", &sdp);
2360 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2361 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2362 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2363 Candidate expected = jcandidate_->candidate();
2364 expected.set_generation(0);
2365 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2366
honghaiza0c44ea2016-03-23 16:07:48 -07002367 // Candidate with network id and/or cost.
2368 sdp = kSdpOneCandidate;
2369 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2370 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2371 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2372 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2373 expected = jcandidate_->candidate();
2374 expected.set_network_id(2);
2375 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2376 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2377 // Add network cost
2378 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2379 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2380 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2381 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2382
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002383 sdp = kSdpTcpActiveCandidate;
2384 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2385 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002386 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002387 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2388 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2389 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002390 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2391 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002392 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2393 jcandidate_template->candidate()));
2394 sdp = kSdpTcpPassiveCandidate;
2395 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2396 sdp = kSdpTcpSOCandidate;
2397 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398}
2399
2400// This test verifies the deserialization of candidate-attribute
2401// as per RFC 5245. Candiate-attribute will be of the format
2402// candidate:<blah>. This format will be used when candidates
2403// are trickled.
2404TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2405 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2406
2407 std::string candidate_attribute = kRawCandidate;
2408 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2409 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2410 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2411 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2412 EXPECT_EQ(2u, jcandidate.candidate().generation());
2413
2414 // Candidate line without generation extension.
2415 candidate_attribute = kRawCandidate;
2416 Replace(" generation 2", "", &candidate_attribute);
2417 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2418 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2419 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2420 Candidate expected = jcandidate_->candidate();
2421 expected.set_generation(0);
2422 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2423
2424 // Candidate line without candidate:
2425 candidate_attribute = kRawCandidate;
2426 Replace("candidate:", "", &candidate_attribute);
2427 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2428
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002429 // Candidate line with IPV6 address.
2430 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2431}
2432
2433// This test verifies that the deserialization of an invalid candidate string
2434// fails.
2435TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2436 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2437
2438 std::string candidate_attribute = kRawCandidate;
2439 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002441
2442 candidate_attribute = kSdpOneCandidate;
2443 candidate_attribute.replace(0, 1, "x");
2444 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2445
2446 candidate_attribute = kRawCandidate;
2447 candidate_attribute.append("\r\n");
2448 candidate_attribute.append(kRawCandidate);
2449 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2450
2451 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452}
2453
2454TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2455 AddRtpDataChannel();
2456 JsepSessionDescription jdesc(kDummyString);
2457 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2458
2459 std::string sdp_with_data = kSdpString;
2460 sdp_with_data.append(kSdpRtpDataChannelString);
2461 JsepSessionDescription jdesc_output(kDummyString);
2462
2463 // Deserialize
2464 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2465 // Verify
2466 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2467}
2468
2469TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002470 bool use_sctpmap = true;
2471 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 JsepSessionDescription jdesc(kDummyString);
2473 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2474
2475 std::string sdp_with_data = kSdpString;
2476 sdp_with_data.append(kSdpSctpDataChannelString);
2477 JsepSessionDescription jdesc_output(kDummyString);
2478
lally@webrtc.org36300852015-02-24 20:19:35 +00002479 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2480 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2481 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2482
2483 // Verify with UDP/DTLS/SCTP.
2484 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2485 strlen(kDtlsSctp), kUdpDtlsSctp);
2486 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2487 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2488
2489 // Verify with TCP/DTLS/SCTP.
2490 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2491 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2493 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2494}
2495
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002496TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002497 bool use_sctpmap = false;
2498 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002499 JsepSessionDescription jdesc(kDummyString);
2500 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2501
2502 std::string sdp_with_data = kSdpString;
2503 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2504 JsepSessionDescription jdesc_output(kDummyString);
2505
lally@webrtc.org36300852015-02-24 20:19:35 +00002506 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002507 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2508 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002509
lally@webrtc.org36300852015-02-24 20:19:35 +00002510 // Verify with UDP/DTLS/SCTP.
2511 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2512 strlen(kDtlsSctp), kUdpDtlsSctp);
2513 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2514 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002515
lally@webrtc.org36300852015-02-24 20:19:35 +00002516 // Verify with TCP/DTLS/SCTP.
2517 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2518 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002519 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2520 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2521}
2522
lally69f57602015-10-08 10:15:04 -07002523TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002524 bool use_sctpmap = false;
2525 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 10:15:04 -07002526 JsepSessionDescription jdesc(kDummyString);
2527 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2528
2529 std::string sdp_with_data = kSdpString;
2530 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2531 JsepSessionDescription jdesc_output(kDummyString);
2532
2533 // Verify with DTLS/SCTP.
2534 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2535 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2536
2537 // Verify with UDP/DTLS/SCTP.
2538 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2539 strlen(kDtlsSctp), kUdpDtlsSctp);
2540 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2541 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2542
2543 // Verify with TCP/DTLS/SCTP.
2544 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2545 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2546 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2547 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2548}
2549
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002550// Test to check the behaviour if sctp-port is specified
2551// on the m= line and in a=sctp-port.
2552TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002553 bool use_sctpmap = true;
2554 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002555 JsepSessionDescription jdesc(kDummyString);
2556 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2557
2558 std::string sdp_with_data = kSdpString;
2559 // Append m= attributes
2560 sdp_with_data.append(kSdpSctpDataChannelString);
2561 // Append a=sctp-port attribute
2562 sdp_with_data.append("a=sctp-port 5000\r\n");
2563 JsepSessionDescription jdesc_output(kDummyString);
2564
2565 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2566}
2567
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002568// For crbug/344475.
2569TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2570 std::string sdp_with_data = kSdpString;
2571 sdp_with_data.append(kSdpSctpDataChannelString);
2572 // Remove the "\n" at the end.
2573 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2574 JsepSessionDescription jdesc_output(kDummyString);
2575
2576 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2577 // No crash is a pass.
2578}
2579
zstein4b2e0822017-02-17 19:48:38 -08002580void MutateJsepSctpPort(JsepSessionDescription& jdesc,
2581 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002582 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002583 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:02 +00002584 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2585 mutant->GetContentDescriptionByName(kDataContentName));
2586 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002587 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002588 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002589 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002590 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002591
2592 // note: mutant's owned by jdesc now.
2593 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2594 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002595}
2596
2597TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2598 bool use_sctpmap = true;
2599 AddSctpDataChannel(use_sctpmap);
2600
2601 // First setup the expected JsepSessionDescription.
2602 JsepSessionDescription jdesc(kDummyString);
2603 MutateJsepSctpPort(jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002604
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002605 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002606 std::string sdp_with_data = kSdpString;
2607 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002608 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2609 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2610 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:02 +00002611 JsepSessionDescription jdesc_output(kDummyString);
2612
2613 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2614 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002615}
2616
2617TEST_F(WebRtcSdpTest,
2618 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2619 bool use_sctpmap = false;
2620 AddSctpDataChannel(use_sctpmap);
2621
2622 JsepSessionDescription jdesc(kDummyString);
2623 MutateJsepSctpPort(jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002624
2625 // We need to test the deserialized JsepSessionDescription from
2626 // kSdpSctpDataChannelStringWithSctpPort for
2627 // draft-ietf-mmusic-sctp-sdp-07
2628 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002629 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002630 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002631 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2632 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2633 &sdp_with_data);
2634 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002635
2636 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2637 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002638}
2639
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002640TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002641 // We want to test that deserializing data content limits bandwidth
2642 // settings (it should never be greater than the default).
2643 // This should prevent someone from using unlimited data bandwidth through
2644 // JS and "breaking the Internet".
2645 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002646 std::string sdp_with_bandwidth = kSdpString;
2647 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2648 InjectAfter("a=mid:data_content_name\r\n",
2649 "b=AS:100\r\n",
2650 &sdp_with_bandwidth);
2651 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2652
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002653 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2654}
2655
2656TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002657 bool use_sctpmap = true;
2658 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002659 JsepSessionDescription jdesc(kDummyString);
2660 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2661 GetFirstDataContent(&desc_)->description);
2662 dcd->set_bandwidth(100 * 1000);
2663 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2664
2665 std::string sdp_with_bandwidth = kSdpString;
2666 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2667 InjectAfter("a=mid:data_content_name\r\n",
2668 "b=AS:100\r\n",
2669 &sdp_with_bandwidth);
2670 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2671
2672 // SCTP has congestion control, so we shouldn't limit the bandwidth
2673 // as we do for RTP.
2674 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002675 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2676}
2677
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2679 TestDeserializeExtmap(true, false);
2680}
2681
2682TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2683 TestDeserializeExtmap(false, true);
2684}
2685
2686TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2687 TestDeserializeExtmap(true, true);
2688}
2689
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002690TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2691 JsepSessionDescription jdesc(kDummyString);
2692 std::string sdp = kSdpFullString;
2693 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2694 // Deserialize
2695 SdpParseError error;
2696 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002697 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002698 EXPECT_EQ(lastline, error.line);
2699 EXPECT_EQ("Invalid SDP line.", error.description);
2700}
2701
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2703 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2704 std::string new_sdp = kSdpOneCandidate;
2705 Replace("udp", "unsupported_transport", &new_sdp);
2706 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2707 new_sdp = kSdpOneCandidate;
2708 Replace("udp", "uDP", &new_sdp);
2709 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2710 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2711 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2712 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2713}
2714
honghaiza54a0802015-12-16 18:37:23 -08002715TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002717 EXPECT_TRUE(
2718 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2720 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2721 Candidate ref_candidate = jcandidate_->candidate();
2722 ref_candidate.set_username("user_rtp");
2723 ref_candidate.set_password("password_rtp");
2724 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2725}
2726
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002727TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2728 JsepSessionDescription jdesc(kDummyString);
2729
2730 // Deserialize
2731 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2732
2733 // Verify
2734 cricket::AudioContentDescription* audio =
2735 static_cast<AudioContentDescription*>(
2736 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2737 EXPECT_TRUE(audio->conference_mode());
2738
2739 cricket::VideoContentDescription* video =
2740 static_cast<VideoContentDescription*>(
2741 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2742 EXPECT_TRUE(video->conference_mode());
2743}
2744
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2746 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002747 const char kSdpEmptyType[] = " =candidate";
2748 const char kSdpEqualAsPlus[] = "a+candidate";
2749 const char kSdpSpaceAfterEqual[] = "a= candidate";
2750 const char kSdpUpperType[] = "A=candidate";
2751 const char kSdpEmptyLine[] = "";
2752 const char kSdpMissingValue[] = "a=";
2753
2754 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 "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 +00002756 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 "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 +00002758 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759 "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 +00002760 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002761 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002762 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763
2764 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002765 ExpectParseFailure("v=", kSdpDestroyer);
2766 ExpectParseFailure("o=", kSdpDestroyer);
2767 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002769 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770
2771 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002772 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2773 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774
2775 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002776 ExpectParseFailure("a=candidate", kSdpEmptyType);
2777 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2778 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2779 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002780
2781 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2782 // because it's orthogonal to what we are replacing and hence
2783 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002784 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2785 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2786 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2787 ExpectParseFailure("a=sendrecv", kSdpMd5);
2788
2789 // Empty Line
2790 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2791 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002792}
2793
2794TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2795 // ssrc
2796 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002797 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002798 // crypto
2799 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2800 // rtpmap
2801 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2802 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2803 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2804 // candidate
2805 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2806 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2807 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2808 ExpectParseFailure("rport 2346", "rport badvalue");
2809 ExpectParseFailure("rport 2346 generation 2",
2810 "rport 2346 generation badvalue");
2811 // m line
2812 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2813 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2814
2815 // bandwidth
2816 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2817 "b=AS:badvalue\r\n",
2818 "b=AS:badvalue");
2819 // rtcp-fb
2820 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2821 "a=rtcp-fb:badvalue nack\r\n",
2822 "a=rtcp-fb:badvalue nack");
2823 // extmap
2824 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2825 "a=extmap:badvalue http://example.com\r\n",
2826 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827}
2828
2829TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2830 JsepSessionDescription jdesc_output(kDummyString);
2831
2832 const char kSdpWithReorderedPlTypesString[] =
2833 "v=0\r\n"
2834 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2835 "s=-\r\n"
2836 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002837 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2839 // in the map.
2840 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002841 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842
2843 // Deserialize
2844 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2845
2846 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2847 ASSERT_TRUE(ac != NULL);
2848 const AudioContentDescription* acd =
2849 static_cast<const AudioContentDescription*>(ac->description);
2850 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002851 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2852 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853 EXPECT_EQ(104, acd->codecs()[0].id);
2854}
2855
2856TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2857 JsepSessionDescription jdesc_output(kDummyString);
2858 CodecParams params;
2859 params.max_ptime = 40;
2860 params.ptime = 30;
2861 params.min_ptime = 10;
2862 params.sprop_stereo = 1;
2863 params.stereo = 1;
2864 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002865 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-16 17:54:10 -08002867 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868}
2869
2870TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2871 const bool kUseWildcard = false;
2872 JsepSessionDescription jdesc_output(kDummyString);
2873 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002874 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875}
2876
2877TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2878 const bool kUseWildcard = true;
2879 JsepSessionDescription jdesc_output(kDummyString);
2880 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-16 17:54:10 -08002881 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882}
2883
2884TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2885 JsepSessionDescription jdesc_output(kDummyString);
2886
2887 const char kSdpWithFmtpString[] =
2888 "v=0\r\n"
2889 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2890 "s=-\r\n"
2891 "t=0 0\r\n"
2892 "m=video 3457 RTP/SAVPF 120\r\n"
2893 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07002894 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2895
2896 // Deserialize
2897 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07002898 EXPECT_TRUE(
2899 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07002900
2901 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2902 ASSERT_TRUE(vc != NULL);
2903 const VideoContentDescription* vcd =
2904 static_cast<const VideoContentDescription*>(vc->description);
2905 ASSERT_FALSE(vcd->codecs().empty());
2906 cricket::VideoCodec vp8 = vcd->codecs()[0];
2907 EXPECT_EQ("VP8", vp8.name);
2908 EXPECT_EQ(120, vp8.id);
2909 cricket::CodecParameterMap::iterator found =
2910 vp8.params.find("x-google-min-bitrate");
2911 ASSERT_TRUE(found != vp8.params.end());
2912 EXPECT_EQ(found->second, "10");
2913 found = vp8.params.find("x-google-max-quantization");
2914 ASSERT_TRUE(found != vp8.params.end());
2915 EXPECT_EQ(found->second, "40");
2916}
2917
johan2d8d23e2016-06-03 01:22:42 -07002918TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2919 JsepSessionDescription jdesc_output(kDummyString);
2920
2921 const char kSdpWithFmtpString[] =
2922 "v=0\r\n"
2923 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2924 "s=-\r\n"
2925 "t=0 0\r\n"
2926 "m=video 49170 RTP/AVP 98\r\n"
2927 "a=rtpmap:98 H264/90000\r\n"
2928 "a=fmtp:98 profile-level-id=42A01E; "
2929 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2930
2931 // Deserialize.
2932 SdpParseError error;
2933 EXPECT_TRUE(
2934 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2935
2936 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2937 ASSERT_TRUE(vc != NULL);
2938 const VideoContentDescription* vcd =
2939 static_cast<const VideoContentDescription*>(vc->description);
2940 ASSERT_TRUE(vcd != NULL);
2941 ASSERT_FALSE(vcd->codecs().empty());
2942 cricket::VideoCodec h264 = vcd->codecs()[0];
2943 EXPECT_EQ("H264", h264.name);
2944 EXPECT_EQ(98, h264.id);
2945 cricket::CodecParameterMap::const_iterator found =
2946 h264.params.find("profile-level-id");
2947 ASSERT_TRUE(found != h264.params.end());
2948 EXPECT_EQ(found->second, "42A01E");
2949 found = h264.params.find("sprop-parameter-sets");
2950 ASSERT_TRUE(found != h264.params.end());
2951 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
2952}
2953
Donald Curtis0e07f922015-05-15 09:21:23 -07002954TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2955 JsepSessionDescription jdesc_output(kDummyString);
2956
2957 const char kSdpWithFmtpString[] =
2958 "v=0\r\n"
2959 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2960 "s=-\r\n"
2961 "t=0 0\r\n"
2962 "m=video 3457 RTP/SAVPF 120\r\n"
2963 "a=rtpmap:120 VP8/90000\r\n"
2964 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002965
2966 // Deserialize
2967 SdpParseError error;
2968 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2969 &error));
2970
2971 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2972 ASSERT_TRUE(vc != NULL);
2973 const VideoContentDescription* vcd =
2974 static_cast<const VideoContentDescription*>(vc->description);
2975 ASSERT_FALSE(vcd->codecs().empty());
2976 cricket::VideoCodec vp8 = vcd->codecs()[0];
2977 EXPECT_EQ("VP8", vp8.name);
2978 EXPECT_EQ(120, vp8.id);
2979 cricket::CodecParameterMap::iterator found =
2980 vp8.params.find("x-google-min-bitrate");
2981 ASSERT_TRUE(found != vp8.params.end());
2982 EXPECT_EQ(found->second, "10");
2983 found = vp8.params.find("x-google-max-quantization");
2984 ASSERT_TRUE(found != vp8.params.end());
2985 EXPECT_EQ(found->second, "40");
2986}
2987
ossuaa4b0772017-01-30 07:41:18 -08002988TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
2989 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2990 GetFirstAudioContent(&desc_)->description);
2991
2992 cricket::AudioCodecs codecs = acd->codecs();
2993 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
2994 acd->set_codecs(codecs);
2995
2996 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2997 jdesc_.session_id(),
2998 jdesc_.session_version()));
2999 std::string message = webrtc::SdpSerialize(jdesc_, false);
3000 std::string sdp_with_fmtp = kSdpFullString;
3001 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3002 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3003 &sdp_with_fmtp);
3004 EXPECT_EQ(sdp_with_fmtp, message);
3005}
3006
3007TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3008 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3009 GetFirstAudioContent(&desc_)->description);
3010
3011 cricket::AudioCodecs codecs = acd->codecs();
3012 codecs[0].params["stereo"] = "1";
3013 acd->set_codecs(codecs);
3014
3015 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3016 jdesc_.session_id(),
3017 jdesc_.session_version()));
3018 std::string message = webrtc::SdpSerialize(jdesc_, false);
3019 std::string sdp_with_fmtp = kSdpFullString;
3020 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3021 "a=fmtp:111 stereo=1\r\n",
3022 &sdp_with_fmtp);
3023 EXPECT_EQ(sdp_with_fmtp, message);
3024}
3025
3026TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3027 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3028 GetFirstAudioContent(&desc_)->description);
3029
3030 cricket::AudioCodecs codecs = acd->codecs();
3031 codecs[0].params["ptime"] = "20";
3032 codecs[0].params["maxptime"] = "120";
3033 acd->set_codecs(codecs);
3034
3035 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3036 jdesc_.session_id(),
3037 jdesc_.session_version()));
3038 std::string message = webrtc::SdpSerialize(jdesc_, false);
3039 std::string sdp_with_fmtp = kSdpFullString;
3040 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3041 "a=maxptime:120\r\n" // No comma here. String merging!
3042 "a=ptime:20\r\n",
3043 &sdp_with_fmtp);
3044 EXPECT_EQ(sdp_with_fmtp, message);
3045}
3046
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3048 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3049 GetFirstVideoContent(&desc_)->description);
3050
3051 cricket::VideoCodecs codecs = vcd->codecs();
3052 codecs[0].params["x-google-min-bitrate"] = "10";
3053 vcd->set_codecs(codecs);
3054
3055 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3056 jdesc_.session_id(),
3057 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003058 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059 std::string sdp_with_fmtp = kSdpFullString;
3060 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3061 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3062 &sdp_with_fmtp);
3063 EXPECT_EQ(sdp_with_fmtp, message);
3064}
3065
3066TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3067 JsepSessionDescription jdesc_with_icelite(kDummyString);
3068 std::string sdp_with_icelite = kSdpFullString;
3069 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3070 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3071 const cricket::TransportInfo* tinfo1 =
3072 desc->GetTransportInfoByName("audio_content_name");
3073 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3074 const cricket::TransportInfo* tinfo2 =
3075 desc->GetTransportInfoByName("video_content_name");
3076 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3077 InjectAfter(kSessionTime,
3078 "a=ice-lite\r\n",
3079 &sdp_with_icelite);
3080 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3081 desc = jdesc_with_icelite.description();
3082 const cricket::TransportInfo* atinfo =
3083 desc->GetTransportInfoByName("audio_content_name");
3084 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3085 const cricket::TransportInfo* vtinfo =
3086 desc->GetTransportInfoByName("video_content_name");
3087 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3088}
3089
3090// Verifies that the candidates in the input SDP are parsed and serialized
3091// correctly in the output SDP.
3092TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3093 std::string sdp_with_data = kSdpString;
3094 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3095 JsepSessionDescription jdesc_output(kDummyString);
3096
3097 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-16 17:54:10 -08003098 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003100
3101TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3102 AddFingerprint();
3103 TransportInfo audio_transport_info =
3104 *(desc_.GetTransportInfoByName(kAudioContentName));
3105 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3106 audio_transport_info.description.connection_role);
3107 audio_transport_info.description.connection_role =
3108 cricket::CONNECTIONROLE_ACTIVE;
3109
3110 TransportInfo video_transport_info =
3111 *(desc_.GetTransportInfoByName(kVideoContentName));
3112 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3113 video_transport_info.description.connection_role);
3114 video_transport_info.description.connection_role =
3115 cricket::CONNECTIONROLE_ACTIVE;
3116
3117 desc_.RemoveTransportInfoByName(kAudioContentName);
3118 desc_.RemoveTransportInfoByName(kVideoContentName);
3119
3120 desc_.AddTransportInfo(audio_transport_info);
3121 desc_.AddTransportInfo(video_transport_info);
3122
3123 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3124 jdesc_.session_id(),
3125 jdesc_.session_version()));
deadbeef9d3584c2016-02-16 17:54:10 -08003126 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003127 std::string sdp_with_dtlssetup = kSdpFullString;
3128
3129 // Fingerprint attribute is necessary to add DTLS setup attribute.
3130 InjectAfter(kAttributeIcePwdVoice,
3131 kFingerprint, &sdp_with_dtlssetup);
3132 InjectAfter(kAttributeIcePwdVideo,
3133 kFingerprint, &sdp_with_dtlssetup);
3134 // Now adding |setup| attribute.
3135 InjectAfter(kFingerprint,
3136 "a=setup:active\r\n", &sdp_with_dtlssetup);
3137 EXPECT_EQ(sdp_with_dtlssetup, message);
3138}
3139
3140TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3141 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3142 std::string sdp_with_dtlssetup = kSdpFullString;
3143 InjectAfter(kSessionTime,
3144 "a=setup:actpass\r\n",
3145 &sdp_with_dtlssetup);
3146 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3147 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3148 const cricket::TransportInfo* atinfo =
3149 desc->GetTransportInfoByName("audio_content_name");
3150 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3151 atinfo->description.connection_role);
3152 const cricket::TransportInfo* vtinfo =
3153 desc->GetTransportInfoByName("video_content_name");
3154 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3155 vtinfo->description.connection_role);
3156}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003157
3158// Verifies that the order of the serialized m-lines follows the order of the
3159// ContentInfo in SessionDescription, and vise versa for deserialization.
3160TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3161 JsepSessionDescription jdesc(kDummyString);
3162 const std::string media_content_sdps[3] = {
3163 kSdpAudioString,
3164 kSdpVideoString,
3165 kSdpSctpDataChannelString
3166 };
3167 const cricket::MediaType media_types[3] = {
3168 cricket::MEDIA_TYPE_AUDIO,
3169 cricket::MEDIA_TYPE_VIDEO,
3170 cricket::MEDIA_TYPE_DATA
3171 };
3172
3173 // Verifies all 6 permutations.
3174 for (size_t i = 0; i < 6; ++i) {
3175 size_t media_content_in_sdp[3];
3176 // The index of the first media content.
3177 media_content_in_sdp[0] = i / 2;
3178 // The index of the second media content.
3179 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3180 // The index of the third media content.
3181 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3182
3183 std::string sdp_string = kSdpSessionString;
3184 for (size_t i = 0; i < 3; ++i)
3185 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3186
3187 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3188 cricket::SessionDescription* desc = jdesc.description();
3189 EXPECT_EQ(3u, desc->contents().size());
3190
3191 for (size_t i = 0; i < 3; ++i) {
3192 const cricket::MediaContentDescription* mdesc =
3193 static_cast<const cricket::MediaContentDescription*>(
3194 desc->contents()[i].description);
3195 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3196 }
3197
deadbeef9d3584c2016-02-16 17:54:10 -08003198 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003199 EXPECT_EQ(sdp_string, serialized_sdp);
3200 }
3201}
deadbeef9d3584c2016-02-16 17:54:10 -08003202
deadbeef25ed4352016-12-12 18:37:36 -08003203TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3204 MakeBundleOnlyDescription();
3205 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 13:53:47 -08003206 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003207 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3208 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3209}
3210
deadbeef12771a12017-01-03 13:53:47 -08003211// The semantics of "a=bundle-only" are only defined when it's used in
3212// combination with a 0 port on the m= line. We should ignore it if used with a
3213// nonzero port.
3214TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3215 // Make the base bundle-only description but unset the bundle-only flag.
3216 MakeBundleOnlyDescription();
3217 jdesc_.description()->contents()[1].bundle_only = false;
3218
3219 std::string modified_sdp = kBundleOnlySdpFullString;
3220 Replace("m=video 0", "m=video 9", &modified_sdp);
3221 JsepSessionDescription deserialized_description(kDummyString);
3222 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3223 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003224}
3225
3226TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3227 MakeBundleOnlyDescription();
3228 TestSerialize(jdesc_, false);
3229}
3230
deadbeef9d3584c2016-02-16 17:54:10 -08003231TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3232 MakePlanBDescription();
3233
3234 JsepSessionDescription deserialized_description(kDummyString);
3235 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3236
3237 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3238}
3239
3240TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3241 MakePlanBDescription();
3242 TestSerialize(jdesc_, false);
3243}
3244
Taylor Brandstetter5de6b752016-03-09 17:02:30 -08003245// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3246// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3247// some extent). If we parse this, the Plan B msid attribute (which is more
3248// specific, since it's at the SSRC level) should take priority.
3249TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3250 MakePlanBDescription();
3251
3252 JsepSessionDescription deserialized_description(kDummyString);
3253 EXPECT_TRUE(
3254 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3255
3256 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3257}
3258
deadbeef9d3584c2016-02-16 17:54:10 -08003259TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3260 MakeUnifiedPlanDescription();
3261
3262 JsepSessionDescription deserialized_description(kDummyString);
3263 EXPECT_TRUE(
3264 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3265
3266 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3267}
3268
3269TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3270 MakeUnifiedPlanDescription();
3271 TestSerialize(jdesc_, true);
3272}
deadbeef7e146cb2016-09-28 10:04:34 -07003273
3274// Regression test for heap overflow bug:
3275// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3276TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003277 // The issue occurs when the sctp-port attribute is found in a video
3278 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003279 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003280 "v=0\r\n"
3281 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3282 "s=-\r\n"
3283 "t=0 0\r\n"
3284 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3285 "a=sctp-port 5000\r\n"
3286 "a=fmtp:108 foo=10\r\n";
3287
3288 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3289 "sctp-port");
3290}
deadbeefb2362572016-12-13 16:37:06 -08003291
3292// Regression test for integer overflow bug:
3293// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3294TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003295 // Bandwidth attribute is the max signed 32-bit int, which will get
3296 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003297 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003298 "v=0\r\n"
3299 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3300 "s=-\r\n"
3301 "t=0 0\r\n"
3302 "m=video 3457 RTP/SAVPF 120\r\n"
3303 "b=AS:2147483647\r\n"
3304 "foo=fail\r\n";
3305
3306 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3307}
deadbeef7bcdb692017-01-20 12:43:58 -08003308
3309// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3310// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3311// Regression test for:
3312// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3313TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3314 // Important piece is "ufrag foo pwd bar".
3315 static const char kSdpWithIceCredentialsInCandidateString[] =
3316 "v=0\r\n"
3317 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3318 "s=-\r\n"
3319 "t=0 0\r\n"
3320 "m=audio 9 RTP/SAVPF 111\r\n"
3321 "c=IN IP4 0.0.0.0\r\n"
3322 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3323 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3324 "a=rtpmap:111 opus/48000/2\r\n"
3325 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3326 "generation 2 ufrag foo pwd bar\r\n";
3327
3328 JsepSessionDescription jdesc_output(kDummyString);
3329 EXPECT_TRUE(
3330 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3331 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3332 ASSERT_NE(nullptr, candidates);
3333 ASSERT_EQ(1, candidates->count());
3334 cricket::Candidate c = candidates->at(0)->candidate();
3335 EXPECT_EQ("ufrag_voice", c.username());
3336 EXPECT_EQ("pwd_voice", c.password());
3337}
deadbeef90f1e1e2017-02-10 12:35:05 -08003338
3339// Test that SDP with an invalid port number in "a=candidate" lines is
3340// rejected, without crashing.
3341// Regression test for:
3342// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3343TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3344 static const char kSdpWithInvalidCandidatePort[] =
3345 "v=0\r\n"
3346 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3347 "s=-\r\n"
3348 "t=0 0\r\n"
3349 "m=audio 9 RTP/SAVPF 111\r\n"
3350 "c=IN IP4 0.0.0.0\r\n"
3351 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3352 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3353 "a=rtpmap:111 opus/48000/2\r\n"
3354 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3355 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3356
3357 JsepSessionDescription jdesc_output(kDummyString);
3358 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3359}
deadbeefa4549d62017-02-10 17:26:22 -08003360
3361// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3362// Regression test for:
3363// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3364TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3365 static const char kSdpWithMissingTrackId[] =
3366 "v=0\r\n"
3367 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3368 "s=-\r\n"
3369 "t=0 0\r\n"
3370 "m=audio 9 RTP/SAVPF 111\r\n"
3371 "c=IN IP4 0.0.0.0\r\n"
3372 "a=rtpmap:111 opus/48000/2\r\n"
3373 "a=msid:stream_id \r\n";
3374
3375 JsepSessionDescription jdesc_output(kDummyString);
3376 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3377}
3378
3379TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3380 static const char kSdpWithMissingStreamId[] =
3381 "v=0\r\n"
3382 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3383 "s=-\r\n"
3384 "t=0 0\r\n"
3385 "m=audio 9 RTP/SAVPF 111\r\n"
3386 "c=IN IP4 0.0.0.0\r\n"
3387 "a=rtpmap:111 opus/48000/2\r\n"
3388 "a=msid: track_id\r\n";
3389
3390 JsepSessionDescription jdesc_output(kDummyString);
3391 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3392}
zhihuang38989e52017-03-21 11:04:53 -07003393
3394// Tests that if both session-level address and media-level address exist, use
3395// the media-level address.
3396TEST_F(WebRtcSdpTest, ParseConnectionData) {
3397 JsepSessionDescription jsep_desc(kDummyString);
3398
3399 // Sesssion-level address.
3400 std::string sdp = kSdpFullString;
3401 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3402 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3403
3404 const auto& content1 = jsep_desc.description()->contents()[0];
3405 EXPECT_EQ("74.125.127.126:2345",
3406 static_cast<cricket::MediaContentDescription*>(content1.description)
3407 ->connection_address()
3408 .ToString());
3409 const auto& content2 = jsep_desc.description()->contents()[1];
3410 EXPECT_EQ("74.125.224.39:3457",
3411 static_cast<cricket::MediaContentDescription*>(content2.description)
3412 ->connection_address()
3413 .ToString());
3414}
3415
3416// Tests that the session-level connection address will be used if the media
3417// level-addresses are not specified.
3418TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
3419 JsepSessionDescription jsep_desc(kDummyString);
3420
3421 // Sesssion-level address.
3422 std::string sdp = kSdpString;
3423 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3424 // Remove the media level addresses.
3425 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3426 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3427 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3428
3429 const auto& content1 = jsep_desc.description()->contents()[0];
3430 EXPECT_EQ("192.168.0.3:9",
3431 static_cast<cricket::MediaContentDescription*>(content1.description)
3432 ->connection_address()
3433 .ToString());
3434 const auto& content2 = jsep_desc.description()->contents()[1];
3435 EXPECT_EQ("192.168.0.3:9",
3436 static_cast<cricket::MediaContentDescription*>(content2.description)
3437 ->connection_address()
3438 .ToString());
3439}
3440
3441TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
3442 JsepSessionDescription jsep_desc(kDummyString);
3443
3444 std::string sdp = kSdpString;
3445 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3446 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3447 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3448 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3449 &sdp);
3450 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3451 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3452 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3453 &sdp);
3454 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3455 const auto& content1 = jsep_desc.description()->contents()[0];
3456 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
3457 static_cast<cricket::MediaContentDescription*>(content1.description)
3458 ->connection_address()
3459 .ToString());
3460 const auto& content2 = jsep_desc.description()->contents()[1];
3461 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
3462 static_cast<cricket::MediaContentDescription*>(content2.description)
3463 ->connection_address()
3464 .ToString());
3465}
3466
3467// Test that the invalid or unsupprted connection data cannot be parsed.
3468TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
3469 JsepSessionDescription jsep_desc(kDummyString);
3470 std::string sdp = kSdpString;
3471 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3472
3473 // Unsupported multicast IPv4 address.
3474 sdp = kSdpFullString;
3475 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3476 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3477
3478 // Unsupported multicast IPv6 address.
3479 sdp = kSdpFullString;
3480 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3481 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3482
3483 // Mismatched address type.
3484 sdp = kSdpFullString;
3485 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3486 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3487
3488 sdp = kSdpFullString;
3489 Replace("c=IN IP4 74.125.224.39\r\n",
3490 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3491 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3492}
3493
3494TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
3495 JsepSessionDescription expected_jsep(kDummyString);
3496 MakeDescriptionWithoutCandidates(&expected_jsep);
3497 // Serialization.
3498 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3499 // Deserialization.
3500 JsepSessionDescription jdesc(kDummyString);
3501 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3502 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3503 jdesc.description()->GetContentByName(kAudioContentName)->description);
3504 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3505 jdesc.description()->GetContentByName(kVideoContentName)->description);
3506 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3507 audio_desc->connection_address().ToString());
3508 EXPECT_EQ(video_desc_->connection_address().ToString(),
3509 video_desc->connection_address().ToString());
3510}