blob: 831d23655af8ce50bfc4face80bdb20e18fa1d0f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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:369 */
10
kwibergd1fe2812016-04-27 13:47:2911#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3612#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Patrik Höglundaba85d12017-11-28 14:46:0819#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "p2p/base/p2pconstants.h"
21#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "rtc_base/stringencode.h"
26#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 07:04:2827
ossu7bb87ee2017-01-23 12:56:2528#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 04:47:3129#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 12:56:2530#endif
Mirko Bonadei92ea95e2017-09-15 04:47:3131#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:3632
33using cricket::AudioCodec;
34using cricket::AudioContentDescription;
35using cricket::Candidate;
36using cricket::ContentInfo;
37using cricket::CryptoParams;
38using cricket::ContentGroup;
39using cricket::DataCodec;
40using cricket::DataContentDescription;
41using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
42using cricket::ICE_CANDIDATE_COMPONENT_RTP;
43using cricket::kFecSsrcGroupSemantics;
44using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:3645using cricket::RELAY_PORT_TYPE;
46using cricket::SessionDescription;
Steve Anton5adfafd2017-12-21 00:34:0047using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:3648using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 18:24:5558using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 22:57:1059using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:3660using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 18:27:4161using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:3662using webrtc::SessionDescriptionInterface;
63
64typedef std::vector<AudioCodec> AudioCodecs;
65typedef std::vector<Candidate> Candidates;
66
Peter Boström0c4e06b2015-10-07 10:23:2167static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-18 03:48:3868static const char kDefaultSctpPortStr[] = "5000";
69static const uint16_t kUnusualSctpPort = 9556;
70static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:3671static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2172static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1473static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3674static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:1475static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3676static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2177static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:3678static 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";
jbauch5869f502017-06-29 19:31:3697static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36100
Peter Boström0c4e06b2015-10-07 10:23:21101static const uint8_t kIdentityDigest[] = {
102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36104
lally@webrtc.org34807282015-02-24 20:19:39105static const char kDtlsSctp[] = "DTLS/SCTP";
106static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
107static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35108
henrike@webrtc.org28e20752013-07-10 00:45:36109struct CodecParams {
110 int max_ptime;
111 int ptime;
112 int min_ptime;
113 int sprop_stereo;
114 int stereo;
115 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59116 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36117};
118
deadbeef9d3584c2016-02-17 01:54:10119// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
120// instead of "a=crypto", and have an explicit test for adding "a=crypto".
121// Currently it's the other way around.
122
henrike@webrtc.org28e20752013-07-10 00:45:36123// Reference sdp string
124static const char kSdpFullString[] =
125 "v=0\r\n"
126 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10129 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36130 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
131 "c=IN IP4 74.125.127.126\r\n"
132 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
133 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
142 "raddr 192.168.1.5 rport 2346 "
143 "generation 2\r\n"
144 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
145 "raddr 192.168.1.5 rport 2348 "
146 "generation 2\r\n"
147 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
148 "a=mid:audio_content_name\r\n"
149 "a=sendrecv\r\n"
150 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51151 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36152 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
153 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
154 "dummy_session_params\r\n"
155 "a=rtpmap:111 opus/48000/2\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41157 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36158 "a=ssrc:1 cname:stream_1_cname\r\n"
159 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
160 "a=ssrc:1 mslabel:local_stream_1\r\n"
161 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36162 "m=video 3457 RTP/SAVPF 120\r\n"
163 "c=IN IP4 74.125.224.39\r\n"
164 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
165 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
172 "generation 2\r\n"
173 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
174 "generation 2\r\n"
175 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
176 "generation 2\r\n"
177 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
178 "a=mid:video_content_name\r\n"
179 "a=sendrecv\r\n"
180 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
181 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
182 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10183 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36184 "a=ssrc:2 cname:stream_1_cname\r\n"
185 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
186 "a=ssrc:2 mslabel:local_stream_1\r\n"
187 "a=ssrc:2 label:video_track_id_1\r\n"
188 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10189 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36190 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10191 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36192
193// SDP reference string without the candidates.
194static const char kSdpString[] =
195 "v=0\r\n"
196 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
197 "s=-\r\n"
198 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10199 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22200 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06201 "c=IN IP4 0.0.0.0\r\n"
202 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36203 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
204 "a=mid:audio_content_name\r\n"
205 "a=sendrecv\r\n"
206 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51207 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36208 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
209 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
210 "dummy_session_params\r\n"
211 "a=rtpmap:111 opus/48000/2\r\n"
212 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41213 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36214 "a=ssrc:1 cname:stream_1_cname\r\n"
215 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
216 "a=ssrc:1 mslabel:local_stream_1\r\n"
217 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22218 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06219 "c=IN IP4 0.0.0.0\r\n"
220 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36221 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
222 "a=mid:video_content_name\r\n"
223 "a=sendrecv\r\n"
224 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
225 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
226 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10227 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36228 "a=ssrc:2 cname:stream_1_cname\r\n"
229 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
230 "a=ssrc:2 mslabel:local_stream_1\r\n"
231 "a=ssrc:2 label:video_track_id_1\r\n"
232 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10233 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36234 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10235 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36236
237static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22238 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06239 "c=IN IP4 0.0.0.0\r\n"
240 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36241 "a=ice-ufrag:ufrag_data\r\n"
242 "a=ice-pwd:pwd_data\r\n"
243 "a=mid:data_content_name\r\n"
244 "a=sendrecv\r\n"
245 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
246 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
247 "a=rtpmap:101 google-data/90000\r\n"
248 "a=ssrc:10 cname:data_channel_cname\r\n"
249 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
250 "a=ssrc:10 mslabel:data_channel\r\n"
251 "a=ssrc:10 label:data_channeld0\r\n";
252
253static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22254 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06255 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36256 "a=ice-ufrag:ufrag_data\r\n"
257 "a=ice-pwd:pwd_data\r\n"
258 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33259 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36260
lally@webrtc.orgec97c652015-02-24 20:18:48261// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56262static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26263 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
264 "a=max-message-size=100000\r\n"
265 "a=sctp-port 5000\r\n"
266 "c=IN IP4 0.0.0.0\r\n"
267 "a=ice-ufrag:ufrag_data\r\n"
268 "a=ice-pwd:pwd_data\r\n"
269 "a=mid:data_content_name\r\n";
270
lally69f57602015-10-08 17:15:04271static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
272 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
273 "a=max-message-size=100000\r\n"
274 "a=sctp-port:5000\r\n"
275 "c=IN IP4 0.0.0.0\r\n"
276 "a=ice-ufrag:ufrag_data\r\n"
277 "a=ice-pwd:pwd_data\r\n"
278 "a=mid:data_content_name\r\n";
279
henrike@webrtc.org28e20752013-07-10 00:45:36280static const char kSdpSctpDataChannelWithCandidatesString[] =
281 "m=application 2345 DTLS/SCTP 5000\r\n"
282 "c=IN IP4 74.125.127.126\r\n"
283 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
284 "generation 2\r\n"
285 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
286 "generation 2\r\n"
287 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
288 "raddr 192.168.1.5 rport 2346 "
289 "generation 2\r\n"
290 "a=ice-ufrag:ufrag_data\r\n"
291 "a=ice-pwd:pwd_data\r\n"
292 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33293 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36294
jiayl@webrtc.org9c16c392014-05-01 18:30:30295static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04296 "v=0\r\n"
297 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
298 "s=-\r\n"
299 "t=0 0\r\n"
300 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22301 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06302 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04303 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22304 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06305 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04306 "a=x-google-flag:conference\r\n";
307
jiayl@webrtc.orge7d47a12014-08-05 19:19:05308static const char kSdpSessionString[] =
309 "v=0\r\n"
310 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
311 "s=-\r\n"
312 "t=0 0\r\n"
313 "a=msid-semantic: WMS local_stream\r\n";
314
315static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22316 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06317 "c=IN IP4 0.0.0.0\r\n"
318 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05319 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
320 "a=mid:audio_content_name\r\n"
321 "a=sendrecv\r\n"
322 "a=rtpmap:111 opus/48000/2\r\n"
323 "a=ssrc:1 cname:stream_1_cname\r\n"
324 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
325 "a=ssrc:1 mslabel:local_stream\r\n"
326 "a=ssrc:1 label:audio_track_id_1\r\n";
327
328static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22329 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06330 "c=IN IP4 0.0.0.0\r\n"
331 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05332 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
333 "a=mid:video_content_name\r\n"
334 "a=sendrecv\r\n"
335 "a=rtpmap:120 VP8/90000\r\n"
336 "a=ssrc:2 cname:stream_1_cname\r\n"
337 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
338 "a=ssrc:2 mslabel:local_stream\r\n"
339 "a=ssrc:2 label:video_track_id_1\r\n";
340
deadbeef25ed4352016-12-13 02:37:36341// Reference sdp string using bundle-only.
342static const char kBundleOnlySdpFullString[] =
343 "v=0\r\n"
344 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
347 "a=group:BUNDLE audio_content_name video_content_name\r\n"
348 "a=msid-semantic: WMS local_stream_1\r\n"
349 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
350 "c=IN IP4 74.125.127.126\r\n"
351 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
352 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
359 "generation 2\r\n"
360 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
361 "raddr 192.168.1.5 rport 2346 "
362 "generation 2\r\n"
363 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
364 "raddr 192.168.1.5 rport 2348 "
365 "generation 2\r\n"
366 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
367 "a=mid:audio_content_name\r\n"
368 "a=sendrecv\r\n"
369 "a=rtcp-mux\r\n"
370 "a=rtcp-rsize\r\n"
371 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
372 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
373 "dummy_session_params\r\n"
374 "a=rtpmap:111 opus/48000/2\r\n"
375 "a=rtpmap:103 ISAC/16000\r\n"
376 "a=rtpmap:104 ISAC/32000\r\n"
377 "a=ssrc:1 cname:stream_1_cname\r\n"
378 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
379 "a=ssrc:1 mslabel:local_stream_1\r\n"
380 "a=ssrc:1 label:audio_track_id_1\r\n"
381 "m=video 0 RTP/SAVPF 120\r\n"
382 "c=IN IP4 0.0.0.0\r\n"
383 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
384 "a=bundle-only\r\n"
385 "a=mid:video_content_name\r\n"
386 "a=sendrecv\r\n"
387 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
388 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
389 "a=rtpmap:120 VP8/90000\r\n"
390 "a=ssrc-group:FEC 2 3\r\n"
391 "a=ssrc:2 cname:stream_1_cname\r\n"
392 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
393 "a=ssrc:2 mslabel:local_stream_1\r\n"
394 "a=ssrc:2 label:video_track_id_1\r\n"
395 "a=ssrc:3 cname:stream_1_cname\r\n"
396 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
397 "a=ssrc:3 mslabel:local_stream_1\r\n"
398 "a=ssrc:3 label:video_track_id_1\r\n";
399
deadbeef9d3584c2016-02-17 01:54:10400// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
401// tracks.
402static const char kPlanBSdpFullString[] =
403 "v=0\r\n"
404 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
405 "s=-\r\n"
406 "t=0 0\r\n"
407 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
408 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
409 "c=IN IP4 74.125.127.126\r\n"
410 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
411 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
418 "generation 2\r\n"
419 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
420 "raddr 192.168.1.5 rport 2346 "
421 "generation 2\r\n"
422 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
423 "raddr 192.168.1.5 rport 2348 "
424 "generation 2\r\n"
425 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
426 "a=mid:audio_content_name\r\n"
427 "a=sendrecv\r\n"
428 "a=rtcp-mux\r\n"
429 "a=rtcp-rsize\r\n"
430 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
431 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
432 "dummy_session_params\r\n"
433 "a=rtpmap:111 opus/48000/2\r\n"
434 "a=rtpmap:103 ISAC/16000\r\n"
435 "a=rtpmap:104 ISAC/32000\r\n"
436 "a=ssrc:1 cname:stream_1_cname\r\n"
437 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
438 "a=ssrc:1 mslabel:local_stream_1\r\n"
439 "a=ssrc:1 label:audio_track_id_1\r\n"
440 "a=ssrc:4 cname:stream_2_cname\r\n"
441 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
442 "a=ssrc:4 mslabel:local_stream_2\r\n"
443 "a=ssrc:4 label:audio_track_id_2\r\n"
444 "m=video 3457 RTP/SAVPF 120\r\n"
445 "c=IN IP4 74.125.224.39\r\n"
446 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
447 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
454 "generation 2\r\n"
455 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
456 "generation 2\r\n"
457 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
458 "generation 2\r\n"
459 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
460 "a=mid:video_content_name\r\n"
461 "a=sendrecv\r\n"
462 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
463 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
464 "a=rtpmap:120 VP8/90000\r\n"
465 "a=ssrc-group:FEC 2 3\r\n"
466 "a=ssrc:2 cname:stream_1_cname\r\n"
467 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
468 "a=ssrc:2 mslabel:local_stream_1\r\n"
469 "a=ssrc:2 label:video_track_id_1\r\n"
470 "a=ssrc:3 cname:stream_1_cname\r\n"
471 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
472 "a=ssrc:3 mslabel:local_stream_1\r\n"
473 "a=ssrc:3 label:video_track_id_1\r\n"
474 "a=ssrc:5 cname:stream_2_cname\r\n"
475 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
476 "a=ssrc:5 mslabel:local_stream_2\r\n"
477 "a=ssrc:5 label:video_track_id_2\r\n"
478 "a=ssrc:6 cname:stream_2_cname\r\n"
479 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
480 "a=ssrc:6 mslabel:local_stream_2\r\n"
481 "a=ssrc:6 label:video_track_id_3\r\n";
482
Taylor Brandstetter5de6b752016-03-10 01:02:30483// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
484// tracks, but with the unified plan "a=msid" attribute.
485static const char kPlanBSdpFullStringWithMsid[] =
486 "v=0\r\n"
487 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
488 "s=-\r\n"
489 "t=0 0\r\n"
490 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
491 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
492 "c=IN IP4 74.125.127.126\r\n"
493 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
494 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
497 "generation 2\r\n"
498 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
501 "generation 2\r\n"
502 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
503 "raddr 192.168.1.5 rport 2346 "
504 "generation 2\r\n"
505 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
506 "raddr 192.168.1.5 rport 2348 "
507 "generation 2\r\n"
508 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
509 "a=mid:audio_content_name\r\n"
510 "a=msid:local_stream_1 audio_track_id_1\r\n"
511 "a=sendrecv\r\n"
512 "a=rtcp-mux\r\n"
513 "a=rtcp-rsize\r\n"
514 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
515 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
516 "dummy_session_params\r\n"
517 "a=rtpmap:111 opus/48000/2\r\n"
518 "a=rtpmap:103 ISAC/16000\r\n"
519 "a=rtpmap:104 ISAC/32000\r\n"
520 "a=ssrc:1 cname:stream_1_cname\r\n"
521 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
522 "a=ssrc:1 mslabel:local_stream_1\r\n"
523 "a=ssrc:1 label:audio_track_id_1\r\n"
524 "a=ssrc:4 cname:stream_2_cname\r\n"
525 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
526 "a=ssrc:4 mslabel:local_stream_2\r\n"
527 "a=ssrc:4 label:audio_track_id_2\r\n"
528 "m=video 3457 RTP/SAVPF 120\r\n"
529 "c=IN IP4 74.125.224.39\r\n"
530 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
531 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
540 "generation 2\r\n"
541 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
542 "generation 2\r\n"
543 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
544 "a=mid:video_content_name\r\n"
545 "a=msid:local_stream_1 video_track_id_1\r\n"
546 "a=sendrecv\r\n"
547 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
548 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
549 "a=rtpmap:120 VP8/90000\r\n"
550 "a=ssrc-group:FEC 2 3\r\n"
551 "a=ssrc:2 cname:stream_1_cname\r\n"
552 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
553 "a=ssrc:2 mslabel:local_stream_1\r\n"
554 "a=ssrc:2 label:video_track_id_1\r\n"
555 "a=ssrc:3 cname:stream_1_cname\r\n"
556 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
557 "a=ssrc:3 mslabel:local_stream_1\r\n"
558 "a=ssrc:3 label:video_track_id_1\r\n"
559 "a=ssrc:5 cname:stream_2_cname\r\n"
560 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
561 "a=ssrc:5 mslabel:local_stream_2\r\n"
562 "a=ssrc:5 label:video_track_id_2\r\n"
563 "a=ssrc:6 cname:stream_2_cname\r\n"
564 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
565 "a=ssrc:6 mslabel:local_stream_2\r\n"
566 "a=ssrc:6 label:video_track_id_3\r\n";
567
deadbeef9d3584c2016-02-17 01:54:10568// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
569// tracks.
570static const char kUnifiedPlanSdpFullString[] =
571 "v=0\r\n"
572 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
573 "s=-\r\n"
574 "t=0 0\r\n"
575 "a=msid-semantic: WMS local_stream_1\r\n"
576 // Audio track 1, stream 1 (with candidates).
577 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
578 "c=IN IP4 74.125.127.126\r\n"
579 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
580 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
581 "generation 2\r\n"
582 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
583 "generation 2\r\n"
584 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
585 "generation 2\r\n"
586 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
587 "generation 2\r\n"
588 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
589 "raddr 192.168.1.5 rport 2346 "
590 "generation 2\r\n"
591 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
592 "raddr 192.168.1.5 rport 2348 "
593 "generation 2\r\n"
594 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
595 "a=mid:audio_content_name\r\n"
596 "a=msid:local_stream_1 audio_track_id_1\r\n"
597 "a=sendrecv\r\n"
598 "a=rtcp-mux\r\n"
599 "a=rtcp-rsize\r\n"
600 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
601 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
602 "dummy_session_params\r\n"
603 "a=rtpmap:111 opus/48000/2\r\n"
604 "a=rtpmap:103 ISAC/16000\r\n"
605 "a=rtpmap:104 ISAC/32000\r\n"
606 "a=ssrc:1 cname:stream_1_cname\r\n"
607 // Video track 1, stream 1 (with candidates).
608 "m=video 3457 RTP/SAVPF 120\r\n"
609 "c=IN IP4 74.125.224.39\r\n"
610 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
611 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
616 "generation 2\r\n"
617 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
618 "generation 2\r\n"
619 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
620 "generation 2\r\n"
621 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
622 "generation 2\r\n"
623 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
624 "a=mid:video_content_name\r\n"
625 "a=msid:local_stream_1 video_track_id_1\r\n"
626 "a=sendrecv\r\n"
627 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
628 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
629 "a=rtpmap:120 VP8/90000\r\n"
630 "a=ssrc-group:FEC 2 3\r\n"
631 "a=ssrc:2 cname:stream_1_cname\r\n"
632 "a=ssrc:3 cname:stream_1_cname\r\n"
633 // Audio track 2, stream 2.
634 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
635 "c=IN IP4 0.0.0.0\r\n"
636 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
637 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
638 "a=mid:audio_content_name_2\r\n"
639 "a=msid:local_stream_2 audio_track_id_2\r\n"
640 "a=sendrecv\r\n"
641 "a=rtcp-mux\r\n"
642 "a=rtcp-rsize\r\n"
643 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
644 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
645 "dummy_session_params\r\n"
646 "a=rtpmap:111 opus/48000/2\r\n"
647 "a=rtpmap:103 ISAC/16000\r\n"
648 "a=rtpmap:104 ISAC/32000\r\n"
649 "a=ssrc:4 cname:stream_2_cname\r\n"
650 // Video track 2, stream 2.
651 "m=video 9 RTP/SAVPF 120\r\n"
652 "c=IN IP4 0.0.0.0\r\n"
653 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
654 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
655 "a=mid:video_content_name_2\r\n"
656 "a=msid:local_stream_2 video_track_id_2\r\n"
657 "a=sendrecv\r\n"
658 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
659 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
660 "a=rtpmap:120 VP8/90000\r\n"
661 "a=ssrc:5 cname:stream_2_cname\r\n"
662 // Video track 3, stream 2.
663 "m=video 9 RTP/SAVPF 120\r\n"
664 "c=IN IP4 0.0.0.0\r\n"
665 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
666 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
667 "a=mid:video_content_name_3\r\n"
668 "a=msid:local_stream_2 video_track_id_3\r\n"
669 "a=sendrecv\r\n"
670 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
671 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
672 "a=rtpmap:120 VP8/90000\r\n"
673 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36674
675// One candidate reference string as per W3c spec.
676// candidate:<blah> not a=candidate:<blah>CRLF
677static const char kRawCandidate[] =
678 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
679// One candidate reference string.
680static const char kSdpOneCandidate[] =
681 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
682 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15683
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20684static const char kSdpTcpActiveCandidate[] =
685 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
686 "tcptype active generation 2";
687static const char kSdpTcpPassiveCandidate[] =
688 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
689 "tcptype passive generation 2";
690static const char kSdpTcpSOCandidate[] =
691 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
692 "tcptype so generation 2";
693static const char kSdpTcpInvalidCandidate[] =
694 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
695 "tcptype invalid generation 2";
696
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15697// One candidate reference string with IPV6 address.
698static const char kRawIPV6Candidate[] =
699 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 19:04:36700 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36701
702// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23703static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36704 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23705 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36706
707// Session id and version
708static const char kSessionId[] = "18446744069414584320";
709static const char kSessionVersion[] = "18446462598732840960";
710
deadbeef9d3584c2016-02-17 01:54:10711// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36712static const char kIceOption1[] = "iceoption1";
713static const char kIceOption2[] = "iceoption2";
714static const char kIceOption3[] = "iceoption3";
715
deadbeef9d3584c2016-02-17 01:54:10716// ICE ufrags/passwords.
717static const char kUfragVoice[] = "ufrag_voice";
718static const char kPwdVoice[] = "pwd_voice";
719static const char kUfragVideo[] = "ufrag_video";
720static const char kPwdVideo[] = "pwd_video";
721static const char kUfragData[] = "ufrag_data";
722static const char kPwdData[] = "pwd_data";
723
724// Extra ufrags/passwords for extra unified plan m= sections.
725static const char kUfragVoice2[] = "ufrag_voice_2";
726static const char kPwdVoice2[] = "pwd_voice_2";
727static const char kUfragVideo2[] = "ufrag_video_2";
728static const char kPwdVideo2[] = "pwd_video_2";
729static const char kUfragVideo3[] = "ufrag_video_3";
730static const char kPwdVideo3[] = "pwd_video_3";
731
henrike@webrtc.org28e20752013-07-10 00:45:36732// Content name
733static const char kAudioContentName[] = "audio_content_name";
734static const char kVideoContentName[] = "video_content_name";
735static const char kDataContentName[] = "data_content_name";
736
deadbeef9d3584c2016-02-17 01:54:10737// Extra content names for extra unified plan m= sections.
738static const char kAudioContentName2[] = "audio_content_name_2";
739static const char kVideoContentName2[] = "video_content_name_2";
740static const char kVideoContentName3[] = "video_content_name_3";
741
henrike@webrtc.org28e20752013-07-10 00:45:36742// MediaStream 1
743static const char kStreamLabel1[] = "local_stream_1";
744static const char kStream1Cname[] = "stream_1_cname";
745static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21746static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36747static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10748static const uint32_t kVideoTrack1Ssrc1 = 2;
749static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36750
751// MediaStream 2
752static const char kStreamLabel2[] = "local_stream_2";
753static const char kStream2Cname[] = "stream_2_cname";
754static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21755static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10756static const char kVideoTrackId2[] = "video_track_id_2";
757static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36758static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10759static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36760
761// DataChannel
762static const char kDataChannelLabel[] = "data_channel";
763static const char kDataChannelMsid[] = "data_channeld0";
764static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 10:23:21765static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36766
767// Candidate
768static const char kDummyMid[] = "dummy_mid";
769static const int kDummyIndex = 123;
770
771// Misc
Steve Antona3a92c22017-12-07 18:27:41772static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36773
774// Helper functions
775
776static bool SdpDeserialize(const std::string& message,
777 JsepSessionDescription* jdesc) {
778 return webrtc::SdpDeserialize(message, jdesc, NULL);
779}
780
781static bool SdpDeserializeCandidate(const std::string& message,
782 JsepIceCandidate* candidate) {
783 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
784}
785
786// Add some extra |newlines| to the |message| after |line|.
787static void InjectAfter(const std::string& line,
788 const std::string& newlines,
789 std::string* message) {
790 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52791 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36792 tmp.c_str(), tmp.length(), message);
793}
794
795static void Replace(const std::string& line,
796 const std::string& newlines,
797 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52798 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36799 newlines.c_str(), newlines.length(), message);
800}
801
wu@webrtc.org5e760e72014-04-02 23:19:09802// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
803// message.
804static void ExpectParseFailure(const std::string& bad_sdp,
805 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 18:27:41806 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36807 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09808 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36809 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09810 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
811}
812
813// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
814static void ExpectParseFailure(const char* good_part, const char* bad_part) {
815 std::string bad_sdp = kSdpFullString;
816 Replace(good_part, bad_part, &bad_sdp);
817 ExpectParseFailure(bad_sdp, bad_part);
818}
819
820// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
821static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
822 const std::string& newlines,
823 const std::string& bad_part) {
824 std::string bad_sdp = kSdpFullString;
825 InjectAfter(injectpoint, newlines, &bad_sdp);
826 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36827}
828
Steve Anton4e70a722017-11-28 22:57:10829static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36830 std::string* message) {
831 std::string new_direction;
832 switch (direction) {
Steve Anton4e70a722017-11-28 22:57:10833 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36834 new_direction = "a=inactive";
835 break;
Steve Anton4e70a722017-11-28 22:57:10836 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36837 new_direction = "a=sendonly";
838 break;
Steve Anton4e70a722017-11-28 22:57:10839 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36840 new_direction = "a=recvonly";
841 break;
Steve Anton4e70a722017-11-28 22:57:10842 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36843 default:
844 new_direction = "a=sendrecv";
845 break;
846 }
847 Replace("a=sendrecv", new_direction, message);
848}
849
850static void ReplaceRejected(bool audio_rejected, bool video_rejected,
851 std::string* message) {
852 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14853 Replace("m=audio 9", "m=audio 0", message);
854 Replace(kAttributeIceUfragVoice, "", message);
855 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36856 }
857 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14858 Replace("m=video 9", "m=video 0", message);
859 Replace(kAttributeIceUfragVideo, "", message);
860 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36861 }
862}
863
864// WebRtcSdpTest
865
866class WebRtcSdpTest : public testing::Test {
867 public:
Steve Antona3a92c22017-12-07 18:27:41868 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 13:04:57869#ifdef WEBRTC_ANDROID
870 webrtc::InitializeAndroidObjects();
871#endif
henrike@webrtc.org28e20752013-07-10 00:45:36872 // AudioContentDescription
873 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:10874 StreamParams audio_stream;
875 audio_stream.id = kAudioTrackId1;
876 audio_stream.cname = kStream1Cname;
877 audio_stream.sync_label = kStreamLabel1;
878 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
879 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 18:04:53880 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
881 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-21 00:34:00882 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36883
884 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:10885 video_desc_ = CreateVideoContentDescription();
886 StreamParams video_stream;
887 video_stream.id = kVideoTrackId1;
888 video_stream.cname = kStream1Cname;
889 video_stream.sync_label = kStreamLabel1;
890 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
891 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
892 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
893 video_stream.ssrc_groups.push_back(ssrc_group);
894 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 18:04:53895 rtc::SocketAddress video_addr("74.125.224.39", 3457);
896 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-21 00:34:00897 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36898
899 // TransportInfo
deadbeef9d3584c2016-02-17 01:54:10900 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
901 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
902 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
903 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36904
905 // v4 host
906 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52907 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07908 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31909 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
910 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36911 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07912 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31913 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
914 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36915 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07916 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31917 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
918 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36919 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07920 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31921 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
922 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36923
924 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52925 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07926 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
927 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31928 cricket::LOCAL_PORT_TYPE,
929 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36930 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07931 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
932 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31933 cricket::LOCAL_PORT_TYPE,
934 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36935 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07936 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
937 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31938 cricket::LOCAL_PORT_TYPE,
939 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36940 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07941 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
942 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31943 cricket::LOCAL_PORT_TYPE,
944 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36945
946 // stun
947 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52948 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
949 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07950 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
951 address_stun, kCandidatePriority, "", "",
952 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31953 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36954 candidate9.set_related_address(rel_address_stun);
955
956 address_stun.SetPort(port_stun++);
957 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07958 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
959 address_stun, kCandidatePriority, "", "",
960 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31961 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36962 candidate10.set_related_address(rel_address_stun);
963
964 // relay
965 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52966 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07967 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
968 address_relay, kCandidatePriority, "", "",
969 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31970 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36971 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07972 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
973 address_relay, kCandidatePriority, "", "",
974 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31975 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36976
977 // voice
978 candidates_.push_back(candidate1);
979 candidates_.push_back(candidate2);
980 candidates_.push_back(candidate5);
981 candidates_.push_back(candidate6);
982 candidates_.push_back(candidate9);
983 candidates_.push_back(candidate10);
984
985 // video
986 candidates_.push_back(candidate3);
987 candidates_.push_back(candidate4);
988 candidates_.push_back(candidate7);
989 candidates_.push_back(candidate8);
990 candidates_.push_back(candidate11);
991 candidates_.push_back(candidate12);
992
993 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
994 0, candidate1));
995
996 // Set up JsepSessionDescription.
997 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
998 std::string mline_id;
999 int mline_index = 0;
1000 for (size_t i = 0; i< candidates_.size(); ++i) {
1001 // In this test, the audio m line index will be 0, and the video m line
1002 // will be 1.
1003 bool is_video = (i > 5);
1004 mline_id = is_video ? "video_content_name" : "audio_content_name";
1005 mline_index = is_video ? 1 : 0;
1006 JsepIceCandidate jice(mline_id,
1007 mline_index,
1008 candidates_.at(i));
1009 jdesc_.AddCandidate(&jice);
1010 }
1011 }
1012
deadbeef25ed4352016-12-13 02:37:361013 // Turns the existing reference description into a description using
1014 // a=bundle-only. This means no transport attributes and a 0 port value on
1015 // the m= sections not associated with the BUNDLE-tag.
1016 void MakeBundleOnlyDescription() {
1017 // Remove video candidates. JsepSessionDescription doesn't make it
1018 // simple.
1019 const IceCandidateCollection* video_candidates_collection =
1020 jdesc_.candidates(1);
1021 ASSERT_NE(nullptr, video_candidates_collection);
1022 std::vector<cricket::Candidate> video_candidates;
1023 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1024 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1025 c.set_transport_name("video_content_name");
1026 video_candidates.push_back(c);
1027 }
1028 jdesc_.RemoveCandidates(video_candidates);
1029
1030 // And the rest of the transport attributes.
1031 desc_.transport_infos()[1].description.ice_ufrag.clear();
1032 desc_.transport_infos()[1].description.ice_pwd.clear();
1033 desc_.transport_infos()[1].description.connection_role =
1034 cricket::CONNECTIONROLE_NONE;
1035
1036 // Set bundle-only flag.
1037 desc_.contents()[1].bundle_only = true;
1038
1039 // Add BUNDLE group.
1040 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1041 group.AddContentName(kAudioContentName);
1042 group.AddContentName(kVideoContentName);
1043 desc_.AddGroup(group);
1044
1045 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1046 jdesc_.session_version()));
1047 }
1048
deadbeef9d3584c2016-02-17 01:54:101049 // Turns the existing reference description into a plan B description,
1050 // with 2 audio tracks and 3 video tracks.
1051 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 23:14:301052 audio_desc_ = audio_desc_->Copy();
1053 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-17 01:54:101054
1055 StreamParams audio_track_2;
1056 audio_track_2.id = kAudioTrackId2;
1057 audio_track_2.cname = kStream2Cname;
1058 audio_track_2.sync_label = kStreamLabel2;
1059 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1060 audio_desc_->AddStream(audio_track_2);
1061
1062 StreamParams video_track_2;
1063 video_track_2.id = kVideoTrackId2;
1064 video_track_2.cname = kStream2Cname;
1065 video_track_2.sync_label = kStreamLabel2;
1066 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1067 video_desc_->AddStream(video_track_2);
1068
1069 StreamParams video_track_3;
1070 video_track_3.id = kVideoTrackId3;
1071 video_track_3.cname = kStream2Cname;
1072 video_track_3.sync_label = kStreamLabel2;
1073 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1074 video_desc_->AddStream(video_track_3);
1075
1076 desc_.RemoveContentByName(kAudioContentName);
1077 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001078 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1079 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-17 01:54:101080
1081 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1082 jdesc_.session_version()));
1083 }
1084
1085 // Turns the existing reference description into a unified plan description,
1086 // with 2 audio tracks and 3 video tracks.
1087 void MakeUnifiedPlanDescription() {
1088 // Audio track 2.
1089 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1090 StreamParams audio_track_2;
1091 audio_track_2.id = kAudioTrackId2;
1092 audio_track_2.cname = kStream2Cname;
1093 audio_track_2.sync_label = kStreamLabel2;
1094 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1095 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-21 00:34:001096 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-17 01:54:101097 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1098 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-17 01:54:101099 // Video track 2, in stream 2.
1100 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1101 StreamParams video_track_2;
1102 video_track_2.id = kVideoTrackId2;
1103 video_track_2.cname = kStream2Cname;
1104 video_track_2.sync_label = kStreamLabel2;
1105 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1106 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-21 00:34:001107 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-17 01:54:101108 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1109 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1110
1111 // Video track 3, in stream 2.
1112 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1113 StreamParams video_track_3;
1114 video_track_3.id = kVideoTrackId3;
1115 video_track_3.cname = kStream2Cname;
1116 video_track_3.sync_label = kStreamLabel2;
1117 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1118 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-21 00:34:001119 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-17 01:54:101120 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1121 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1122
1123 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1124 jdesc_.session_version()));
1125 }
1126
1127 // Creates an audio content description with no streams, and some default
1128 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361129 AudioContentDescription* CreateAudioContentDescription() {
1130 AudioContentDescription* audio = new AudioContentDescription();
1131 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511132 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:361133 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1134 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1135 "dummy_session_params"));
1136 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 17:07:161137 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-17 01:54:101138 audio->AddCodec(opus);
ossue1405ad2017-01-23 16:55:481139 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1140 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361141 return audio;
1142 }
1143
deadbeef9d3584c2016-02-17 01:54:101144 // Creates a video content description with no streams, and some default
1145 // configuration.
1146 VideoContentDescription* CreateVideoContentDescription() {
1147 VideoContentDescription* video = new VideoContentDescription();
1148 video->AddCrypto(CryptoParams(
1149 1, "AES_CM_128_HMAC_SHA1_80",
1150 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1151 video->set_protocol(cricket::kMediaProtocolSavpf);
1152 video->AddCodec(
perkj26752742016-10-24 08:21:161153 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-17 01:54:101154 return video;
1155 }
1156
henrike@webrtc.org28e20752013-07-10 00:45:361157 template <class MCD>
1158 void CompareMediaContentDescription(const MCD* cd1,
1159 const MCD* cd2) {
1160 // type
1161 EXPECT_EQ(cd1->type(), cd1->type());
1162
1163 // content direction
1164 EXPECT_EQ(cd1->direction(), cd2->direction());
1165
1166 // rtcp_mux
1167 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1168
deadbeef13871492015-12-09 20:37:511169 // rtcp_reduced_size
1170 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1171
henrike@webrtc.org28e20752013-07-10 00:45:361172 // cryptos
1173 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1174 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1175 ADD_FAILURE();
1176 return;
1177 }
1178 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1179 const CryptoParams c1 = cd1->cryptos().at(i);
1180 const CryptoParams c2 = cd2->cryptos().at(i);
1181 EXPECT_TRUE(c1.Matches(c2));
1182 EXPECT_EQ(c1.key_params, c2.key_params);
1183 EXPECT_EQ(c1.session_params, c2.session_params);
1184 }
lally@webrtc.orgd7b61652015-02-24 20:18:551185
henrike@webrtc.org28e20752013-07-10 00:45:361186 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551187 // Use an equivalence class here, for old and new versions of the
1188 // protocol description.
1189 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351190 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1191 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1192 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:551193 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351194 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1195 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1196 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551197 } else {
1198 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1199 }
henrike@webrtc.org28e20752013-07-10 00:45:361200
1201 // codecs
1202 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1203
1204 // bandwidth
1205 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1206
1207 // streams
1208 EXPECT_EQ(cd1->streams(), cd2->streams());
1209
1210 // extmap
1211 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1212 cd2->rtp_header_extensions().size());
1213 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 18:24:551214 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1215 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:361216 EXPECT_EQ(ext1.uri, ext2.uri);
1217 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 19:31:361218 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:361219 }
henrike@webrtc.org28e20752013-07-10 00:45:361220 }
1221
zstein4b2e0822017-02-18 03:48:381222 void CompareDataContentDescription(const DataContentDescription* dcd1,
1223 const DataContentDescription* dcd2) {
1224 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1225 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1226 }
henrike@webrtc.org28e20752013-07-10 00:45:361227
1228 void CompareSessionDescription(const SessionDescription& desc1,
1229 const SessionDescription& desc2) {
1230 // Compare content descriptions.
1231 if (desc1.contents().size() != desc2.contents().size()) {
1232 ADD_FAILURE();
1233 return;
1234 }
1235 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1236 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1237 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-13 02:37:361238 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:361239 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-13 02:37:361240 EXPECT_EQ(c1.type, c2.type);
1241 EXPECT_EQ(c1.rejected, c2.rejected);
1242 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:361243
1244 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1245 if (IsAudioContent(&c1)) {
1246 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 23:14:301247 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361248 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 23:14:301249 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361250 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1251 }
1252
1253 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1254 if (IsVideoContent(&c1)) {
1255 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 23:14:301256 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361257 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 23:14:301258 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361259 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1260 }
1261
1262 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1263 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 23:14:301264 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1265 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-18 03:48:381266 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:361267 }
1268 }
1269
1270 // group
1271 const cricket::ContentGroups groups1 = desc1.groups();
1272 const cricket::ContentGroups groups2 = desc2.groups();
1273 EXPECT_EQ(groups1.size(), groups1.size());
1274 if (groups1.size() != groups2.size()) {
1275 ADD_FAILURE();
1276 return;
1277 }
1278 for (size_t i = 0; i < groups1.size(); ++i) {
1279 const cricket::ContentGroup group1 = groups1.at(i);
1280 const cricket::ContentGroup group2 = groups2.at(i);
1281 EXPECT_EQ(group1.semantics(), group2.semantics());
1282 const cricket::ContentNames names1 = group1.content_names();
1283 const cricket::ContentNames names2 = group2.content_names();
1284 EXPECT_EQ(names1.size(), names2.size());
1285 if (names1.size() != names2.size()) {
1286 ADD_FAILURE();
1287 return;
1288 }
1289 cricket::ContentNames::const_iterator iter1 = names1.begin();
1290 cricket::ContentNames::const_iterator iter2 = names2.begin();
1291 while (iter1 != names1.end()) {
1292 EXPECT_EQ(*iter1++, *iter2++);
1293 }
1294 }
1295
1296 // transport info
1297 const cricket::TransportInfos transports1 = desc1.transport_infos();
1298 const cricket::TransportInfos transports2 = desc2.transport_infos();
1299 EXPECT_EQ(transports1.size(), transports2.size());
1300 if (transports1.size() != transports2.size()) {
1301 ADD_FAILURE();
1302 return;
1303 }
1304 for (size_t i = 0; i < transports1.size(); ++i) {
1305 const cricket::TransportInfo transport1 = transports1.at(i);
1306 const cricket::TransportInfo transport2 = transports2.at(i);
1307 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361308 EXPECT_EQ(transport1.description.ice_ufrag,
1309 transport2.description.ice_ufrag);
1310 EXPECT_EQ(transport1.description.ice_pwd,
1311 transport2.description.ice_pwd);
1312 if (transport1.description.identity_fingerprint) {
1313 EXPECT_EQ(*transport1.description.identity_fingerprint,
1314 *transport2.description.identity_fingerprint);
1315 } else {
1316 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1317 transport2.description.identity_fingerprint.get());
1318 }
1319 EXPECT_EQ(transport1.description.transport_options,
1320 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:361321 }
deadbeefc80741f2015-10-22 20:14:451322
1323 // global attributes
1324 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:361325 }
1326
henrike@webrtc.org28e20752013-07-10 00:45:361327 bool CompareSessionDescription(
1328 const JsepSessionDescription& desc1,
1329 const JsepSessionDescription& desc2) {
1330 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1331 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1332 CompareSessionDescription(*desc1.description(), *desc2.description());
1333 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1334 return false;
1335 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1336 const IceCandidateCollection* cc1 = desc1.candidates(i);
1337 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-13 02:37:361338 if (cc1->count() != cc2->count()) {
1339 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:361340 return false;
deadbeef25ed4352016-12-13 02:37:361341 }
henrike@webrtc.org28e20752013-07-10 00:45:361342 for (size_t j = 0; j < cc1->count(); ++j) {
1343 const IceCandidateInterface* c1 = cc1->at(j);
1344 const IceCandidateInterface* c2 = cc2->at(j);
1345 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1346 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1347 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1348 }
1349 }
1350 return true;
1351 }
1352
1353 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1354 // them with invalid keywords so that the parser will just ignore them.
1355 bool RemoveCandidateUfragPwd(std::string* sdp) {
1356 const char ice_ufrag[] = "a=ice-ufrag";
1357 const char ice_ufragx[] = "a=xice-ufrag";
1358 const char ice_pwd[] = "a=ice-pwd";
1359 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521360 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:361361 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521362 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:361363 ice_pwdx, strlen(ice_pwdx), sdp);
1364 return true;
1365 }
1366
1367 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1368 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1369 const std::string& ufrag, const std::string& pwd) {
1370 std::string content_name;
1371 if (mline_index == 0) {
1372 content_name = kAudioContentName;
1373 } else if (mline_index == 1) {
1374 content_name = kVideoContentName;
1375 } else {
nissec80e7412017-01-11 13:56:461376 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:361377 }
1378 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-18 01:54:521379 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361380 SessionDescription* desc =
1381 const_cast<SessionDescription*>(jdesc->description());
1382 desc->RemoveTransportInfoByName(content_name);
1383 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1384 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1385 const IceCandidateCollection* cc = jdesc_.candidates(i);
1386 for (size_t j = 0; j < cc->count(); ++j) {
1387 if (cc->at(j)->sdp_mline_index() == mline_index) {
1388 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1389 ufrag);
1390 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1391 pwd);
1392 }
1393 }
1394 }
1395 return true;
1396 }
1397
1398 void AddIceOptions(const std::string& content_name,
1399 const std::vector<std::string>& transport_options) {
1400 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1401 cricket::TransportInfo transport_info =
1402 *(desc_.GetTransportInfoByName(content_name));
1403 desc_.RemoveTransportInfoByName(content_name);
1404 transport_info.description.transport_options = transport_options;
1405 desc_.AddTransportInfo(transport_info);
1406 }
1407
deadbeef3f7219b2015-12-28 23:17:141408 void SetIceUfragPwd(const std::string& content_name,
1409 const std::string& ice_ufrag,
1410 const std::string& ice_pwd) {
1411 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1412 cricket::TransportInfo transport_info =
1413 *(desc_.GetTransportInfoByName(content_name));
1414 desc_.RemoveTransportInfoByName(content_name);
1415 transport_info.description.ice_ufrag = ice_ufrag;
1416 transport_info.description.ice_pwd = ice_pwd;
1417 desc_.AddTransportInfo(transport_info);
1418 }
1419
henrike@webrtc.org28e20752013-07-10 00:45:361420 void AddFingerprint() {
1421 desc_.RemoveTransportInfoByName(kAudioContentName);
1422 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521423 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:361424 kIdentityDigest,
1425 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 21:24:371426 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1427 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101428 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1429 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371430 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1431 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1432 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101433 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1434 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371435 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:361436 }
1437
jbauch5869f502017-06-29 19:31:361438 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 23:14:301439 audio_desc_ = audio_desc_->Copy();
1440 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 19:31:361441 audio_desc_->AddRtpHeaderExtension(
1442 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1443 video_desc_->AddRtpHeaderExtension(
1444 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:361445 desc_.RemoveContentByName(kAudioContentName);
1446 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001447 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1448 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:361449 }
1450
1451 void RemoveCryptos() {
1452 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1453 video_desc_->set_cryptos(std::vector<CryptoParams>());
1454 }
1455
Steve Anton4e70a722017-11-28 22:57:101456 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361457 audio_desc_->set_direction(direction);
1458 video_desc_->set_direction(direction);
1459 std::string new_sdp = kSdpFullString;
1460 ReplaceDirection(direction, &new_sdp);
1461
1462 if (!jdesc_.Initialize(desc_.Copy(),
1463 jdesc_.session_id(),
1464 jdesc_.session_version())) {
1465 return false;
1466 }
deadbeef9d3584c2016-02-17 01:54:101467 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361468 EXPECT_EQ(new_sdp, message);
1469 return true;
1470 }
1471
1472 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 23:14:301473 audio_desc_ = audio_desc_->Copy();
1474 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 18:04:531475
henrike@webrtc.org28e20752013-07-10 00:45:361476 desc_.RemoveContentByName(kAudioContentName);
1477 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001478 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:361479 audio_desc_);
Steve Anton5adfafd2017-12-21 00:34:001480 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:361481 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101482 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1483 audio_rejected ? "" : kPwdVoice);
1484 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1485 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141486
1487 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361488 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1489
Steve Antona3a92c22017-12-07 18:27:411490 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:531491 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-17 01:54:101492 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361493 EXPECT_EQ(new_sdp, message);
1494 return true;
1495 }
1496
zstein4b2e0822017-02-18 03:48:381497 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 13:47:291498 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361499 data_desc_ = data.get();
zstein4b2e0822017-02-18 03:48:381500 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:361501 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 20:02:441502 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 17:07:161503 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:021504 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1505 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-21 00:34:001506 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1507 data.release());
deadbeef9d3584c2016-02-17 01:54:101508 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1509 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361510 }
1511
1512 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 13:47:291513 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361514 data_desc_ = data.get();
1515
deadbeef67cf2c12016-04-13 17:07:161516 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:361517 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);
Steve Anton5adfafd2017-12-21 00:34:001527 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-17 01:54:101528 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1529 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361530 }
1531
Steve Anton4e70a722017-11-28 22:57:101532 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361533 std::string new_sdp = kSdpFullString;
1534 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411535 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361536
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 23:17:141551 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361552 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411553 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361554 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141555
Steve Antonb1c1de12017-12-21 23:14:301556 audio_desc_ = audio_desc_->Copy();
1557 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:361558 desc_.RemoveContentByName(kAudioContentName);
1559 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001560 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:361561 audio_desc_);
Steve Anton5adfafd2017-12-21 00:34:001562 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:361563 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101564 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1565 audio_rejected ? "" : kPwdVoice);
1566 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1567 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 18:27:411568 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 23:17:141569 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1570 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361571 return false;
1572 }
deadbeef3f7219b2015-12-28 23:17:141573 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361574 return true;
1575 }
1576
jbauch5869f502017-06-29 19:31:361577 void TestDeserializeExtmap(bool session_level, bool media_level,
1578 bool encrypted) {
1579 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:411580 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361581 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1582 jdesc_.session_id(),
1583 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 18:27:411584 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361585 std::string sdp_with_extmap = kSdpString;
1586 if (session_level) {
jbauch5869f502017-06-29 19:31:361587 InjectAfter(kSessionTime,
1588 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1589 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361590 &sdp_with_extmap);
1591 }
1592 if (media_level) {
jbauch5869f502017-06-29 19:31:361593 InjectAfter(kAttributeIcePwdVoice,
1594 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1595 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361596 &sdp_with_extmap);
jbauch5869f502017-06-29 19:31:361597 InjectAfter(kAttributeIcePwdVideo,
1598 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1599 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361600 &sdp_with_extmap);
1601 }
1602 // The extmap can't be present at the same time in both session level and
1603 // media level.
1604 if (session_level && media_level) {
1605 SdpParseError error;
1606 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1607 &jdesc_with_extmap, &error));
1608 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1609 } else {
1610 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1611 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1612 }
1613 }
1614
1615 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1616 const std::string& name, int expected_value) {
1617 cricket::CodecParameterMap::const_iterator found = params.find(name);
1618 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521619 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361620 }
1621
1622 void TestDeserializeCodecParams(const CodecParams& params,
1623 JsepSessionDescription* jdesc_output) {
1624 std::string sdp =
1625 "v=0\r\n"
1626 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1627 "s=-\r\n"
1628 "t=0 0\r\n"
1629 // Include semantics for WebRTC Media Streams since it is supported by
1630 // this parser, and will be added to the SDP when serializing a session
1631 // description.
1632 "a=msid-semantic: WMS\r\n"
1633 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411634 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361635 // Pltype 111 listed before 103 and 104 in the map.
1636 "a=rtpmap:111 opus/48000/2\r\n"
1637 // Pltype 103 listed before 104.
1638 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411639 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151640 "a=fmtp:111 0-15,66,70\r\n"
1641 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361642 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241643 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151644 << "; sprop-stereo=" << params.sprop_stereo
1645 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 16:21:231646 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361647 << "a=ptime:" << params.ptime << "\r\n"
1648 << "a=maxptime:" << params.max_ptime << "\r\n";
1649 sdp += os.str();
1650
stefan@webrtc.org85d27942014-06-09 12:51:391651 os.clear();
1652 os.str("");
1653 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221654 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:391655 << "a=rtpmap:99 VP8/90000\r\n"
1656 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:231657 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391658 sdp += os.str();
1659
henrike@webrtc.org28e20752013-07-10 00:45:361660 // Deserialize
1661 SdpParseError error;
1662 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1663
henrike@webrtc.org28e20752013-07-10 00:45:361664 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301665 GetFirstAudioContentDescription(jdesc_output->description());
1666 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361667 ASSERT_FALSE(acd->codecs().empty());
1668 cricket::AudioCodec opus = acd->codecs()[0];
1669 EXPECT_EQ("opus", opus.name);
1670 EXPECT_EQ(111, opus.id);
1671 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1672 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1673 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1674 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591675 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1676 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:361677 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1678 cricket::AudioCodec codec = acd->codecs()[i];
1679 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1680 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:361681 }
stefan@webrtc.org85d27942014-06-09 12:51:391682
stefan@webrtc.org85d27942014-06-09 12:51:391683 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:301684 GetFirstVideoContentDescription(jdesc_output->description());
1685 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:391686 ASSERT_FALSE(vcd->codecs().empty());
1687 cricket::VideoCodec vp8 = vcd->codecs()[0];
1688 EXPECT_EQ("VP8", vp8.name);
1689 EXPECT_EQ(99, vp8.id);
1690 cricket::VideoCodec rtx = vcd->codecs()[1];
1691 EXPECT_EQ("RTX", rtx.name);
1692 EXPECT_EQ(95, rtx.id);
1693 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:361694 }
1695
1696 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1697 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:461698 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:361699 "v=0\r\n"
1700 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1701 "s=-\r\n"
1702 "t=0 0\r\n"
1703 // Include semantics for WebRTC Media Streams since it is supported by
1704 // this parser, and will be added to the SDP when serializing a session
1705 // description.
1706 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221707 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461708 "a=rtpmap:111 opus/48000/2\r\n";
1709 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:361710 "m=video 3457 RTP/SAVPF 101\r\n"
1711 "a=rtpmap:101 VP8/90000\r\n"
1712 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581713 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461714 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361715 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:461716 os << sdp_session_and_audio;
1717 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1718 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:361719 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:461720 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:361721 // Deserialize
1722 SdpParseError error;
1723 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:361724 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301725 GetFirstAudioContentDescription(jdesc_output->description());
1726 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361727 ASSERT_FALSE(acd->codecs().empty());
1728 cricket::AudioCodec opus = acd->codecs()[0];
1729 EXPECT_EQ(111, opus.id);
1730 EXPECT_TRUE(opus.HasFeedbackParam(
1731 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1732 cricket::kParamValueEmpty)));
1733
henrike@webrtc.org28e20752013-07-10 00:45:361734 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:301735 GetFirstVideoContentDescription(jdesc_output->description());
1736 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:361737 ASSERT_FALSE(vcd->codecs().empty());
1738 cricket::VideoCodec vp8 = vcd->codecs()[0];
1739 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1740 vp8.name.c_str());
1741 EXPECT_EQ(101, vp8.id);
1742 EXPECT_TRUE(vp8.HasFeedbackParam(
1743 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1744 cricket::kParamValueEmpty)));
1745 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581746 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1747 cricket::kRtcpFbNackParamPli)));
1748 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:361749 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1750 cricket::kParamValueEmpty)));
1751 EXPECT_TRUE(vp8.HasFeedbackParam(
1752 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1753 cricket::kRtcpFbCcmParamFir)));
1754 }
1755
1756 // Two SDP messages can mean the same thing but be different strings, e.g.
1757 // some of the lines can be serialized in different order.
1758 // However, a deserialized description can be compared field by field and has
1759 // no order. If deserializer has already been tested, serializing then
1760 // deserializing and comparing JsepSessionDescription will test
1761 // the serializer sufficiently.
deadbeef9d3584c2016-02-17 01:54:101762 void TestSerialize(const JsepSessionDescription& jdesc,
1763 bool unified_plan_sdp) {
1764 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
Steve Antona3a92c22017-12-07 18:27:411765 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361766 SdpParseError error;
1767 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1768 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1769 }
1770
zhihuang38989e52017-03-21 18:04:531771 // Calling 'Initialize' with a copy of the inner SessionDescription will
1772 // create a copy of the JsepSessionDescription without candidates. The
1773 // 'connection address' field, previously set from the candidates, must also
1774 // be reset.
1775 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1776 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1777 rtc::SocketAddress video_addr("0.0.0.0", 9);
1778 audio_desc_->set_connection_address(audio_addr);
1779 video_desc_->set_connection_address(video_addr);
1780 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1781 }
1782
henrike@webrtc.org28e20752013-07-10 00:45:361783 protected:
1784 SessionDescription desc_;
1785 AudioContentDescription* audio_desc_;
1786 VideoContentDescription* video_desc_;
1787 DataContentDescription* data_desc_;
1788 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:291789 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:361790 JsepSessionDescription jdesc_;
1791};
1792
1793void TestMismatch(const std::string& string1, const std::string& string2) {
1794 int position = 0;
1795 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1796 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:491797 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:361798 break;
1799 }
1800 }
1801 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1802 << " character\n"
1803 << " 1: " << string1.substr(position, 20) << "\n"
1804 << " 2: " << string2.substr(position, 20) << "\n";
1805}
1806
henrike@webrtc.org28e20752013-07-10 00:45:361807TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1808 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-17 01:54:101809 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361810 TestMismatch(std::string(kSdpFullString), message);
1811}
1812
1813TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 18:27:411814 JsepSessionDescription jdesc_empty(kDummyType);
deadbeef9d3584c2016-02-17 01:54:101815 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:361816}
1817
1818// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1819// the case in a DTLS offer.
1820TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1821 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:411822 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:531823 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-17 01:54:101824 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361825
1826 std::string sdp_with_fingerprint = kSdpString;
1827 InjectAfter(kAttributeIcePwdVoice,
1828 kFingerprint, &sdp_with_fingerprint);
1829 InjectAfter(kAttributeIcePwdVideo,
1830 kFingerprint, &sdp_with_fingerprint);
1831
1832 EXPECT_EQ(sdp_with_fingerprint, message);
1833}
1834
1835// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1836// be the case in a DTLS answer.
1837TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1838 AddFingerprint();
1839 RemoveCryptos();
Steve Antona3a92c22017-12-07 18:27:411840 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:531841 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-17 01:54:101842 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361843
1844 std::string sdp_with_fingerprint = kSdpString;
1845 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1846 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1847 InjectAfter(kAttributeIcePwdVoice,
1848 kFingerprint, &sdp_with_fingerprint);
1849 InjectAfter(kAttributeIcePwdVideo,
1850 kFingerprint, &sdp_with_fingerprint);
1851
1852 EXPECT_EQ(sdp_with_fingerprint, message);
1853}
1854
1855TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1856 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:411857 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:531858 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-17 01:54:101859 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361860 EXPECT_EQ(std::string(kSdpString), message);
1861}
1862
1863TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1864 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1865 group.AddContentName(kAudioContentName);
1866 group.AddContentName(kVideoContentName);
1867 desc_.AddGroup(group);
1868 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1869 jdesc_.session_id(),
1870 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101871 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361872 std::string sdp_with_bundle = kSdpFullString;
1873 InjectAfter(kSessionTime,
1874 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1875 &sdp_with_bundle);
1876 EXPECT_EQ(sdp_with_bundle, message);
1877}
1878
1879TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 23:14:301880 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:361881 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:301882 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:361883 acd->set_bandwidth(50 * 1000);
1884 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1885 jdesc_.session_id(),
1886 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101887 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361888 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:131889 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361890 "b=AS:100\r\n",
1891 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:131892 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361893 "b=AS:50\r\n",
1894 &sdp_with_bandwidth);
1895 EXPECT_EQ(sdp_with_bandwidth, message);
1896}
1897
1898TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1899 std::vector<std::string> transport_options;
1900 transport_options.push_back(kIceOption1);
1901 transport_options.push_back(kIceOption3);
1902 AddIceOptions(kAudioContentName, transport_options);
1903 transport_options.clear();
1904 transport_options.push_back(kIceOption2);
1905 transport_options.push_back(kIceOption3);
1906 AddIceOptions(kVideoContentName, transport_options);
1907 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1908 jdesc_.session_id(),
1909 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101910 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361911 std::string sdp_with_ice_options = kSdpFullString;
1912 InjectAfter(kAttributeIcePwdVoice,
1913 "a=ice-options:iceoption1 iceoption3\r\n",
1914 &sdp_with_ice_options);
1915 InjectAfter(kAttributeIcePwdVideo,
1916 "a=ice-options:iceoption2 iceoption3\r\n",
1917 &sdp_with_ice_options);
1918 EXPECT_EQ(sdp_with_ice_options, message);
1919}
1920
1921TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:101922 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:361923}
1924
1925TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:101926 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:361927}
1928
1929TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:101930 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:361931}
1932
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1934 EXPECT_TRUE(TestSerializeRejected(true, false));
1935}
1936
1937TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1938 EXPECT_TRUE(TestSerializeRejected(false, true));
1939}
1940
1941TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1942 EXPECT_TRUE(TestSerializeRejected(true, true));
1943}
1944
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1946 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:411947 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361948
zhihuang38989e52017-03-21 18:04:531949 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:101950 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361951
1952 std::string expected_sdp = kSdpString;
1953 expected_sdp.append(kSdpRtpDataChannelString);
1954 EXPECT_EQ(expected_sdp, message);
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-18 03:48:381958 bool use_sctpmap = true;
1959 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:411960 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361961
zhihuang38989e52017-03-21 18:04:531962 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:101963 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361964
1965 std::string expected_sdp = kSdpString;
1966 expected_sdp.append(kSdpSctpDataChannelString);
1967 EXPECT_EQ(message, expected_sdp);
1968}
1969
jiayl@webrtc.org9c16c392014-05-01 18:30:301970TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-18 03:48:381971 bool use_sctpmap = true;
1972 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:411973 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:531974 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 23:14:301975 DataContentDescription* dcdesc =
1976 jsep_desc.description()
1977 ->GetContentDescriptionByName(kDataContentName)
1978 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:301979
1980 const int kNewPort = 1234;
solenberg9fa49752016-10-08 20:02:441981 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 17:07:161982 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:301983 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1984 dcdesc->AddOrReplaceCodec(codec);
1985
deadbeef9d3584c2016-02-17 01:54:101986 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:301987
1988 std::string expected_sdp = kSdpString;
1989 expected_sdp.append(kSdpSctpDataChannelString);
1990
1991 char default_portstr[16];
1992 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521993 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:301994 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521995 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
1996 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:301997 new_portstr, strlen(new_portstr),
1998 &expected_sdp);
1999
2000 EXPECT_EQ(expected_sdp, message);
2001}
2002
wu@webrtc.orgcadf9042013-08-30 21:24:162003TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412004 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:162005 AddRtpDataChannel();
2006 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 18:04:532007 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:102008 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:162009
2010 std::string expected_sdp = kSdpString;
2011 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 22:31:252012 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:062013 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:582014 "b=AS:100\r\n",
2015 &expected_sdp);
2016 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:162017}
2018
henrike@webrtc.org28e20752013-07-10 00:45:362019TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 19:31:362020 bool encrypted = false;
2021 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412022 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 18:04:532023 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-17 01:54:102024 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:362025
2026 std::string sdp_with_extmap = kSdpString;
2027 InjectAfter("a=mid:audio_content_name\r\n",
2028 kExtmap, &sdp_with_extmap);
2029 InjectAfter("a=mid:video_content_name\r\n",
2030 kExtmap, &sdp_with_extmap);
2031
2032 EXPECT_EQ(sdp_with_extmap, message);
2033}
2034
jbauch5869f502017-06-29 19:31:362035TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2036 bool encrypted = true;
2037 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412038 JsepSessionDescription desc_with_extmap(kDummyType);
jbauch5869f502017-06-29 19:31:362039 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2040 kSessionId, kSessionVersion));
2041 TestSerialize(desc_with_extmap, false);
2042}
2043
henrike@webrtc.org28e20752013-07-10 00:45:362044TEST_F(WebRtcSdpTest, SerializeCandidates) {
2045 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102046 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232047
2048 Candidate candidate_with_ufrag(candidates_.front());
2049 candidate_with_ufrag.set_username("ABC");
2050 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2051 candidate_with_ufrag));
2052 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2053 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482054
2055 Candidate candidate_with_network_info(candidates_.front());
2056 candidate_with_network_info.set_network_id(1);
2057 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2058 candidate_with_network_info));
2059 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2060 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2061 candidate_with_network_info.set_network_cost(999);
2062 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2063 candidate_with_network_info));
2064 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2065 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2066 message);
henrike@webrtc.org28e20752013-07-10 00:45:362067}
2068
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202069// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2070// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:552071TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072072 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312073 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2074 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2075 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202076 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292077 std::unique_ptr<IceCandidateInterface> jcandidate(
2078 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202079
2080 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2081 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2082}
2083
htaa6b99442016-04-12 17:29:172084TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 09:34:112085 cricket::VideoCodec h264_codec("H264");
2086 h264_codec.SetParam("profile-level-id", "42e01f");
2087 h264_codec.SetParam("level-asymmetry-allowed", "1");
2088 h264_codec.SetParam("packetization-mode", "1");
2089 video_desc_->AddCodec(h264_codec);
2090
htaa6b99442016-04-12 17:29:172091 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2092
2093 std::string message = webrtc::SdpSerialize(jdesc_, false);
2094 size_t after_pt = message.find(" H264/90000");
2095 ASSERT_NE(after_pt, std::string::npos);
2096 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2097 ASSERT_NE(before_pt, std::string::npos);
2098 before_pt += strlen("a=rtpmap:");
2099 std::string pt = message.substr(before_pt, after_pt - before_pt);
2100 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2101 std::string to_find = "a=fmtp:" + pt + " ";
2102 size_t fmtp_pos = message.find(to_find);
2103 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2104 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2105 ASSERT_NE(std::string::npos, fmtp_endpos);
2106 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2107 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2108 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2109 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142110 // Check that there are no spaces after semicolons.
2111 // https://bugs.webrtc.org/5793
2112 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:362115TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 18:27:412116 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362117 // Deserialize
2118 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2119 // Verify
2120 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2121}
2122
wu@webrtc.orgcecfd182013-10-30 05:18:122123TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 18:27:412124 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:122125 const char kSdpWithoutMline[] =
2126 "v=0\r\n"
2127 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2128 "s=-\r\n"
2129 "t=0 0\r\n"
2130 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2131 // Deserialize
2132 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2133 EXPECT_EQ(0u, jdesc.description()->contents().size());
2134}
2135
henrike@webrtc.org28e20752013-07-10 00:45:362136TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 18:27:412137 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362138 std::string sdp_without_carriage_return = kSdpFullString;
2139 Replace("\r\n", "\n", &sdp_without_carriage_return);
2140 // Deserialize
2141 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2142 // Verify
2143 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2144}
2145
2146TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2147 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412148 JsepSessionDescription jdesc_no_candidates(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362149 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2150 kSessionId, kSessionVersion));
Steve Antona3a92c22017-12-07 18:27:412151 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362152 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2153 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2154}
2155
2156TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2157 static const char kSdpNoRtpmapString[] =
2158 "v=0\r\n"
2159 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2160 "s=-\r\n"
2161 "t=0 0\r\n"
2162 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2163 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412164 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362165 // The rtpmap line for static payload codec is optional.
2166 "a=rtpmap:18 G729/16000\r\n"
2167 "a=rtpmap:103 ISAC/16000\r\n";
2168
Steve Antona3a92c22017-12-07 18:27:412169 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362170 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2171 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 23:14:302172 jdesc.description()
2173 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2174 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:362175 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162176 // The codecs in the AudioContentDescription should be in the same order as
2177 // the payload types (<fmt>s) on the m= line.
2178 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2179 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 16:55:482180 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362181 EXPECT_EQ(ref_codecs, audio->codecs());
2182}
2183
henrike@webrtc.org704bf9e2014-02-27 17:52:042184TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2185 static const char kSdpNoRtpmapString[] =
2186 "v=0\r\n"
2187 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2188 "s=-\r\n"
2189 "t=0 0\r\n"
2190 "m=audio 49232 RTP/AVP 18 103\r\n"
2191 "a=fmtp:18 annexb=yes\r\n"
2192 "a=rtpmap:103 ISAC/16000\r\n";
2193
Steve Antona3a92c22017-12-07 18:27:412194 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:042195 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2196 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 23:14:302197 jdesc.description()
2198 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2199 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:042200
2201 cricket::AudioCodec g729 = audio->codecs()[0];
2202 EXPECT_EQ("G729", g729.name);
2203 EXPECT_EQ(8000, g729.clockrate);
2204 EXPECT_EQ(18, g729.id);
2205 cricket::CodecParameterMap::iterator found =
2206 g729.params.find("annexb");
2207 ASSERT_TRUE(found != g729.params.end());
2208 EXPECT_EQ(found->second, "yes");
2209
2210 cricket::AudioCodec isac = audio->codecs()[1];
2211 EXPECT_EQ("ISAC", isac.name);
2212 EXPECT_EQ(103, isac.id);
2213 EXPECT_EQ(16000, isac.clockrate);
2214}
2215
henrike@webrtc.org28e20752013-07-10 00:45:362216// Ensure that we can deserialize SDP with a=fingerprint properly.
2217TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2218 // Add a DTLS a=fingerprint attribute to our session description.
2219 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412220 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362221 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2222 jdesc_.session_id(),
2223 jdesc_.session_version()));
2224
Steve Antona3a92c22017-12-07 18:27:412225 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362226 std::string sdp_with_fingerprint = kSdpString;
2227 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2228 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2229 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2230 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2231}
2232
2233TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 18:27:412234 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362235 std::string sdp_with_bundle = kSdpFullString;
2236 InjectAfter(kSessionTime,
2237 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2238 &sdp_with_bundle);
2239 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2240 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2241 group.AddContentName(kAudioContentName);
2242 group.AddContentName(kVideoContentName);
2243 desc_.AddGroup(group);
2244 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2245 jdesc_.session_id(),
2246 jdesc_.session_version()));
2247 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2248}
2249
2250TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412251 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362252 std::string sdp_with_bandwidth = kSdpFullString;
2253 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2254 "b=AS:100\r\n",
2255 &sdp_with_bandwidth);
2256 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2257 "b=AS:50\r\n",
2258 &sdp_with_bandwidth);
2259 EXPECT_TRUE(
2260 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 23:14:302261 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362262 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302263 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362264 acd->set_bandwidth(50 * 1000);
2265 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2266 jdesc_.session_id(),
2267 jdesc_.session_version()));
2268 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2269}
2270
2271TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 18:27:412272 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362273 std::string sdp_with_ice_options = kSdpFullString;
2274 InjectAfter(kSessionTime,
2275 "a=ice-options:iceoption3\r\n",
2276 &sdp_with_ice_options);
2277 InjectAfter(kAttributeIcePwdVoice,
2278 "a=ice-options:iceoption1\r\n",
2279 &sdp_with_ice_options);
2280 InjectAfter(kAttributeIcePwdVideo,
2281 "a=ice-options:iceoption2\r\n",
2282 &sdp_with_ice_options);
2283 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2284 std::vector<std::string> transport_options;
2285 transport_options.push_back(kIceOption3);
2286 transport_options.push_back(kIceOption1);
2287 AddIceOptions(kAudioContentName, transport_options);
2288 transport_options.clear();
2289 transport_options.push_back(kIceOption3);
2290 transport_options.push_back(kIceOption2);
2291 AddIceOptions(kVideoContentName, transport_options);
2292 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2293 jdesc_.session_id(),
2294 jdesc_.session_version()));
2295 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2296}
2297
2298TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2299 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 18:27:412300 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362301 std::string sdp_with_ufrag_pwd = kSdpFullString;
2302 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2303 // Add session level ufrag and pwd
2304 InjectAfter(kSessionTime,
2305 "a=ice-pwd:session+level+icepwd\r\n"
2306 "a=ice-ufrag:session+level+iceufrag\r\n",
2307 &sdp_with_ufrag_pwd);
2308 // Add media level ufrag and pwd for audio
2309 InjectAfter("a=mid:audio_content_name\r\n",
2310 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2311 &sdp_with_ufrag_pwd);
2312 // Update the candidate ufrag and pwd to the expected ones.
2313 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2314 "media+level+iceufrag", "media+level+icepwd"));
2315 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2316 "session+level+iceufrag", "session+level+icepwd"));
2317 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2318 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2319}
2320
henrike@webrtc.org28e20752013-07-10 00:45:362321TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102322 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362323}
2324
2325TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102326 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362327}
2328
2329TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102330 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362331}
2332
2333TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2334 EXPECT_TRUE(TestDeserializeRejected(true, false));
2335}
2336
2337TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2338 EXPECT_TRUE(TestDeserializeRejected(false, true));
2339}
2340
2341TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2342 EXPECT_TRUE(TestDeserializeRejected(true, true));
2343}
2344
2345// Tests that we can still handle the sdp uses mslabel and label instead of
2346// msid for backward compatibility.
2347TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 20:14:452348 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 18:27:412349 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362350 std::string sdp_without_msid = kSdpFullString;
2351 Replace("msid", "xmsid", &sdp_without_msid);
2352 // Deserialize
2353 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2354 // Verify
2355 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2356}
2357
2358TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2359 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2360
2361 std::string sdp = kSdpOneCandidate;
2362 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2363 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2364 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2365 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482366 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362367
2368 // Candidate line without generation extension.
2369 sdp = kSdpOneCandidate;
2370 Replace(" generation 2", "", &sdp);
2371 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2372 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2373 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2374 Candidate expected = jcandidate_->candidate();
2375 expected.set_generation(0);
2376 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2377
honghaiza0c44ea2016-03-23 23:07:482378 // Candidate with network id and/or cost.
2379 sdp = kSdpOneCandidate;
2380 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2381 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2382 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2383 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2384 expected = jcandidate_->candidate();
2385 expected.set_network_id(2);
2386 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2387 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2388 // Add network cost
2389 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2390 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2391 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2392 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2393
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202394 sdp = kSdpTcpActiveCandidate;
2395 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2396 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072397 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312398 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2399 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2400 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292401 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2402 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202403 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2404 jcandidate_template->candidate()));
2405 sdp = kSdpTcpPassiveCandidate;
2406 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2407 sdp = kSdpTcpSOCandidate;
2408 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362409}
2410
2411// This test verifies the deserialization of candidate-attribute
2412// as per RFC 5245. Candiate-attribute will be of the format
2413// candidate:<blah>. This format will be used when candidates
2414// are trickled.
2415TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2416 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2417
2418 std::string candidate_attribute = kRawCandidate;
2419 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2420 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2421 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2422 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2423 EXPECT_EQ(2u, jcandidate.candidate().generation());
2424
2425 // Candidate line without generation extension.
2426 candidate_attribute = kRawCandidate;
2427 Replace(" generation 2", "", &candidate_attribute);
2428 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2429 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2430 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2431 Candidate expected = jcandidate_->candidate();
2432 expected.set_generation(0);
2433 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2434
2435 // Candidate line without candidate:
2436 candidate_attribute = kRawCandidate;
2437 Replace("candidate:", "", &candidate_attribute);
2438 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2439
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152440 // Candidate line with IPV6 address.
2441 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2442}
2443
2444// This test verifies that the deserialization of an invalid candidate string
2445// fails.
2446TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2447 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2448
2449 std::string candidate_attribute = kRawCandidate;
2450 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362451 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152452
2453 candidate_attribute = kSdpOneCandidate;
2454 candidate_attribute.replace(0, 1, "x");
2455 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2456
2457 candidate_attribute = kRawCandidate;
2458 candidate_attribute.append("\r\n");
2459 candidate_attribute.append(kRawCandidate);
2460 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2461
2462 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362463}
2464
2465TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2466 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:412467 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362468 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2469
2470 std::string sdp_with_data = kSdpString;
2471 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412472 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362473
2474 // Deserialize
2475 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2476 // Verify
2477 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2478}
2479
2480TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-18 03:48:382481 bool use_sctpmap = true;
2482 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412483 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362484 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2485
2486 std::string sdp_with_data = kSdpString;
2487 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412488 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362489
lally@webrtc.org36300852015-02-24 20:19:352490 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2491 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2492 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2493
2494 // Verify with UDP/DTLS/SCTP.
2495 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2496 strlen(kDtlsSctp), kUdpDtlsSctp);
2497 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2498 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2499
2500 // Verify with TCP/DTLS/SCTP.
2501 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2502 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362503 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2505}
2506
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562507TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-18 03:48:382508 bool use_sctpmap = false;
2509 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412510 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562511 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2512
2513 std::string sdp_with_data = kSdpString;
2514 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 18:27:412515 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562516
lally@webrtc.org36300852015-02-24 20:19:352517 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562518 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2519 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562520
lally@webrtc.org36300852015-02-24 20:19:352521 // Verify with UDP/DTLS/SCTP.
2522 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2523 strlen(kDtlsSctp), kUdpDtlsSctp);
2524 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2525 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:262526
lally@webrtc.org36300852015-02-24 20:19:352527 // Verify with TCP/DTLS/SCTP.
2528 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2529 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:262530 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2531 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2532}
2533
lally69f57602015-10-08 17:15:042534TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-18 03:48:382535 bool use_sctpmap = false;
2536 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412537 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 17:15:042538 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2539
2540 std::string sdp_with_data = kSdpString;
2541 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 18:27:412542 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 17:15:042543
2544 // Verify with DTLS/SCTP.
2545 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2546 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2547
2548 // Verify with UDP/DTLS/SCTP.
2549 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2550 strlen(kDtlsSctp), kUdpDtlsSctp);
2551 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2552 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2553
2554 // Verify with TCP/DTLS/SCTP.
2555 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2556 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2557 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2558 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2559}
2560
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562561// Test to check the behaviour if sctp-port is specified
2562// on the m= line and in a=sctp-port.
2563TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-18 03:48:382564 bool use_sctpmap = true;
2565 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412566 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562567 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2568
2569 std::string sdp_with_data = kSdpString;
2570 // Append m= attributes
2571 sdp_with_data.append(kSdpSctpDataChannelString);
2572 // Append a=sctp-port attribute
2573 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 18:27:412574 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562575
2576 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2577}
2578
henrike@webrtc.org571df2d2014-02-19 23:04:262579// For crbug/344475.
2580TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2581 std::string sdp_with_data = kSdpString;
2582 sdp_with_data.append(kSdpSctpDataChannelString);
2583 // Remove the "\n" at the end.
2584 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 18:27:412585 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:262586
2587 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2588 // No crash is a pass.
2589}
2590
Steve Anton36b29d12017-10-30 16:57:422591void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-18 03:48:382592 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:022593 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-18 03:48:382594 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 23:14:302595 DataContentDescription* dcdesc =
2596 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:022597 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:222598 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 20:02:442599 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:022600 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302601 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:022602
2603 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 16:57:422604 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:022605 mutant = NULL;
zstein4b2e0822017-02-18 03:48:382606}
2607
2608TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2609 bool use_sctpmap = true;
2610 AddSctpDataChannel(use_sctpmap);
2611
2612 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 18:27:412613 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 16:57:422614 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:022615
jiayl@webrtc.org9c16c392014-05-01 18:30:302616 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:022617 std::string sdp_with_data = kSdpString;
2618 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-18 03:48:382619 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2620 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2621 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:412622 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:022623
2624 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2625 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-18 03:48:382626}
2627
2628TEST_F(WebRtcSdpTest,
2629 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2630 bool use_sctpmap = false;
2631 AddSctpDataChannel(use_sctpmap);
2632
Steve Antona3a92c22017-12-07 18:27:412633 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 16:57:422634 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562635
2636 // We need to test the deserialized JsepSessionDescription from
2637 // kSdpSctpDataChannelStringWithSctpPort for
2638 // draft-ietf-mmusic-sctp-sdp-07
2639 // a=sctp-port
zstein4b2e0822017-02-18 03:48:382640 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562641 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-18 03:48:382642 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2643 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2644 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:412645 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562646
2647 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2648 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:022649}
2650
wu@webrtc.orgcadf9042013-08-30 21:24:162651TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 22:31:252652 // We want to test that deserializing data content limits bandwidth
2653 // settings (it should never be greater than the default).
2654 // This should prevent someone from using unlimited data bandwidth through
2655 // JS and "breaking the Internet".
2656 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:162657 std::string sdp_with_bandwidth = kSdpString;
2658 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2659 InjectAfter("a=mid:data_content_name\r\n",
2660 "b=AS:100\r\n",
2661 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:412662 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:162663
Peter Thatcherc0c3a862015-06-24 22:31:252664 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2665}
2666
2667TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-18 03:48:382668 bool use_sctpmap = true;
2669 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412670 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 23:14:302671 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 22:31:252672 dcd->set_bandwidth(100 * 1000);
2673 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2674
2675 std::string sdp_with_bandwidth = kSdpString;
2676 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2677 InjectAfter("a=mid:data_content_name\r\n",
2678 "b=AS:100\r\n",
2679 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:412680 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 22:31:252681
2682 // SCTP has congestion control, so we shouldn't limit the bandwidth
2683 // as we do for RTP.
2684 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:162685 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2686}
2687
jbauch5869f502017-06-29 19:31:362688class WebRtcSdpExtmapTest
2689 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2690};
2691
2692TEST_P(WebRtcSdpExtmapTest,
2693 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2694 bool encrypted = GetParam();
2695 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362696}
2697
jbauch5869f502017-06-29 19:31:362698TEST_P(WebRtcSdpExtmapTest,
2699 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2700 bool encrypted = GetParam();
2701 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362702}
2703
jbauch5869f502017-06-29 19:31:362704TEST_P(WebRtcSdpExtmapTest,
2705 DeserializeSessionDescriptionWithInvalidExtmap) {
2706 bool encrypted = GetParam();
2707 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362708}
2709
jbauch5869f502017-06-29 19:31:362710INSTANTIATE_TEST_CASE_P(Encrypted,
2711 WebRtcSdpExtmapTest,
2712 ::testing::Values(false, true));
2713
sergeyu@chromium.org5bc25c42013-12-05 00:24:062714TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 18:27:412715 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:062716 std::string sdp = kSdpFullString;
2717 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2718 // Deserialize
2719 SdpParseError error;
2720 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-17 01:54:102721 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:062722 EXPECT_EQ(lastline, error.line);
2723 EXPECT_EQ("Invalid SDP line.", error.description);
2724}
2725
henrike@webrtc.org28e20752013-07-10 00:45:362726TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2727 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2728 std::string new_sdp = kSdpOneCandidate;
2729 Replace("udp", "unsupported_transport", &new_sdp);
2730 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2731 new_sdp = kSdpOneCandidate;
2732 Replace("udp", "uDP", &new_sdp);
2733 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2734 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2735 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2736 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2737}
2738
honghaiza54a0802015-12-17 02:37:232739TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:362740 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:232741 EXPECT_TRUE(
2742 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362743 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2744 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2745 Candidate ref_candidate = jcandidate_->candidate();
2746 ref_candidate.set_username("user_rtp");
2747 ref_candidate.set_password("password_rtp");
2748 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2749}
2750
henrike@webrtc.org704bf9e2014-02-27 17:52:042751TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:412752 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:042753
2754 // Deserialize
2755 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2756
2757 // Verify
2758 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 23:14:302759 jdesc.description()
2760 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2761 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:042762 EXPECT_TRUE(audio->conference_mode());
2763
2764 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 23:14:302765 jdesc.description()
2766 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2767 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:042768 EXPECT_TRUE(video->conference_mode());
2769}
2770
deadbeefd45aea82017-09-16 08:24:292771TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:412772 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 08:24:292773
2774 // We tested deserialization already above, so just test that if we serialize
2775 // and deserialize the flag doesn't disappear.
2776 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2777 std::string reserialized = webrtc::SdpSerialize(jdesc, false);
2778 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2779
2780 // Verify.
2781 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 23:14:302782 jdesc.description()
2783 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2784 ->as_audio();
deadbeefd45aea82017-09-16 08:24:292785 EXPECT_TRUE(audio->conference_mode());
2786
2787 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 23:14:302788 jdesc.description()
2789 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2790 ->as_video();
deadbeefd45aea82017-09-16 08:24:292791 EXPECT_TRUE(video->conference_mode());
2792}
2793
henrike@webrtc.org28e20752013-07-10 00:45:362794TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2795 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:512796 const char kSdpEmptyType[] = " =candidate";
2797 const char kSdpEqualAsPlus[] = "a+candidate";
2798 const char kSdpSpaceAfterEqual[] = "a= candidate";
2799 const char kSdpUpperType[] = "A=candidate";
2800 const char kSdpEmptyLine[] = "";
2801 const char kSdpMissingValue[] = "a=";
2802
2803 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362804 "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:512805 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362806 "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:512807 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:362808 "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:582809 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:512810 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582811 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:362812
2813 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:092814 ExpectParseFailure("v=", kSdpDestroyer);
2815 ExpectParseFailure("o=", kSdpDestroyer);
2816 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362817 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:092818 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362819
2820 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:092821 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2822 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362823
2824 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:512825 ExpectParseFailure("a=candidate", kSdpEmptyType);
2826 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2827 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2828 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:362829
2830 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2831 // because it's orthogonal to what we are replacing and hence
2832 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:512833 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2834 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2835 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2836 ExpectParseFailure("a=sendrecv", kSdpMd5);
2837
2838 // Empty Line
2839 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2840 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:092841}
2842
2843TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2844 // ssrc
2845 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:102846 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:092847 // crypto
2848 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2849 // rtpmap
2850 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2851 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2852 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2853 // candidate
2854 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2855 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2856 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2857 ExpectParseFailure("rport 2346", "rport badvalue");
2858 ExpectParseFailure("rport 2346 generation 2",
2859 "rport 2346 generation badvalue");
2860 // m line
2861 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2862 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2863
2864 // bandwidth
2865 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2866 "b=AS:badvalue\r\n",
2867 "b=AS:badvalue");
2868 // rtcp-fb
2869 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2870 "a=rtcp-fb:badvalue nack\r\n",
2871 "a=rtcp-fb:badvalue nack");
2872 // extmap
2873 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2874 "a=extmap:badvalue http://example.com\r\n",
2875 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:362876}
2877
2878TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 18:27:412879 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362880
2881 const char kSdpWithReorderedPlTypesString[] =
2882 "v=0\r\n"
2883 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2884 "s=-\r\n"
2885 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:222886 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:362887 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2888 // in the map.
2889 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412890 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362891
2892 // Deserialize
2893 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2894
henrike@webrtc.org28e20752013-07-10 00:45:362895 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:302896 GetFirstAudioContentDescription(jdesc_output.description());
2897 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:362898 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412899 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2900 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:362901 EXPECT_EQ(104, acd->codecs()[0].id);
2902}
2903
2904TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 18:27:412905 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362906 CodecParams params;
2907 params.max_ptime = 40;
2908 params.ptime = 30;
2909 params.min_ptime = 10;
2910 params.sprop_stereo = 1;
2911 params.stereo = 1;
2912 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:592913 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:362914 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-17 01:54:102915 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362916}
2917
2918TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2919 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 18:27:412920 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362921 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102922 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362923}
2924
2925TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2926 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 18:27:412927 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362928 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102929 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362930}
2931
2932TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 18:27:412933 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362934
2935 const char kSdpWithFmtpString[] =
2936 "v=0\r\n"
2937 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2938 "s=-\r\n"
2939 "t=0 0\r\n"
2940 "m=video 3457 RTP/SAVPF 120\r\n"
2941 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:232942 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2943
2944 // Deserialize
2945 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:242946 EXPECT_TRUE(
2947 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:232948
Donald Curtis0e07f922015-05-15 16:21:232949 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302950 GetFirstVideoContentDescription(jdesc_output.description());
2951 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 16:21:232952 ASSERT_FALSE(vcd->codecs().empty());
2953 cricket::VideoCodec vp8 = vcd->codecs()[0];
2954 EXPECT_EQ("VP8", vp8.name);
2955 EXPECT_EQ(120, vp8.id);
2956 cricket::CodecParameterMap::iterator found =
2957 vp8.params.find("x-google-min-bitrate");
2958 ASSERT_TRUE(found != vp8.params.end());
2959 EXPECT_EQ(found->second, "10");
2960 found = vp8.params.find("x-google-max-quantization");
2961 ASSERT_TRUE(found != vp8.params.end());
2962 EXPECT_EQ(found->second, "40");
2963}
2964
johan2d8d23e2016-06-03 08:22:422965TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 18:27:412966 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 08:22:422967
2968 const char kSdpWithFmtpString[] =
2969 "v=0\r\n"
2970 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2971 "s=-\r\n"
2972 "t=0 0\r\n"
2973 "m=video 49170 RTP/AVP 98\r\n"
2974 "a=rtpmap:98 H264/90000\r\n"
2975 "a=fmtp:98 profile-level-id=42A01E; "
2976 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2977
2978 // Deserialize.
2979 SdpParseError error;
2980 EXPECT_TRUE(
2981 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2982
johan2d8d23e2016-06-03 08:22:422983 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302984 GetFirstVideoContentDescription(jdesc_output.description());
2985 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 08:22:422986 ASSERT_FALSE(vcd->codecs().empty());
2987 cricket::VideoCodec h264 = vcd->codecs()[0];
2988 EXPECT_EQ("H264", h264.name);
2989 EXPECT_EQ(98, h264.id);
2990 cricket::CodecParameterMap::const_iterator found =
2991 h264.params.find("profile-level-id");
2992 ASSERT_TRUE(found != h264.params.end());
2993 EXPECT_EQ(found->second, "42A01E");
2994 found = h264.params.find("sprop-parameter-sets");
2995 ASSERT_TRUE(found != h264.params.end());
2996 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
2997}
2998
Donald Curtis0e07f922015-05-15 16:21:232999TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 18:27:413000 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 16:21:233001
3002 const char kSdpWithFmtpString[] =
3003 "v=0\r\n"
3004 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3005 "s=-\r\n"
3006 "t=0 0\r\n"
3007 "m=video 3457 RTP/SAVPF 120\r\n"
3008 "a=rtpmap:120 VP8/90000\r\n"
3009 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363010
3011 // Deserialize
3012 SdpParseError error;
3013 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3014 &error));
3015
henrike@webrtc.org28e20752013-07-10 00:45:363016 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303017 GetFirstVideoContentDescription(jdesc_output.description());
3018 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:363019 ASSERT_FALSE(vcd->codecs().empty());
3020 cricket::VideoCodec vp8 = vcd->codecs()[0];
3021 EXPECT_EQ("VP8", vp8.name);
3022 EXPECT_EQ(120, vp8.id);
3023 cricket::CodecParameterMap::iterator found =
3024 vp8.params.find("x-google-min-bitrate");
3025 ASSERT_TRUE(found != vp8.params.end());
3026 EXPECT_EQ(found->second, "10");
3027 found = vp8.params.find("x-google-max-quantization");
3028 ASSERT_TRUE(found != vp8.params.end());
3029 EXPECT_EQ(found->second, "40");
3030}
3031
ossuaa4b0772017-01-30 15:41:183032TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 23:14:303033 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183034
3035 cricket::AudioCodecs codecs = acd->codecs();
3036 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3037 acd->set_codecs(codecs);
3038
3039 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3040 jdesc_.session_id(),
3041 jdesc_.session_version()));
3042 std::string message = webrtc::SdpSerialize(jdesc_, false);
3043 std::string sdp_with_fmtp = kSdpFullString;
3044 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3045 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3046 &sdp_with_fmtp);
3047 EXPECT_EQ(sdp_with_fmtp, message);
3048}
3049
3050TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 23:14:303051 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183052
3053 cricket::AudioCodecs codecs = acd->codecs();
3054 codecs[0].params["stereo"] = "1";
3055 acd->set_codecs(codecs);
3056
3057 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3058 jdesc_.session_id(),
3059 jdesc_.session_version()));
3060 std::string message = webrtc::SdpSerialize(jdesc_, false);
3061 std::string sdp_with_fmtp = kSdpFullString;
3062 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3063 "a=fmtp:111 stereo=1\r\n",
3064 &sdp_with_fmtp);
3065 EXPECT_EQ(sdp_with_fmtp, message);
3066}
3067
3068TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 23:14:303069 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183070
3071 cricket::AudioCodecs codecs = acd->codecs();
3072 codecs[0].params["ptime"] = "20";
3073 codecs[0].params["maxptime"] = "120";
3074 acd->set_codecs(codecs);
3075
3076 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3077 jdesc_.session_id(),
3078 jdesc_.session_version()));
3079 std::string message = webrtc::SdpSerialize(jdesc_, false);
3080 std::string sdp_with_fmtp = kSdpFullString;
3081 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3082 "a=maxptime:120\r\n" // No comma here. String merging!
3083 "a=ptime:20\r\n",
3084 &sdp_with_fmtp);
3085 EXPECT_EQ(sdp_with_fmtp, message);
3086}
3087
henrike@webrtc.org28e20752013-07-10 00:45:363088TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 23:14:303089 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:363090
3091 cricket::VideoCodecs codecs = vcd->codecs();
3092 codecs[0].params["x-google-min-bitrate"] = "10";
3093 vcd->set_codecs(codecs);
3094
3095 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3096 jdesc_.session_id(),
3097 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:103098 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:363099 std::string sdp_with_fmtp = kSdpFullString;
3100 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3101 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3102 &sdp_with_fmtp);
3103 EXPECT_EQ(sdp_with_fmtp, message);
3104}
3105
3106TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
Steve Antona3a92c22017-12-07 18:27:413107 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363108 std::string sdp_with_icelite = kSdpFullString;
3109 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3110 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3111 const cricket::TransportInfo* tinfo1 =
3112 desc->GetTransportInfoByName("audio_content_name");
3113 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3114 const cricket::TransportInfo* tinfo2 =
3115 desc->GetTransportInfoByName("video_content_name");
3116 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3117 InjectAfter(kSessionTime,
3118 "a=ice-lite\r\n",
3119 &sdp_with_icelite);
3120 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3121 desc = jdesc_with_icelite.description();
3122 const cricket::TransportInfo* atinfo =
3123 desc->GetTransportInfoByName("audio_content_name");
3124 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3125 const cricket::TransportInfo* vtinfo =
3126 desc->GetTransportInfoByName("video_content_name");
3127 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3128}
3129
3130// Verifies that the candidates in the input SDP are parsed and serialized
3131// correctly in the output SDP.
3132TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3133 std::string sdp_with_data = kSdpString;
3134 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 18:27:413135 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363136
3137 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-17 01:54:103138 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:363139}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253140
3141TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3142 AddFingerprint();
3143 TransportInfo audio_transport_info =
3144 *(desc_.GetTransportInfoByName(kAudioContentName));
3145 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3146 audio_transport_info.description.connection_role);
3147 audio_transport_info.description.connection_role =
3148 cricket::CONNECTIONROLE_ACTIVE;
3149
3150 TransportInfo video_transport_info =
3151 *(desc_.GetTransportInfoByName(kVideoContentName));
3152 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3153 video_transport_info.description.connection_role);
3154 video_transport_info.description.connection_role =
3155 cricket::CONNECTIONROLE_ACTIVE;
3156
3157 desc_.RemoveTransportInfoByName(kAudioContentName);
3158 desc_.RemoveTransportInfoByName(kVideoContentName);
3159
3160 desc_.AddTransportInfo(audio_transport_info);
3161 desc_.AddTransportInfo(video_transport_info);
3162
3163 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3164 jdesc_.session_id(),
3165 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:103166 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253167 std::string sdp_with_dtlssetup = kSdpFullString;
3168
3169 // Fingerprint attribute is necessary to add DTLS setup attribute.
3170 InjectAfter(kAttributeIcePwdVoice,
3171 kFingerprint, &sdp_with_dtlssetup);
3172 InjectAfter(kAttributeIcePwdVideo,
3173 kFingerprint, &sdp_with_dtlssetup);
3174 // Now adding |setup| attribute.
3175 InjectAfter(kFingerprint,
3176 "a=setup:active\r\n", &sdp_with_dtlssetup);
3177 EXPECT_EQ(sdp_with_dtlssetup, message);
3178}
3179
3180TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 18:27:413181 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253182 std::string sdp_with_dtlssetup = kSdpFullString;
3183 InjectAfter(kSessionTime,
3184 "a=setup:actpass\r\n",
3185 &sdp_with_dtlssetup);
3186 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3187 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3188 const cricket::TransportInfo* atinfo =
3189 desc->GetTransportInfoByName("audio_content_name");
3190 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3191 atinfo->description.connection_role);
3192 const cricket::TransportInfo* vtinfo =
3193 desc->GetTransportInfoByName("video_content_name");
3194 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3195 vtinfo->description.connection_role);
3196}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053197
3198// Verifies that the order of the serialized m-lines follows the order of the
3199// ContentInfo in SessionDescription, and vise versa for deserialization.
3200TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 18:27:413201 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053202 const std::string media_content_sdps[3] = {
3203 kSdpAudioString,
3204 kSdpVideoString,
3205 kSdpSctpDataChannelString
3206 };
3207 const cricket::MediaType media_types[3] = {
3208 cricket::MEDIA_TYPE_AUDIO,
3209 cricket::MEDIA_TYPE_VIDEO,
3210 cricket::MEDIA_TYPE_DATA
3211 };
3212
3213 // Verifies all 6 permutations.
3214 for (size_t i = 0; i < 6; ++i) {
3215 size_t media_content_in_sdp[3];
3216 // The index of the first media content.
3217 media_content_in_sdp[0] = i / 2;
3218 // The index of the second media content.
3219 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3220 // The index of the third media content.
3221 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3222
3223 std::string sdp_string = kSdpSessionString;
3224 for (size_t i = 0; i < 3; ++i)
3225 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3226
3227 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3228 cricket::SessionDescription* desc = jdesc.description();
3229 EXPECT_EQ(3u, desc->contents().size());
3230
3231 for (size_t i = 0; i < 3; ++i) {
3232 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 23:14:303233 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:053234 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3235 }
3236
deadbeef9d3584c2016-02-17 01:54:103237 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053238 EXPECT_EQ(sdp_string, serialized_sdp);
3239 }
3240}
deadbeef9d3584c2016-02-17 01:54:103241
deadbeef25ed4352016-12-13 02:37:363242TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3243 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 18:27:413244 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473245 ASSERT_TRUE(
deadbeef25ed4352016-12-13 02:37:363246 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3247 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3248}
3249
deadbeef12771a12017-01-03 21:53:473250// The semantics of "a=bundle-only" are only defined when it's used in
3251// combination with a 0 port on the m= line. We should ignore it if used with a
3252// nonzero port.
3253TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3254 // Make the base bundle-only description but unset the bundle-only flag.
3255 MakeBundleOnlyDescription();
3256 jdesc_.description()->contents()[1].bundle_only = false;
3257
3258 std::string modified_sdp = kBundleOnlySdpFullString;
3259 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 18:27:413260 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473261 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3262 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-13 02:37:363263}
3264
3265TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3266 MakeBundleOnlyDescription();
3267 TestSerialize(jdesc_, false);
3268}
3269
deadbeef9d3584c2016-02-17 01:54:103270TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3271 MakePlanBDescription();
3272
Steve Antona3a92c22017-12-07 18:27:413273 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103274 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3275
3276 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3277}
3278
3279TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3280 MakePlanBDescription();
3281 TestSerialize(jdesc_, false);
3282}
3283
Taylor Brandstetter5de6b752016-03-10 01:02:303284// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3285// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3286// some extent). If we parse this, the Plan B msid attribute (which is more
3287// specific, since it's at the SSRC level) should take priority.
3288TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3289 MakePlanBDescription();
3290
Steve Antona3a92c22017-12-07 18:27:413291 JsepSessionDescription deserialized_description(kDummyType);
Taylor Brandstetter5de6b752016-03-10 01:02:303292 EXPECT_TRUE(
3293 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3294
3295 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3296}
3297
deadbeef9d3584c2016-02-17 01:54:103298TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3299 MakeUnifiedPlanDescription();
3300
Steve Antona3a92c22017-12-07 18:27:413301 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103302 EXPECT_TRUE(
3303 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3304
3305 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3306}
3307
3308TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3309 MakeUnifiedPlanDescription();
3310 TestSerialize(jdesc_, true);
3311}
deadbeef7e146cb2016-09-28 17:04:343312
3313// Regression test for heap overflow bug:
3314// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3315TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 17:04:343316 // The issue occurs when the sctp-port attribute is found in a video
3317 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 20:43:583318 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 17:04:343319 "v=0\r\n"
3320 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3321 "s=-\r\n"
3322 "t=0 0\r\n"
3323 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3324 "a=sctp-port 5000\r\n"
3325 "a=fmtp:108 foo=10\r\n";
3326
3327 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3328 "sctp-port");
3329}
deadbeefb2362572016-12-14 00:37:063330
3331// Regression test for integer overflow bug:
3332// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3333TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-14 00:37:063334 // Bandwidth attribute is the max signed 32-bit int, which will get
3335 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 20:43:583336 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-14 00:37:063337 "v=0\r\n"
3338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3339 "s=-\r\n"
3340 "t=0 0\r\n"
3341 "m=video 3457 RTP/SAVPF 120\r\n"
3342 "b=AS:2147483647\r\n"
3343 "foo=fail\r\n";
3344
3345 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3346}
deadbeef7bcdb692017-01-20 20:43:583347
deadbeefbc88c6b2017-08-02 18:26:343348// Similar to the above, except that negative values are illegal, not just
3349// error-prone as large values are.
3350// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3351TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3352 static const char kSdpWithNegativeBandwidth[] =
3353 "v=0\r\n"
3354 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3355 "s=-\r\n"
3356 "t=0 0\r\n"
3357 "m=video 3457 RTP/SAVPF 120\r\n"
3358 "b=AS:-1000\r\n";
3359
3360 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3361}
3362
deadbeef3e8016e2017-08-04 00:49:303363// An exception to the above rule: a value of -1 for b=AS should just be
3364// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3365// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3366// limit", but this is now what ommitting the attribute entirely will do, so
3367// ignoring it will have the intended effect.
3368TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3369 static const char kSdpWithBandwidthOfNegativeOne[] =
3370 "v=0\r\n"
3371 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3372 "s=-\r\n"
3373 "t=0 0\r\n"
3374 "m=video 3457 RTP/SAVPF 120\r\n"
3375 "b=AS:-1\r\n";
3376
Steve Antona3a92c22017-12-07 18:27:413377 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-04 00:49:303378 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-04 00:49:303379 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303380 GetFirstVideoContentDescription(jdesc_output.description());
3381 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-04 00:49:303382 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3383}
3384
deadbeef7bcdb692017-01-20 20:43:583385// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3386// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3387// Regression test for:
3388// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3389TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3390 // Important piece is "ufrag foo pwd bar".
3391 static const char kSdpWithIceCredentialsInCandidateString[] =
3392 "v=0\r\n"
3393 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3394 "s=-\r\n"
3395 "t=0 0\r\n"
3396 "m=audio 9 RTP/SAVPF 111\r\n"
3397 "c=IN IP4 0.0.0.0\r\n"
3398 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3399 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3400 "a=rtpmap:111 opus/48000/2\r\n"
3401 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3402 "generation 2 ufrag foo pwd bar\r\n";
3403
Steve Antona3a92c22017-12-07 18:27:413404 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 20:43:583405 EXPECT_TRUE(
3406 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3407 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3408 ASSERT_NE(nullptr, candidates);
3409 ASSERT_EQ(1, candidates->count());
3410 cricket::Candidate c = candidates->at(0)->candidate();
3411 EXPECT_EQ("ufrag_voice", c.username());
3412 EXPECT_EQ("pwd_voice", c.password());
3413}
deadbeef90f1e1e2017-02-10 20:35:053414
3415// Test that SDP with an invalid port number in "a=candidate" lines is
3416// rejected, without crashing.
3417// Regression test for:
3418// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3419TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3420 static const char kSdpWithInvalidCandidatePort[] =
3421 "v=0\r\n"
3422 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3423 "s=-\r\n"
3424 "t=0 0\r\n"
3425 "m=audio 9 RTP/SAVPF 111\r\n"
3426 "c=IN IP4 0.0.0.0\r\n"
3427 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3428 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3429 "a=rtpmap:111 opus/48000/2\r\n"
3430 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3431 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3432
Steve Antona3a92c22017-12-07 18:27:413433 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 20:35:053434 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3435}
deadbeefa4549d62017-02-11 01:26:223436
3437// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3438// Regression test for:
3439// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3440TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3441 static const char kSdpWithMissingTrackId[] =
3442 "v=0\r\n"
3443 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3444 "s=-\r\n"
3445 "t=0 0\r\n"
3446 "m=audio 9 RTP/SAVPF 111\r\n"
3447 "c=IN IP4 0.0.0.0\r\n"
3448 "a=rtpmap:111 opus/48000/2\r\n"
3449 "a=msid:stream_id \r\n";
3450
Steve Antona3a92c22017-12-07 18:27:413451 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:223452 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3453}
3454
3455TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3456 static const char kSdpWithMissingStreamId[] =
3457 "v=0\r\n"
3458 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3459 "s=-\r\n"
3460 "t=0 0\r\n"
3461 "m=audio 9 RTP/SAVPF 111\r\n"
3462 "c=IN IP4 0.0.0.0\r\n"
3463 "a=rtpmap:111 opus/48000/2\r\n"
3464 "a=msid: track_id\r\n";
3465
Steve Antona3a92c22017-12-07 18:27:413466 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:223467 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3468}
zhihuang38989e52017-03-21 18:04:533469
3470// Tests that if both session-level address and media-level address exist, use
3471// the media-level address.
3472TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 18:27:413473 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:533474
3475 // Sesssion-level address.
3476 std::string sdp = kSdpFullString;
3477 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3478 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3479
3480 const auto& content1 = jsep_desc.description()->contents()[0];
3481 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 23:14:303482 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533483 const auto& content2 = jsep_desc.description()->contents()[1];
3484 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 23:14:303485 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533486}
3487
3488// Tests that the session-level connection address will be used if the media
3489// level-addresses are not specified.
3490TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 18:27:413491 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:533492
3493 // Sesssion-level address.
3494 std::string sdp = kSdpString;
3495 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3496 // Remove the media level addresses.
3497 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3498 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3499 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3500
3501 const auto& content1 = jsep_desc.description()->contents()[0];
3502 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:303503 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533504 const auto& content2 = jsep_desc.description()->contents()[1];
3505 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:303506 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533507}
3508
3509TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 18:27:413510 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:533511
3512 std::string sdp = kSdpString;
3513 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3514 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3515 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3516 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3517 &sdp);
3518 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3519 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3520 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3521 &sdp);
3522 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3523 const auto& content1 = jsep_desc.description()->contents()[0];
3524 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 23:14:303525 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533526 const auto& content2 = jsep_desc.description()->contents()[1];
3527 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 23:14:303528 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:533529}
3530
3531// Test that the invalid or unsupprted connection data cannot be parsed.
3532TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 18:27:413533 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:533534 std::string sdp = kSdpString;
3535 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3536
3537 // Unsupported multicast IPv4 address.
3538 sdp = kSdpFullString;
3539 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3540 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3541
3542 // Unsupported multicast IPv6 address.
3543 sdp = kSdpFullString;
3544 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3545 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3546
3547 // Mismatched address type.
3548 sdp = kSdpFullString;
3549 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3550 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3551
3552 sdp = kSdpFullString;
3553 Replace("c=IN IP4 74.125.224.39\r\n",
3554 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3555 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3556}
3557
3558TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 18:27:413559 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 18:04:533560 MakeDescriptionWithoutCandidates(&expected_jsep);
3561 // Serialization.
3562 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3563 // Deserialization.
Steve Antona3a92c22017-12-07 18:27:413564 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 18:04:533565 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 23:14:303566 auto audio_desc = jdesc.description()
3567 ->GetContentByName(kAudioContentName)
3568 ->media_description();
3569 auto video_desc = jdesc.description()
3570 ->GetContentByName(kVideoContentName)
3571 ->media_description();
zhihuang38989e52017-03-21 18:04:533572 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3573 audio_desc->connection_address().ToString());
3574 EXPECT_EQ(video_desc_->connection_address().ToString(),
3575 video_desc->connection_address().ToString());
3576}