blob: 9c39c417518f136042fe5fae3df2a9e7ac4402b4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/p2pconstants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/mediasession.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/gunit.h"
24#include "rtc_base/logging.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020025#include "rtc_base/messagedigest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/stringencode.h"
27#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020028
ossu7bb87ee2017-01-23 04:56:25 -080029#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34using cricket::AudioCodec;
35using cricket::AudioContentDescription;
36using cricket::Candidate;
37using cricket::ContentInfo;
38using cricket::CryptoParams;
39using cricket::ContentGroup;
40using cricket::DataCodec;
41using cricket::DataContentDescription;
42using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
43using cricket::ICE_CANDIDATE_COMPONENT_RTP;
44using cricket::kFecSsrcGroupSemantics;
45using cricket::LOCAL_PORT_TYPE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080048using cricket::MediaProtocolType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using cricket::StreamParams;
50using cricket::STUN_PORT_TYPE;
51using cricket::TransportDescription;
52using cricket::TransportInfo;
53using cricket::VideoCodec;
54using cricket::VideoContentDescription;
55using webrtc::IceCandidateCollection;
56using webrtc::IceCandidateInterface;
57using webrtc::JsepIceCandidate;
58using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070059using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080060using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080062using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::SessionDescriptionInterface;
64
65typedef std::vector<AudioCodec> AudioCodecs;
66typedef std::vector<Candidate> Candidates;
67
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080069static const char kDefaultSctpPortStr[] = "5000";
70static const uint16_t kUnusualSctpPort = 9556;
71static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020073static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080074static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080076static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020078static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079static const char kCandidateFoundation1[] = "a0+B/1";
80static const char kCandidateFoundation2[] = "a0+B/2";
81static const char kCandidateFoundation3[] = "a0+B/3";
82static const char kCandidateFoundation4[] = "a0+B/4";
83static const char kAttributeCryptoVoice[] =
84 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
85 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
86 "dummy_session_params\r\n";
87static const char kAttributeCryptoVideo[] =
88 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
89 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +020090static const char kFingerprint[] =
91 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
93static const int kExtmapId = 1;
94static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
95static const char kExtmap[] =
96 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
97static const char kExtmapWithDirectionAndAttribute[] =
98 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -070099static const char kExtmapWithDirectionAndAttributeEncrypted[] =
100 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
101 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
Peter Boström0c4e06b2015-10-07 12:23:21 +0200103static const uint8_t kIdentityDigest[] = {
104 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
105 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106
lally@webrtc.org34807282015-02-24 20:19:39 +0000107static const char kDtlsSctp[] = "DTLS/SCTP";
108static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
109static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000110
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111struct CodecParams {
112 int max_ptime;
113 int ptime;
114 int min_ptime;
115 int sprop_stereo;
116 int stereo;
117 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000118 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119};
120
deadbeef9d3584c2016-02-16 17:54:10 -0800121// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
122// instead of "a=crypto", and have an explicit test for adding "a=crypto".
123// Currently it's the other way around.
124
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125// Reference sdp string
126static const char kSdpFullString[] =
127 "v=0\r\n"
128 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
129 "s=-\r\n"
130 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800131 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
133 "c=IN IP4 74.125.127.126\r\n"
134 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
135 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
140 "generation 2\r\n"
141 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
142 "generation 2\r\n"
143 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
144 "raddr 192.168.1.5 rport 2346 "
145 "generation 2\r\n"
146 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
147 "raddr 192.168.1.5 rport 2348 "
148 "generation 2\r\n"
149 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
150 "a=mid:audio_content_name\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800153 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
155 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
156 "dummy_session_params\r\n"
157 "a=rtpmap:111 opus/48000/2\r\n"
158 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000159 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160 "a=ssrc:1 cname:stream_1_cname\r\n"
161 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
162 "a=ssrc:1 mslabel:local_stream_1\r\n"
163 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 "m=video 3457 RTP/SAVPF 120\r\n"
165 "c=IN IP4 74.125.224.39\r\n"
166 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
167 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
172 "generation 2\r\n"
173 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
174 "generation 2\r\n"
175 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
176 "generation 2\r\n"
177 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
178 "generation 2\r\n"
179 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
180 "a=mid:video_content_name\r\n"
181 "a=sendrecv\r\n"
182 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
183 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
184 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800185 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "a=ssrc:2 cname:stream_1_cname\r\n"
187 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
188 "a=ssrc:2 mslabel:local_stream_1\r\n"
189 "a=ssrc:2 label:video_track_id_1\r\n"
190 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800191 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800193 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194
195// SDP reference string without the candidates.
196static const char kSdpString[] =
197 "v=0\r\n"
198 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
199 "s=-\r\n"
200 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800201 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000202 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000203 "c=IN IP4 0.0.0.0\r\n"
204 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
206 "a=mid:audio_content_name\r\n"
207 "a=sendrecv\r\n"
208 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800209 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
211 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
212 "dummy_session_params\r\n"
213 "a=rtpmap:111 opus/48000/2\r\n"
214 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000215 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 "a=ssrc:1 cname:stream_1_cname\r\n"
217 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
218 "a=ssrc:1 mslabel:local_stream_1\r\n"
219 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000220 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000221 "c=IN IP4 0.0.0.0\r\n"
222 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
224 "a=mid:video_content_name\r\n"
225 "a=sendrecv\r\n"
226 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
227 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
228 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800229 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 "a=ssrc:2 cname:stream_1_cname\r\n"
231 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
232 "a=ssrc:2 mslabel:local_stream_1\r\n"
233 "a=ssrc:2 label:video_track_id_1\r\n"
234 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800235 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800237 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238
239static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000240 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000241 "c=IN IP4 0.0.0.0\r\n"
242 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 "a=ice-ufrag:ufrag_data\r\n"
244 "a=ice-pwd:pwd_data\r\n"
245 "a=mid:data_content_name\r\n"
246 "a=sendrecv\r\n"
247 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
248 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
249 "a=rtpmap:101 google-data/90000\r\n"
250 "a=ssrc:10 cname:data_channel_cname\r\n"
251 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
252 "a=ssrc:10 mslabel:data_channel\r\n"
253 "a=ssrc:10 label:data_channeld0\r\n";
254
255static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000256 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000257 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=ice-ufrag:ufrag_data\r\n"
259 "a=ice-pwd:pwd_data\r\n"
260 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000261 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000263// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000264static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000265 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
266 "a=max-message-size=100000\r\n"
267 "a=sctp-port 5000\r\n"
268 "c=IN IP4 0.0.0.0\r\n"
269 "a=ice-ufrag:ufrag_data\r\n"
270 "a=ice-pwd:pwd_data\r\n"
271 "a=mid:data_content_name\r\n";
272
lally69f57602015-10-08 10:15:04 -0700273static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
274 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
275 "a=max-message-size=100000\r\n"
276 "a=sctp-port:5000\r\n"
277 "c=IN IP4 0.0.0.0\r\n"
278 "a=ice-ufrag:ufrag_data\r\n"
279 "a=ice-pwd:pwd_data\r\n"
280 "a=mid:data_content_name\r\n";
281
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282static const char kSdpSctpDataChannelWithCandidatesString[] =
283 "m=application 2345 DTLS/SCTP 5000\r\n"
284 "c=IN IP4 74.125.127.126\r\n"
285 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
286 "generation 2\r\n"
287 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
288 "generation 2\r\n"
289 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
290 "raddr 192.168.1.5 rport 2346 "
291 "generation 2\r\n"
292 "a=ice-ufrag:ufrag_data\r\n"
293 "a=ice-pwd:pwd_data\r\n"
294 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000295 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000297static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000298 "v=0\r\n"
299 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
300 "s=-\r\n"
301 "t=0 0\r\n"
302 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000303 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000304 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000305 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000306 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000307 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000308 "a=x-google-flag:conference\r\n";
309
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000310static const char kSdpSessionString[] =
311 "v=0\r\n"
312 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
313 "s=-\r\n"
314 "t=0 0\r\n"
315 "a=msid-semantic: WMS local_stream\r\n";
316
317static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000318 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000319 "c=IN IP4 0.0.0.0\r\n"
320 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000321 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
322 "a=mid:audio_content_name\r\n"
323 "a=sendrecv\r\n"
324 "a=rtpmap:111 opus/48000/2\r\n"
325 "a=ssrc:1 cname:stream_1_cname\r\n"
326 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
327 "a=ssrc:1 mslabel:local_stream\r\n"
328 "a=ssrc:1 label:audio_track_id_1\r\n";
329
330static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000331 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000332 "c=IN IP4 0.0.0.0\r\n"
333 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000334 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
335 "a=mid:video_content_name\r\n"
336 "a=sendrecv\r\n"
337 "a=rtpmap:120 VP8/90000\r\n"
338 "a=ssrc:2 cname:stream_1_cname\r\n"
339 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
340 "a=ssrc:2 mslabel:local_stream\r\n"
341 "a=ssrc:2 label:video_track_id_1\r\n";
342
deadbeef25ed4352016-12-12 18:37:36 -0800343// Reference sdp string using bundle-only.
344static const char kBundleOnlySdpFullString[] =
345 "v=0\r\n"
346 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
347 "s=-\r\n"
348 "t=0 0\r\n"
349 "a=group:BUNDLE audio_content_name video_content_name\r\n"
350 "a=msid-semantic: WMS local_stream_1\r\n"
351 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
352 "c=IN IP4 74.125.127.126\r\n"
353 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
354 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
359 "generation 2\r\n"
360 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
361 "generation 2\r\n"
362 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
363 "raddr 192.168.1.5 rport 2346 "
364 "generation 2\r\n"
365 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
366 "raddr 192.168.1.5 rport 2348 "
367 "generation 2\r\n"
368 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
369 "a=mid:audio_content_name\r\n"
370 "a=sendrecv\r\n"
371 "a=rtcp-mux\r\n"
372 "a=rtcp-rsize\r\n"
373 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
374 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
375 "dummy_session_params\r\n"
376 "a=rtpmap:111 opus/48000/2\r\n"
377 "a=rtpmap:103 ISAC/16000\r\n"
378 "a=rtpmap:104 ISAC/32000\r\n"
379 "a=ssrc:1 cname:stream_1_cname\r\n"
380 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
381 "a=ssrc:1 mslabel:local_stream_1\r\n"
382 "a=ssrc:1 label:audio_track_id_1\r\n"
383 "m=video 0 RTP/SAVPF 120\r\n"
384 "c=IN IP4 0.0.0.0\r\n"
385 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
386 "a=bundle-only\r\n"
387 "a=mid:video_content_name\r\n"
388 "a=sendrecv\r\n"
389 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
390 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
391 "a=rtpmap:120 VP8/90000\r\n"
392 "a=ssrc-group:FEC 2 3\r\n"
393 "a=ssrc:2 cname:stream_1_cname\r\n"
394 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
395 "a=ssrc:2 mslabel:local_stream_1\r\n"
396 "a=ssrc:2 label:video_track_id_1\r\n"
397 "a=ssrc:3 cname:stream_1_cname\r\n"
398 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
399 "a=ssrc:3 mslabel:local_stream_1\r\n"
400 "a=ssrc:3 label:video_track_id_1\r\n";
401
deadbeef9d3584c2016-02-16 17:54:10 -0800402// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
403// tracks.
404static const char kPlanBSdpFullString[] =
405 "v=0\r\n"
406 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
407 "s=-\r\n"
408 "t=0 0\r\n"
409 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
410 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
411 "c=IN IP4 74.125.127.126\r\n"
412 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
413 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
418 "generation 2\r\n"
419 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
420 "generation 2\r\n"
421 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
422 "raddr 192.168.1.5 rport 2346 "
423 "generation 2\r\n"
424 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
425 "raddr 192.168.1.5 rport 2348 "
426 "generation 2\r\n"
427 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
428 "a=mid:audio_content_name\r\n"
429 "a=sendrecv\r\n"
430 "a=rtcp-mux\r\n"
431 "a=rtcp-rsize\r\n"
432 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
433 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
434 "dummy_session_params\r\n"
435 "a=rtpmap:111 opus/48000/2\r\n"
436 "a=rtpmap:103 ISAC/16000\r\n"
437 "a=rtpmap:104 ISAC/32000\r\n"
438 "a=ssrc:1 cname:stream_1_cname\r\n"
439 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
440 "a=ssrc:1 mslabel:local_stream_1\r\n"
441 "a=ssrc:1 label:audio_track_id_1\r\n"
442 "a=ssrc:4 cname:stream_2_cname\r\n"
443 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
444 "a=ssrc:4 mslabel:local_stream_2\r\n"
445 "a=ssrc:4 label:audio_track_id_2\r\n"
446 "m=video 3457 RTP/SAVPF 120\r\n"
447 "c=IN IP4 74.125.224.39\r\n"
448 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
449 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
454 "generation 2\r\n"
455 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
456 "generation 2\r\n"
457 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
458 "generation 2\r\n"
459 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
460 "generation 2\r\n"
461 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
462 "a=mid:video_content_name\r\n"
463 "a=sendrecv\r\n"
464 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
465 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
466 "a=rtpmap:120 VP8/90000\r\n"
467 "a=ssrc-group:FEC 2 3\r\n"
468 "a=ssrc:2 cname:stream_1_cname\r\n"
469 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
470 "a=ssrc:2 mslabel:local_stream_1\r\n"
471 "a=ssrc:2 label:video_track_id_1\r\n"
472 "a=ssrc:3 cname:stream_1_cname\r\n"
473 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
474 "a=ssrc:3 mslabel:local_stream_1\r\n"
475 "a=ssrc:3 label:video_track_id_1\r\n"
476 "a=ssrc:5 cname:stream_2_cname\r\n"
477 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
478 "a=ssrc:5 mslabel:local_stream_2\r\n"
479 "a=ssrc:5 label:video_track_id_2\r\n"
480 "a=ssrc:6 cname:stream_2_cname\r\n"
481 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
482 "a=ssrc:6 mslabel:local_stream_2\r\n"
483 "a=ssrc:6 label:video_track_id_3\r\n";
484
485// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
486// tracks.
487static const char kUnifiedPlanSdpFullString[] =
488 "v=0\r\n"
489 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
490 "s=-\r\n"
491 "t=0 0\r\n"
492 "a=msid-semantic: WMS local_stream_1\r\n"
493 // Audio track 1, stream 1 (with candidates).
494 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
495 "c=IN IP4 74.125.127.126\r\n"
496 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
497 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
498 "generation 2\r\n"
499 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
500 "generation 2\r\n"
501 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
502 "generation 2\r\n"
503 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
504 "generation 2\r\n"
505 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
506 "raddr 192.168.1.5 rport 2346 "
507 "generation 2\r\n"
508 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
509 "raddr 192.168.1.5 rport 2348 "
510 "generation 2\r\n"
511 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
512 "a=mid:audio_content_name\r\n"
513 "a=msid:local_stream_1 audio_track_id_1\r\n"
514 "a=sendrecv\r\n"
515 "a=rtcp-mux\r\n"
516 "a=rtcp-rsize\r\n"
517 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
518 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
519 "dummy_session_params\r\n"
520 "a=rtpmap:111 opus/48000/2\r\n"
521 "a=rtpmap:103 ISAC/16000\r\n"
522 "a=rtpmap:104 ISAC/32000\r\n"
523 "a=ssrc:1 cname:stream_1_cname\r\n"
524 // Video track 1, stream 1 (with candidates).
525 "m=video 3457 RTP/SAVPF 120\r\n"
526 "c=IN IP4 74.125.224.39\r\n"
527 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
528 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
533 "generation 2\r\n"
534 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
535 "generation 2\r\n"
536 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
537 "generation 2\r\n"
538 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
539 "generation 2\r\n"
540 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
541 "a=mid:video_content_name\r\n"
542 "a=msid:local_stream_1 video_track_id_1\r\n"
543 "a=sendrecv\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
545 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
546 "a=rtpmap:120 VP8/90000\r\n"
547 "a=ssrc-group:FEC 2 3\r\n"
548 "a=ssrc:2 cname:stream_1_cname\r\n"
549 "a=ssrc:3 cname:stream_1_cname\r\n"
550 // Audio track 2, stream 2.
551 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
552 "c=IN IP4 0.0.0.0\r\n"
553 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
554 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
555 "a=mid:audio_content_name_2\r\n"
556 "a=msid:local_stream_2 audio_track_id_2\r\n"
557 "a=sendrecv\r\n"
558 "a=rtcp-mux\r\n"
559 "a=rtcp-rsize\r\n"
560 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
561 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
562 "dummy_session_params\r\n"
563 "a=rtpmap:111 opus/48000/2\r\n"
564 "a=rtpmap:103 ISAC/16000\r\n"
565 "a=rtpmap:104 ISAC/32000\r\n"
566 "a=ssrc:4 cname:stream_2_cname\r\n"
567 // Video track 2, stream 2.
568 "m=video 9 RTP/SAVPF 120\r\n"
569 "c=IN IP4 0.0.0.0\r\n"
570 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
571 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
572 "a=mid:video_content_name_2\r\n"
573 "a=msid:local_stream_2 video_track_id_2\r\n"
574 "a=sendrecv\r\n"
575 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
576 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
577 "a=rtpmap:120 VP8/90000\r\n"
578 "a=ssrc:5 cname:stream_2_cname\r\n"
579 // Video track 3, stream 2.
580 "m=video 9 RTP/SAVPF 120\r\n"
581 "c=IN IP4 0.0.0.0\r\n"
582 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
583 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
584 "a=mid:video_content_name_3\r\n"
585 "a=msid:local_stream_2 video_track_id_3\r\n"
586 "a=sendrecv\r\n"
587 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
588 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
589 "a=rtpmap:120 VP8/90000\r\n"
590 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591
Seth Hampson5b4f0752018-04-02 16:31:36 -0700592// Unified Plan SDP reference string:
593// - audio track 1 has 1 a=msid lines
594// - audio track 2 has 2 a=msid lines
595// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
596// there are 0 media stream ids.
597// This Unified Plan SDP represents a SDP that signals the msid using both
598// a=msid and a=ssrc msid semantics.
599static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
600 "v=0\r\n"
601 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
602 "s=-\r\n"
603 "t=0 0\r\n"
604 "a=msid-semantic: WMS local_stream_1\r\n"
605 // Audio track 1, with 1 stream id.
606 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
607 "c=IN IP4 74.125.127.126\r\n"
608 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
609 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
610 "generation 2\r\n"
611 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
616 "generation 2\r\n"
617 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
618 "raddr 192.168.1.5 rport 2346 "
619 "generation 2\r\n"
620 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
621 "raddr 192.168.1.5 rport 2348 "
622 "generation 2\r\n"
623 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
624 "a=mid:audio_content_name\r\n"
625 "a=msid:local_stream_1 audio_track_id_1\r\n"
626 "a=sendrecv\r\n"
627 "a=rtcp-mux\r\n"
628 "a=rtcp-rsize\r\n"
629 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
630 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
631 "dummy_session_params\r\n"
632 "a=rtpmap:111 opus/48000/2\r\n"
633 "a=rtpmap:103 ISAC/16000\r\n"
634 "a=rtpmap:104 ISAC/32000\r\n"
635 "a=ssrc:1 cname:stream_1_cname\r\n"
636 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
637 "a=ssrc:1 mslabel:local_stream_1\r\n"
638 "a=ssrc:1 label:audio_track_id_1\r\n"
639 // Audio track 2, with two stream ids.
640 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
641 "c=IN IP4 0.0.0.0\r\n"
642 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
643 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
644 "a=mid:audio_content_name_2\r\n"
645 "a=msid:local_stream_1 audio_track_id_2\r\n"
646 "a=msid:local_stream_2 audio_track_id_2\r\n"
647 "a=sendrecv\r\n"
648 "a=rtcp-mux\r\n"
649 "a=rtcp-rsize\r\n"
650 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
651 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
652 "dummy_session_params\r\n"
653 "a=rtpmap:111 opus/48000/2\r\n"
654 "a=rtpmap:103 ISAC/16000\r\n"
655 "a=rtpmap:104 ISAC/32000\r\n"
656 "a=ssrc:4 cname:stream_1_cname\r\n"
657 // The support for Plan B msid signaling only includes the
658 // first media stream id "local_stream_1."
659 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
660 "a=ssrc:4 mslabel:local_stream_1\r\n"
661 "a=ssrc:4 label:audio_track_id_2\r\n"
662 // Audio track 3, with no stream ids.
663 "m=audio 9 RTP/SAVPF 111 103 104\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_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
667 "a=mid:audio_content_name_3\r\n"
668 "a=msid:- audio_track_id_3\r\n"
669 "a=sendrecv\r\n"
670 "a=rtcp-mux\r\n"
671 "a=rtcp-rsize\r\n"
672 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
673 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
674 "dummy_session_params\r\n"
675 "a=rtpmap:111 opus/48000/2\r\n"
676 "a=rtpmap:103 ISAC/16000\r\n"
677 "a=rtpmap:104 ISAC/32000\r\n"
678 "a=ssrc:7 cname:stream_2_cname\r\n";
679
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680// One candidate reference string as per W3c spec.
681// candidate:<blah> not a=candidate:<blah>CRLF
682static const char kRawCandidate[] =
683 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
684// One candidate reference string.
685static const char kSdpOneCandidate[] =
686 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
687 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000688
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000689static const char kSdpTcpActiveCandidate[] =
690 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
691 "tcptype active generation 2";
692static const char kSdpTcpPassiveCandidate[] =
693 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
694 "tcptype passive generation 2";
695static const char kSdpTcpSOCandidate[] =
696 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
697 "tcptype so generation 2";
698static const char kSdpTcpInvalidCandidate[] =
699 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
700 "tcptype invalid generation 2";
701
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000702// One candidate reference string with IPV6 address.
703static const char kRawIPV6Candidate[] =
704 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700705 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706
707// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800708static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800710 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711
Zach Steinb336c272018-08-09 01:16:13 -0700712static const char kRawHostnameCandidate[] =
713 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
714
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715// Session id and version
716static const char kSessionId[] = "18446744069414584320";
717static const char kSessionVersion[] = "18446462598732840960";
718
deadbeef9d3584c2016-02-16 17:54:10 -0800719// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720static const char kIceOption1[] = "iceoption1";
721static const char kIceOption2[] = "iceoption2";
722static const char kIceOption3[] = "iceoption3";
723
deadbeef9d3584c2016-02-16 17:54:10 -0800724// ICE ufrags/passwords.
725static const char kUfragVoice[] = "ufrag_voice";
726static const char kPwdVoice[] = "pwd_voice";
727static const char kUfragVideo[] = "ufrag_video";
728static const char kPwdVideo[] = "pwd_video";
729static const char kUfragData[] = "ufrag_data";
730static const char kPwdData[] = "pwd_data";
731
732// Extra ufrags/passwords for extra unified plan m= sections.
733static const char kUfragVoice2[] = "ufrag_voice_2";
734static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700735static const char kUfragVoice3[] = "ufrag_voice_3";
736static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800737static const char kUfragVideo2[] = "ufrag_video_2";
738static const char kPwdVideo2[] = "pwd_video_2";
739static const char kUfragVideo3[] = "ufrag_video_3";
740static const char kPwdVideo3[] = "pwd_video_3";
741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742// Content name
743static const char kAudioContentName[] = "audio_content_name";
744static const char kVideoContentName[] = "video_content_name";
745static const char kDataContentName[] = "data_content_name";
746
deadbeef9d3584c2016-02-16 17:54:10 -0800747// Extra content names for extra unified plan m= sections.
748static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700749static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800750static const char kVideoContentName2[] = "video_content_name_2";
751static const char kVideoContentName3[] = "video_content_name_3";
752
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800754static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755static const char kStream1Cname[] = "stream_1_cname";
756static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200757static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800759static const uint32_t kVideoTrack1Ssrc1 = 2;
760static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761
762// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800763static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764static const char kStream2Cname[] = "stream_2_cname";
765static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200766static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800767static const char kVideoTrackId2[] = "video_track_id_2";
768static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800770static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700771static const char kAudioTrackId3[] = "audio_track_id_3";
772static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773
774// DataChannel
775static const char kDataChannelLabel[] = "data_channel";
776static const char kDataChannelMsid[] = "data_channeld0";
777static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200778static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779
780// Candidate
781static const char kDummyMid[] = "dummy_mid";
782static const int kDummyIndex = 123;
783
784// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800785static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
787// Helper functions
788
789static bool SdpDeserialize(const std::string& message,
790 JsepSessionDescription* jdesc) {
791 return webrtc::SdpDeserialize(message, jdesc, NULL);
792}
793
794static bool SdpDeserializeCandidate(const std::string& message,
795 JsepIceCandidate* candidate) {
796 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
797}
798
799// Add some extra |newlines| to the |message| after |line|.
800static void InjectAfter(const std::string& line,
801 const std::string& newlines,
802 std::string* message) {
803 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200804 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
805 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806}
807
808static void Replace(const std::string& line,
809 const std::string& newlines,
810 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200811 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
812 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813}
814
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000815// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
816// message.
817static void ExpectParseFailure(const std::string& bad_sdp,
818 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800819 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000821 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000823 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
824}
825
826// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
827static void ExpectParseFailure(const char* good_part, const char* bad_part) {
828 std::string bad_sdp = kSdpFullString;
829 Replace(good_part, bad_part, &bad_sdp);
830 ExpectParseFailure(bad_sdp, bad_part);
831}
832
833// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
834static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
835 const std::string& newlines,
836 const std::string& bad_part) {
837 std::string bad_sdp = kSdpFullString;
838 InjectAfter(injectpoint, newlines, &bad_sdp);
839 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840}
841
Steve Anton4e70a722017-11-28 14:57:10 -0800842static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 std::string* message) {
844 std::string new_direction;
845 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800846 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 new_direction = "a=inactive";
848 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800849 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 new_direction = "a=sendonly";
851 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800852 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 new_direction = "a=recvonly";
854 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800855 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 default:
857 new_direction = "a=sendrecv";
858 break;
859 }
860 Replace("a=sendrecv", new_direction, message);
861}
862
Yves Gerey665174f2018-06-19 15:03:05 +0200863static void ReplaceRejected(bool audio_rejected,
864 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 std::string* message) {
866 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800867 Replace("m=audio 9", "m=audio 0", message);
868 Replace(kAttributeIceUfragVoice, "", message);
869 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 }
871 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800872 Replace("m=video 9", "m=video 0", message);
873 Replace(kAttributeIceUfragVideo, "", message);
874 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 }
876}
877
878// WebRtcSdpTest
879
880class WebRtcSdpTest : public testing::Test {
881 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800882 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -0800883#ifdef WEBRTC_ANDROID
884 webrtc::InitializeAndroidObjects();
885#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 // AudioContentDescription
887 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -0800888 StreamParams audio_stream;
889 audio_stream.id = kAudioTrackId1;
890 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800891 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800892 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
893 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -0700894 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
895 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800896 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897
898 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -0800899 video_desc_ = CreateVideoContentDescription();
900 StreamParams video_stream;
901 video_stream.id = kVideoTrackId1;
902 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -0800903 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -0800904 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
905 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
906 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
907 video_stream.ssrc_groups.push_back(ssrc_group);
908 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -0700909 rtc::SocketAddress video_addr("74.125.224.39", 3457);
910 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -0800911 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
913 // TransportInfo
deadbeef9d3584c2016-02-16 17:54:10 -0800914 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
915 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
916 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
917 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918
919 // v4 host
920 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000921 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000922 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000923 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
924 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000926 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000927 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000930 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000931 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
932 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000934 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000935 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
936 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937
938 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000939 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000940 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
941 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000942 cricket::LOCAL_PORT_TYPE,
943 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000945 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
946 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000947 cricket::LOCAL_PORT_TYPE,
948 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000950 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
951 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000952 cricket::LOCAL_PORT_TYPE,
953 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000955 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
956 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000957 cricket::LOCAL_PORT_TYPE,
958 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959
960 // stun
961 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000962 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
963 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000964 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
965 address_stun, kCandidatePriority, "", "",
966 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000967 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 candidate9.set_related_address(rel_address_stun);
969
970 address_stun.SetPort(port_stun++);
971 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000972 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
973 address_stun, kCandidatePriority, "", "",
974 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000975 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 candidate10.set_related_address(rel_address_stun);
977
978 // relay
979 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000980 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000981 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
982 address_relay, kCandidatePriority, "", "",
983 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000984 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +0000986 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
987 address_relay, kCandidatePriority, "", "",
988 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000989 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990
991 // voice
992 candidates_.push_back(candidate1);
993 candidates_.push_back(candidate2);
994 candidates_.push_back(candidate5);
995 candidates_.push_back(candidate6);
996 candidates_.push_back(candidate9);
997 candidates_.push_back(candidate10);
998
999 // video
1000 candidates_.push_back(candidate3);
1001 candidates_.push_back(candidate4);
1002 candidates_.push_back(candidate7);
1003 candidates_.push_back(candidate8);
1004 candidates_.push_back(candidate11);
1005 candidates_.push_back(candidate12);
1006
Yves Gerey665174f2018-06-19 15:03:05 +02001007 jcandidate_.reset(
1008 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009
1010 // Set up JsepSessionDescription.
1011 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1012 std::string mline_id;
1013 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001014 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 // In this test, the audio m line index will be 0, and the video m line
1016 // will be 1.
1017 bool is_video = (i > 5);
1018 mline_id = is_video ? "video_content_name" : "audio_content_name";
1019 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001020 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 jdesc_.AddCandidate(&jice);
1022 }
1023 }
1024
Seth Hampson5b4f0752018-04-02 16:31:36 -07001025 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001026 const IceCandidateCollection* video_candidates_collection =
1027 jdesc_.candidates(1);
1028 ASSERT_NE(nullptr, video_candidates_collection);
1029 std::vector<cricket::Candidate> video_candidates;
1030 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1031 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1032 c.set_transport_name("video_content_name");
1033 video_candidates.push_back(c);
1034 }
1035 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001036 }
1037
1038 // Turns the existing reference description into a description using
1039 // a=bundle-only. This means no transport attributes and a 0 port value on
1040 // the m= sections not associated with the BUNDLE-tag.
1041 void MakeBundleOnlyDescription() {
1042 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001043
1044 // And the rest of the transport attributes.
1045 desc_.transport_infos()[1].description.ice_ufrag.clear();
1046 desc_.transport_infos()[1].description.ice_pwd.clear();
1047 desc_.transport_infos()[1].description.connection_role =
1048 cricket::CONNECTIONROLE_NONE;
1049
1050 // Set bundle-only flag.
1051 desc_.contents()[1].bundle_only = true;
1052
1053 // Add BUNDLE group.
1054 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1055 group.AddContentName(kAudioContentName);
1056 group.AddContentName(kVideoContentName);
1057 desc_.AddGroup(group);
1058
1059 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1060 jdesc_.session_version()));
1061 }
1062
deadbeef9d3584c2016-02-16 17:54:10 -08001063 // Turns the existing reference description into a plan B description,
1064 // with 2 audio tracks and 3 video tracks.
1065 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001066 audio_desc_ = audio_desc_->Copy();
1067 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001068
1069 StreamParams audio_track_2;
1070 audio_track_2.id = kAudioTrackId2;
1071 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001072 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001073 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1074 audio_desc_->AddStream(audio_track_2);
1075
1076 StreamParams video_track_2;
1077 video_track_2.id = kVideoTrackId2;
1078 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001079 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001080 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1081 video_desc_->AddStream(video_track_2);
1082
1083 StreamParams video_track_3;
1084 video_track_3.id = kVideoTrackId3;
1085 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001086 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001087 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1088 video_desc_->AddStream(video_track_3);
1089
1090 desc_.RemoveContentByName(kAudioContentName);
1091 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001092 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1093 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001094
1095 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1096 jdesc_.session_version()));
1097 }
1098
1099 // Turns the existing reference description into a unified plan description,
1100 // with 2 audio tracks and 3 video tracks.
1101 void MakeUnifiedPlanDescription() {
1102 // Audio track 2.
1103 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1104 StreamParams audio_track_2;
1105 audio_track_2.id = kAudioTrackId2;
1106 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001107 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001108 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1109 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001110 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001111 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1112 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-16 17:54:10 -08001113 // Video track 2, in stream 2.
1114 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1115 StreamParams video_track_2;
1116 video_track_2.id = kVideoTrackId2;
1117 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001118 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001119 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1120 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001121 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
deadbeef9d3584c2016-02-16 17:54:10 -08001122 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1123 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1124
1125 // Video track 3, in stream 2.
1126 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1127 StreamParams video_track_3;
1128 video_track_3.id = kVideoTrackId3;
1129 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001130 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001131 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1132 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001133 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
deadbeef9d3584c2016-02-16 17:54:10 -08001134 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1135 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
Steve Antone831b8c2018-02-01 12:22:16 -08001136 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001137
1138 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1139 jdesc_.session_version()));
1140 }
1141
1142 // Creates an audio content description with no streams, and some default
1143 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 AudioContentDescription* CreateAudioContentDescription() {
1145 AudioContentDescription* audio = new AudioContentDescription();
1146 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001147 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001148 audio->AddCrypto(CryptoParams(
1149 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1151 "dummy_session_params"));
1152 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001153 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001154 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001155 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1156 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 return audio;
1158 }
1159
Seth Hampson5b4f0752018-04-02 16:31:36 -07001160 // Turns the existing reference description into a unified plan description,
1161 // with 3 audio MediaContentDescriptions with special StreamParams that
1162 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1163 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
1164 void MakeUnifiedPlanDescriptionMultipleStreamIds() {
1165 desc_.RemoveContentByName(kVideoContentName);
1166 desc_.RemoveTransportInfoByName(kVideoContentName);
1167 RemoveVideoCandidates();
1168
1169 // Audio track 2 has 2 media stream ids.
1170 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1171 StreamParams audio_track_2;
1172 audio_track_2.id = kAudioTrackId2;
1173 audio_track_2.cname = kStream1Cname;
1174 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1175 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1176 audio_desc_2->AddStream(audio_track_2);
1177 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
1178 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1179 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
1180
1181 // Audio track 3 has no stream ids.
1182 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1183 StreamParams audio_track_3;
1184 audio_track_3.id = kAudioTrackId3;
1185 audio_track_3.cname = kStream2Cname;
1186 audio_track_3.set_stream_ids({});
1187 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1188 audio_desc_3->AddStream(audio_track_3);
1189 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
1190 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1191 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))));
1192 // Make sure to create both a=msid lines.
1193 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection |
1194 cricket::kMsidSignalingSsrcAttribute);
1195 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1196 jdesc_.session_version()));
1197 }
1198
Seth Hampson5897a6e2018-04-03 11:16:33 -07001199 // Turns the existing reference description into a unified plan description
1200 // with one audio MediaContentDescription that contains one StreamParams with
1201 // 0 ssrcs.
1202 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1203 desc_.RemoveContentByName(kVideoContentName);
1204 desc_.RemoveContentByName(kAudioContentName);
1205 desc_.RemoveTransportInfoByName(kVideoContentName);
1206 RemoveVideoCandidates();
1207
1208 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1209 StreamParams audio_track;
1210 audio_track.id = kAudioTrackId1;
1211 audio_track.set_stream_ids({kStreamId1});
1212 audio_desc->AddStream(audio_track);
1213 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1214
1215 // Enable signaling a=msid lines.
1216 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1217 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1218 jdesc_.session_version()));
1219 }
1220
deadbeef9d3584c2016-02-16 17:54:10 -08001221 // Creates a video content description with no streams, and some default
1222 // configuration.
1223 VideoContentDescription* CreateVideoContentDescription() {
1224 VideoContentDescription* video = new VideoContentDescription();
1225 video->AddCrypto(CryptoParams(
1226 1, "AES_CM_128_HMAC_SHA1_80",
1227 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1228 video->set_protocol(cricket::kMediaProtocolSavpf);
1229 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001230 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001231 return video;
1232 }
1233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001235 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 // type
1237 EXPECT_EQ(cd1->type(), cd1->type());
1238
1239 // content direction
1240 EXPECT_EQ(cd1->direction(), cd2->direction());
1241
1242 // rtcp_mux
1243 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1244
deadbeef13871492015-12-09 12:37:51 -08001245 // rtcp_reduced_size
1246 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1247
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 // cryptos
1249 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1250 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1251 ADD_FAILURE();
1252 return;
1253 }
Yves Gerey665174f2018-06-19 15:03:05 +02001254 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 const CryptoParams c1 = cd1->cryptos().at(i);
1256 const CryptoParams c2 = cd2->cryptos().at(i);
1257 EXPECT_TRUE(c1.Matches(c2));
1258 EXPECT_EQ(c1.key_params, c2.key_params);
1259 EXPECT_EQ(c1.session_params, c2.session_params);
1260 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001261
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001263 // Use an equivalence class here, for old and new versions of the
1264 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001265 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1266 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1267 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001268 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001269 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1270 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1271 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001272 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001273 } else {
1274 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1275 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276
1277 // codecs
1278 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1279
1280 // bandwidth
1281 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1282
1283 // streams
1284 EXPECT_EQ(cd1->streams(), cd2->streams());
1285
1286 // extmap
1287 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1288 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001289 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001290 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1291 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 EXPECT_EQ(ext1.uri, ext2.uri);
1293 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001294 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 }
1297
zstein4b2e0822017-02-17 19:48:38 -08001298 void CompareDataContentDescription(const DataContentDescription* dcd1,
1299 const DataContentDescription* dcd2) {
1300 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1301 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1302 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303
1304 void CompareSessionDescription(const SessionDescription& desc1,
1305 const SessionDescription& desc2) {
1306 // Compare content descriptions.
1307 if (desc1.contents().size() != desc2.contents().size()) {
1308 ADD_FAILURE();
1309 return;
1310 }
Yves Gerey665174f2018-06-19 15:03:05 +02001311 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1313 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001314 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001316 EXPECT_EQ(c1.type, c2.type);
1317 EXPECT_EQ(c1.rejected, c2.rejected);
1318 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319
1320 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1321 if (IsAudioContent(&c1)) {
1322 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001323 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001325 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1327 }
1328
1329 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1330 if (IsVideoContent(&c1)) {
1331 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001332 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001334 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1336 }
1337
1338 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1339 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001340 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1341 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001342 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 }
1344 }
1345
1346 // group
1347 const cricket::ContentGroups groups1 = desc1.groups();
1348 const cricket::ContentGroups groups2 = desc2.groups();
1349 EXPECT_EQ(groups1.size(), groups1.size());
1350 if (groups1.size() != groups2.size()) {
1351 ADD_FAILURE();
1352 return;
1353 }
1354 for (size_t i = 0; i < groups1.size(); ++i) {
1355 const cricket::ContentGroup group1 = groups1.at(i);
1356 const cricket::ContentGroup group2 = groups2.at(i);
1357 EXPECT_EQ(group1.semantics(), group2.semantics());
1358 const cricket::ContentNames names1 = group1.content_names();
1359 const cricket::ContentNames names2 = group2.content_names();
1360 EXPECT_EQ(names1.size(), names2.size());
1361 if (names1.size() != names2.size()) {
1362 ADD_FAILURE();
1363 return;
1364 }
1365 cricket::ContentNames::const_iterator iter1 = names1.begin();
1366 cricket::ContentNames::const_iterator iter2 = names2.begin();
1367 while (iter1 != names1.end()) {
1368 EXPECT_EQ(*iter1++, *iter2++);
1369 }
1370 }
1371
1372 // transport info
1373 const cricket::TransportInfos transports1 = desc1.transport_infos();
1374 const cricket::TransportInfos transports2 = desc2.transport_infos();
1375 EXPECT_EQ(transports1.size(), transports2.size());
1376 if (transports1.size() != transports2.size()) {
1377 ADD_FAILURE();
1378 return;
1379 }
1380 for (size_t i = 0; i < transports1.size(); ++i) {
1381 const cricket::TransportInfo transport1 = transports1.at(i);
1382 const cricket::TransportInfo transport2 = transports2.at(i);
1383 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 EXPECT_EQ(transport1.description.ice_ufrag,
1385 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001386 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001387 EXPECT_EQ(transport1.description.ice_mode,
1388 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 if (transport1.description.identity_fingerprint) {
1390 EXPECT_EQ(*transport1.description.identity_fingerprint,
1391 *transport2.description.identity_fingerprint);
1392 } else {
1393 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1394 transport2.description.identity_fingerprint.get());
1395 }
1396 EXPECT_EQ(transport1.description.transport_options,
1397 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 }
deadbeefc80741f2015-10-22 13:14:45 -07001399
1400 // global attributes
1401 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 }
1403
Yves Gerey665174f2018-06-19 15:03:05 +02001404 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1405 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1407 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1408 CompareSessionDescription(*desc1.description(), *desc2.description());
1409 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1410 return false;
1411 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1412 const IceCandidateCollection* cc1 = desc1.candidates(i);
1413 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001414 if (cc1->count() != cc2->count()) {
1415 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001417 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 for (size_t j = 0; j < cc1->count(); ++j) {
1419 const IceCandidateInterface* c1 = cc1->at(j);
1420 const IceCandidateInterface* c2 = cc2->at(j);
1421 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1422 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1423 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1424 }
1425 }
1426 return true;
1427 }
1428
1429 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1430 // them with invalid keywords so that the parser will just ignore them.
1431 bool RemoveCandidateUfragPwd(std::string* sdp) {
1432 const char ice_ufrag[] = "a=ice-ufrag";
1433 const char ice_ufragx[] = "a=xice-ufrag";
1434 const char ice_pwd[] = "a=ice-pwd";
1435 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001436 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1437 strlen(ice_ufragx), sdp);
1438 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1439 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 return true;
1441 }
1442
1443 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001444 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1445 int mline_index,
1446 const std::string& ufrag,
1447 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 std::string content_name;
1449 if (mline_index == 0) {
1450 content_name = kAudioContentName;
1451 } else if (mline_index == 1) {
1452 content_name = kVideoContentName;
1453 } else {
nissec80e7412017-01-11 05:56:46 -08001454 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 }
Yves Gerey665174f2018-06-19 15:03:05 +02001456 TransportInfo transport_info(content_name,
1457 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 SessionDescription* desc =
1459 const_cast<SessionDescription*>(jdesc->description());
1460 desc->RemoveTransportInfoByName(content_name);
1461 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1462 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1463 const IceCandidateCollection* cc = jdesc_.candidates(i);
1464 for (size_t j = 0; j < cc->count(); ++j) {
1465 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001466 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1467 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 }
1469 }
1470 }
1471 return true;
1472 }
1473
1474 void AddIceOptions(const std::string& content_name,
1475 const std::vector<std::string>& transport_options) {
1476 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1477 cricket::TransportInfo transport_info =
1478 *(desc_.GetTransportInfoByName(content_name));
1479 desc_.RemoveTransportInfoByName(content_name);
1480 transport_info.description.transport_options = transport_options;
1481 desc_.AddTransportInfo(transport_info);
1482 }
1483
deadbeef3f7219b2015-12-28 15:17:14 -08001484 void SetIceUfragPwd(const std::string& content_name,
1485 const std::string& ice_ufrag,
1486 const std::string& ice_pwd) {
1487 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1488 cricket::TransportInfo transport_info =
1489 *(desc_.GetTransportInfoByName(content_name));
1490 desc_.RemoveTransportInfoByName(content_name);
1491 transport_info.description.ice_ufrag = ice_ufrag;
1492 transport_info.description.ice_pwd = ice_pwd;
1493 desc_.AddTransportInfo(transport_info);
1494 }
1495
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 void AddFingerprint() {
1497 desc_.RemoveTransportInfoByName(kAudioContentName);
1498 desc_.RemoveTransportInfoByName(kVideoContentName);
Yves Gerey665174f2018-06-19 15:03:05 +02001499 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest,
1500 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 13:24:37 -08001501 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1502 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001503 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1504 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001505 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1506 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1507 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001508 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1509 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 13:24:37 -08001510 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 }
1512
jbauch5869f502017-06-29 12:31:36 -07001513 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001514 audio_desc_ = audio_desc_->Copy();
1515 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001516 audio_desc_->AddRtpHeaderExtension(
1517 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1518 video_desc_->AddRtpHeaderExtension(
1519 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 desc_.RemoveContentByName(kAudioContentName);
1521 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001522 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1523 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 }
1525
1526 void RemoveCryptos() {
1527 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1528 video_desc_->set_cryptos(std::vector<CryptoParams>());
1529 }
1530
Seth Hampson5897a6e2018-04-03 11:16:33 -07001531 // Removes everything in StreamParams from the session description that is
1532 // used for a=ssrc lines.
1533 void RemoveSsrcSignalingFromStreamParams() {
1534 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1535 // With Unified Plan there should be one StreamParams per m= section.
1536 StreamParams& stream =
1537 content_info.media_description()->mutable_streams()[0];
1538 stream.ssrcs.clear();
1539 stream.ssrc_groups.clear();
1540 stream.cname.clear();
1541 }
1542 }
1543
1544 // Removes all a=ssrc lines from the SDP string.
1545 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1546 const char kAttributeSsrc[] = "a=ssrc";
1547 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1548 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1549 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1550 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1551 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1552 }
1553 }
1554
Steve Anton4e70a722017-11-28 14:57:10 -08001555 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 audio_desc_->set_direction(direction);
1557 video_desc_->set_direction(direction);
1558 std::string new_sdp = kSdpFullString;
1559 ReplaceDirection(direction, &new_sdp);
1560
Yves Gerey665174f2018-06-19 15:03:05 +02001561 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 jdesc_.session_version())) {
1563 return false;
1564 }
Steve Antone831b8c2018-02-01 12:22:16 -08001565 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 EXPECT_EQ(new_sdp, message);
1567 return true;
1568 }
1569
1570 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001571 audio_desc_ = audio_desc_->Copy();
1572 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 desc_.RemoveContentByName(kAudioContentName);
1575 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001576 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001578 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001580 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1581 audio_rejected ? "" : kPwdVoice);
1582 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1583 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001584
1585 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1587
Steve Antona3a92c22017-12-07 10:27:41 -08001588 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001589 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001590 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 EXPECT_EQ(new_sdp, message);
1592 return true;
1593 }
1594
zstein4b2e0822017-02-17 19:48:38 -08001595 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001596 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001598 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001600 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001601 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001602 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1603 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001604 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1605 data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001606 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1607 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 }
1609
1610 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001611 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 data_desc_ = data.get();
1613
deadbeef67cf2c12016-04-13 10:07:16 -07001614 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 StreamParams data_stream;
1616 data_stream.id = kDataChannelMsid;
1617 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001618 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 data_stream.ssrcs.push_back(kDataChannelSsrc);
1620 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001621 data_desc_->AddCrypto(
1622 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1623 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001625 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
deadbeef9d3584c2016-02-16 17:54:10 -08001626 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1627 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 }
1629
Steve Anton4e70a722017-11-28 14:57:10 -08001630 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 std::string new_sdp = kSdpFullString;
1632 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001633 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
1635 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1636
1637 audio_desc_->set_direction(direction);
1638 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001639 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 jdesc_.session_version())) {
1641 return false;
1642 }
1643 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1644 return true;
1645 }
1646
1647 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001648 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001650 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001652
Steve Antonb1c1de12017-12-21 15:14:30 -08001653 audio_desc_ = audio_desc_->Copy();
1654 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 desc_.RemoveContentByName(kAudioContentName);
1656 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001657 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001659 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001661 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1662 audio_rejected ? "" : kPwdVoice);
1663 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1664 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001665 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001666 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1667 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 return false;
1669 }
deadbeef3f7219b2015-12-28 15:17:14 -08001670 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 return true;
1672 }
1673
Yves Gerey665174f2018-06-19 15:03:05 +02001674 void TestDeserializeExtmap(bool session_level,
1675 bool media_level,
1676 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001677 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001678 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001679 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001681 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 std::string sdp_with_extmap = kSdpString;
1683 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001684 InjectAfter(kSessionTime,
1685 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1686 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 &sdp_with_extmap);
1688 }
1689 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001690 InjectAfter(kAttributeIcePwdVoice,
1691 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1692 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001694 InjectAfter(kAttributeIcePwdVideo,
1695 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1696 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 &sdp_with_extmap);
1698 }
1699 // The extmap can't be present at the same time in both session level and
1700 // media level.
1701 if (session_level && media_level) {
1702 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001703 EXPECT_FALSE(
1704 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1706 } else {
1707 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1708 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1709 }
1710 }
1711
1712 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001713 const std::string& name,
1714 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 cricket::CodecParameterMap::const_iterator found = params.find(name);
1716 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001717 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 }
1719
1720 void TestDeserializeCodecParams(const CodecParams& params,
1721 JsepSessionDescription* jdesc_output) {
1722 std::string sdp =
1723 "v=0\r\n"
1724 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1725 "s=-\r\n"
1726 "t=0 0\r\n"
1727 // Include semantics for WebRTC Media Streams since it is supported by
1728 // this parser, and will be added to the SDP when serializing a session
1729 // description.
1730 "a=msid-semantic: WMS\r\n"
1731 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001732 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 // Pltype 111 listed before 103 and 104 in the map.
1734 "a=rtpmap:111 opus/48000/2\r\n"
1735 // Pltype 103 listed before 104.
1736 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001737 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001738 "a=fmtp:111 0-15,66,70\r\n"
1739 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001741 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001742 << "; sprop-stereo=" << params.sprop_stereo
1743 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001744 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 << "a=ptime:" << params.ptime << "\r\n"
1746 << "a=maxptime:" << params.max_ptime << "\r\n";
1747 sdp += os.str();
1748
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001749 os.clear();
1750 os.str("");
1751 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001752 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001753 << "a=rtpmap:99 VP8/90000\r\n"
1754 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001755 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001756 sdp += os.str();
1757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 // Deserialize
1759 SdpParseError error;
1760 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1761
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001763 GetFirstAudioContentDescription(jdesc_output->description());
1764 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 ASSERT_FALSE(acd->codecs().empty());
1766 cricket::AudioCodec opus = acd->codecs()[0];
1767 EXPECT_EQ("opus", opus.name);
1768 EXPECT_EQ(111, opus.id);
1769 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1770 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1771 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1772 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001773 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1774 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1776 cricket::AudioCodec codec = acd->codecs()[i];
1777 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1778 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001780
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001781 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001782 GetFirstVideoContentDescription(jdesc_output->description());
1783 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001784 ASSERT_FALSE(vcd->codecs().empty());
1785 cricket::VideoCodec vp8 = vcd->codecs()[0];
1786 EXPECT_EQ("VP8", vp8.name);
1787 EXPECT_EQ(99, vp8.id);
1788 cricket::VideoCodec rtx = vcd->codecs()[1];
1789 EXPECT_EQ("RTX", rtx.name);
1790 EXPECT_EQ(95, rtx.id);
1791 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 }
1793
1794 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1795 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001796 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 "v=0\r\n"
1798 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1799 "s=-\r\n"
1800 "t=0 0\r\n"
1801 // Include semantics for WebRTC Media Streams since it is supported by
1802 // this parser, and will be added to the SDP when serializing a session
1803 // description.
1804 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001805 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001806 "a=rtpmap:111 opus/48000/2\r\n";
1807 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 "m=video 3457 RTP/SAVPF 101\r\n"
1809 "a=rtpmap:101 VP8/90000\r\n"
1810 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001811 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001812 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001814 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001815 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001816 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001817 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001818 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 // Deserialize
1820 SdpParseError error;
1821 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001823 GetFirstAudioContentDescription(jdesc_output->description());
1824 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 ASSERT_FALSE(acd->codecs().empty());
1826 cricket::AudioCodec opus = acd->codecs()[0];
1827 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001828 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
1829 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001832 GetFirstVideoContentDescription(jdesc_output->description());
1833 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 ASSERT_FALSE(vcd->codecs().empty());
1835 cricket::VideoCodec vp8 = vcd->codecs()[0];
1836 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1837 vp8.name.c_str());
1838 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02001839 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1840 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
1841 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1842 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
1843 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1844 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
1845 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
1846 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 }
1848
1849 // Two SDP messages can mean the same thing but be different strings, e.g.
1850 // some of the lines can be serialized in different order.
1851 // However, a deserialized description can be compared field by field and has
1852 // no order. If deserializer has already been tested, serializing then
1853 // deserializing and comparing JsepSessionDescription will test
1854 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08001855 void TestSerialize(const JsepSessionDescription& jdesc) {
1856 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08001857 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 SdpParseError error;
1859 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1860 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1861 }
1862
zhihuang38989e52017-03-21 11:04:53 -07001863 // Calling 'Initialize' with a copy of the inner SessionDescription will
1864 // create a copy of the JsepSessionDescription without candidates. The
1865 // 'connection address' field, previously set from the candidates, must also
1866 // be reset.
1867 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1868 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1869 rtc::SocketAddress video_addr("0.0.0.0", 9);
1870 audio_desc_->set_connection_address(audio_addr);
1871 video_desc_->set_connection_address(video_addr);
1872 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1873 }
1874
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 protected:
1876 SessionDescription desc_;
1877 AudioContentDescription* audio_desc_;
1878 VideoContentDescription* video_desc_;
1879 DataContentDescription* data_desc_;
1880 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07001881 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 JsepSessionDescription jdesc_;
1883};
1884
1885void TestMismatch(const std::string& string1, const std::string& string2) {
1886 int position = 0;
1887 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1888 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001889 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 break;
1891 }
1892 }
1893 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1894 << " character\n"
1895 << " 1: " << string1.substr(position, 20) << "\n"
1896 << " 2: " << string2.substr(position, 20) << "\n";
1897}
1898
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1900 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08001901 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 TestMismatch(std::string(kSdpFullString), message);
1903}
1904
1905TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08001906 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08001907 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908}
1909
1910// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1911// the case in a DTLS offer.
1912TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1913 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08001914 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001915 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001916 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917
1918 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02001919 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1920 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921
1922 EXPECT_EQ(sdp_with_fingerprint, message);
1923}
1924
1925// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1926// be the case in a DTLS answer.
1927TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1928 AddFingerprint();
1929 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08001930 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001931 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08001932 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933
1934 std::string sdp_with_fingerprint = kSdpString;
1935 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1936 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02001937 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
1938 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939
1940 EXPECT_EQ(sdp_with_fingerprint, message);
1941}
1942
1943TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1944 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08001945 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001946 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001947 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 EXPECT_EQ(std::string(kSdpString), message);
1949}
1950
1951TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1952 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1953 group.AddContentName(kAudioContentName);
1954 group.AddContentName(kVideoContentName);
1955 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02001956 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001958 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 std::string sdp_with_bundle = kSdpFullString;
1960 InjectAfter(kSessionTime,
1961 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1962 &sdp_with_bundle);
1963 EXPECT_EQ(sdp_with_bundle, message);
1964}
1965
1966TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001967 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08001969 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02001971 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001973 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001975 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02001977 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 &sdp_with_bandwidth);
1979 EXPECT_EQ(sdp_with_bandwidth, message);
1980}
1981
1982TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1983 std::vector<std::string> transport_options;
1984 transport_options.push_back(kIceOption1);
1985 transport_options.push_back(kIceOption3);
1986 AddIceOptions(kAudioContentName, transport_options);
1987 transport_options.clear();
1988 transport_options.push_back(kIceOption2);
1989 transport_options.push_back(kIceOption3);
1990 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001991 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08001993 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02001995 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02001997 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 &sdp_with_ice_options);
1999 EXPECT_EQ(sdp_with_ice_options, message);
2000}
2001
2002TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002003 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004}
2005
2006TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002007 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008}
2009
2010TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002011 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012}
2013
2014TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2015 EXPECT_TRUE(TestSerializeRejected(true, false));
2016}
2017
2018TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2019 EXPECT_TRUE(TestSerializeRejected(false, true));
2020}
2021
2022TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2023 EXPECT_TRUE(TestSerializeRejected(true, true));
2024}
2025
2026TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2027 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002028 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029
zhihuang38989e52017-03-21 11:04:53 -07002030 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002031 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032
2033 std::string expected_sdp = kSdpString;
2034 expected_sdp.append(kSdpRtpDataChannelString);
2035 EXPECT_EQ(expected_sdp, message);
2036}
2037
2038TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002039 bool use_sctpmap = true;
2040 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002041 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
zhihuang38989e52017-03-21 11:04:53 -07002043 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002044 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045
2046 std::string expected_sdp = kSdpString;
2047 expected_sdp.append(kSdpSctpDataChannelString);
2048 EXPECT_EQ(message, expected_sdp);
2049}
2050
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002051TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002052 bool use_sctpmap = true;
2053 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002054 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002055 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002056 DataContentDescription* dcdesc =
2057 jsep_desc.description()
2058 ->GetContentDescriptionByName(kDataContentName)
2059 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002060
2061 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002062 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002063 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002064 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2065 dcdesc->AddOrReplaceCodec(codec);
2066
Steve Antone831b8c2018-02-01 12:22:16 -08002067 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002068
2069 std::string expected_sdp = kSdpString;
2070 expected_sdp.append(kSdpSctpDataChannelString);
2071
2072 char default_portstr[16];
2073 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002074 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
Yves Gerey665174f2018-06-19 15:03:05 +02002075 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002076 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002077 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2078 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002079
2080 EXPECT_EQ(expected_sdp, message);
2081}
2082
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002083TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002084 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002085 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002086 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002087 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002088 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002089
2090 std::string expected_sdp = kSdpString;
2091 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002092 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002093 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002094 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002095 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002096}
2097
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002099 bool encrypted = false;
2100 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002101 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002102 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002103 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
2105 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002106 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2107 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 EXPECT_EQ(sdp_with_extmap, message);
2110}
2111
jbauch5869f502017-06-29 12:31:36 -07002112TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2113 bool encrypted = true;
2114 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002115 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002116 ASSERT_TRUE(
2117 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002118 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002119}
2120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121TEST_F(WebRtcSdpTest, SerializeCandidates) {
2122 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002123 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002124
2125 Candidate candidate_with_ufrag(candidates_.front());
2126 candidate_with_ufrag.set_username("ABC");
2127 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2128 candidate_with_ufrag));
2129 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2130 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002131
2132 Candidate candidate_with_network_info(candidates_.front());
2133 candidate_with_network_info.set_network_id(1);
2134 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2135 candidate_with_network_info));
2136 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2137 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2138 candidate_with_network_info.set_network_cost(999);
2139 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2140 candidate_with_network_info));
2141 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2142 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2143 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144}
2145
Zach Steinb336c272018-08-09 01:16:13 -07002146TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2147 rtc::SocketAddress address("a.test", 1234);
2148 cricket::Candidate candidate(
2149 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2150 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2151 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2152 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2153 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2154}
2155
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002156// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2157// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002158TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002159 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002160 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2161 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2162 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002163 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002164 std::unique_ptr<IceCandidateInterface> jcandidate(
2165 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002166
2167 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2168 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2169}
2170
htaa6b99442016-04-12 10:29:17 -07002171TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002172 cricket::VideoCodec h264_codec("H264");
2173 h264_codec.SetParam("profile-level-id", "42e01f");
2174 h264_codec.SetParam("level-asymmetry-allowed", "1");
2175 h264_codec.SetParam("packetization-mode", "1");
2176 video_desc_->AddCodec(h264_codec);
2177
htaa6b99442016-04-12 10:29:17 -07002178 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2179
Steve Antone831b8c2018-02-01 12:22:16 -08002180 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002181 size_t after_pt = message.find(" H264/90000");
2182 ASSERT_NE(after_pt, std::string::npos);
2183 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2184 ASSERT_NE(before_pt, std::string::npos);
2185 before_pt += strlen("a=rtpmap:");
2186 std::string pt = message.substr(before_pt, after_pt - before_pt);
2187 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2188 std::string to_find = "a=fmtp:" + pt + " ";
2189 size_t fmtp_pos = message.find(to_find);
2190 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2191 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2192 ASSERT_NE(std::string::npos, fmtp_endpos);
2193 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2194 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2195 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2196 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002197 // Check that there are no spaces after semicolons.
2198 // https://bugs.webrtc.org/5793
2199 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002200}
2201
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002203 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 // Deserialize
2205 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2206 // Verify
2207 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2208}
2209
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002210TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002211 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002212 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002213 "v=0\r\n"
2214 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2215 "s=-\r\n"
2216 "t=0 0\r\n"
2217 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002218 // Deserialize
2219 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2220 EXPECT_EQ(0u, jdesc.description()->contents().size());
2221}
2222
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002224 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 std::string sdp_without_carriage_return = kSdpFullString;
2226 Replace("\r\n", "\n", &sdp_without_carriage_return);
2227 // Deserialize
2228 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2229 // Verify
2230 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2231}
2232
2233TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2234 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002235 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002236 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2237 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002238 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2240 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2241}
2242
2243TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2244 static const char kSdpNoRtpmapString[] =
2245 "v=0\r\n"
2246 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2247 "s=-\r\n"
2248 "t=0 0\r\n"
2249 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2250 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002251 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 // The rtpmap line for static payload codec is optional.
2253 "a=rtpmap:18 G729/16000\r\n"
2254 "a=rtpmap:103 ISAC/16000\r\n";
2255
Steve Antona3a92c22017-12-07 10:27:41 -08002256 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2258 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002259 jdesc.description()
2260 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2261 ->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002263 // The codecs in the AudioContentDescription should be in the same order as
2264 // the payload types (<fmt>s) on the m= line.
2265 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2266 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002267 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 EXPECT_EQ(ref_codecs, audio->codecs());
2269}
2270
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002271TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2272 static const char kSdpNoRtpmapString[] =
2273 "v=0\r\n"
2274 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2275 "s=-\r\n"
2276 "t=0 0\r\n"
2277 "m=audio 49232 RTP/AVP 18 103\r\n"
2278 "a=fmtp:18 annexb=yes\r\n"
2279 "a=rtpmap:103 ISAC/16000\r\n";
2280
Steve Antona3a92c22017-12-07 10:27:41 -08002281 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002282 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2283 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002284 jdesc.description()
2285 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2286 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002287
2288 cricket::AudioCodec g729 = audio->codecs()[0];
2289 EXPECT_EQ("G729", g729.name);
2290 EXPECT_EQ(8000, g729.clockrate);
2291 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002292 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002293 ASSERT_TRUE(found != g729.params.end());
2294 EXPECT_EQ(found->second, "yes");
2295
2296 cricket::AudioCodec isac = audio->codecs()[1];
2297 EXPECT_EQ("ISAC", isac.name);
2298 EXPECT_EQ(103, isac.id);
2299 EXPECT_EQ(16000, isac.clockrate);
2300}
2301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302// Ensure that we can deserialize SDP with a=fingerprint properly.
2303TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2304 // Add a DTLS a=fingerprint attribute to our session description.
2305 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002306 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002307 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 jdesc_.session_version()));
2309
Steve Antona3a92c22017-12-07 10:27:41 -08002310 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 std::string sdp_with_fingerprint = kSdpString;
2312 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2313 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2314 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2315 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2316}
2317
2318TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002319 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 std::string sdp_with_bundle = kSdpFullString;
2321 InjectAfter(kSessionTime,
2322 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2323 &sdp_with_bundle);
2324 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2325 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2326 group.AddContentName(kAudioContentName);
2327 group.AddContentName(kVideoContentName);
2328 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002329 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 jdesc_.session_version()));
2331 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2332}
2333
2334TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002335 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002337 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002339 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002341 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002342 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002344 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002346 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 jdesc_.session_version()));
2348 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2349}
2350
2351TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002352 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002354 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002356 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002358 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 &sdp_with_ice_options);
2360 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2361 std::vector<std::string> transport_options;
2362 transport_options.push_back(kIceOption3);
2363 transport_options.push_back(kIceOption1);
2364 AddIceOptions(kAudioContentName, transport_options);
2365 transport_options.clear();
2366 transport_options.push_back(kIceOption3);
2367 transport_options.push_back(kIceOption2);
2368 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002369 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 jdesc_.session_version()));
2371 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2372}
2373
2374TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2375 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002376 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 std::string sdp_with_ufrag_pwd = kSdpFullString;
2378 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2379 // Add session level ufrag and pwd
2380 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002381 "a=ice-pwd:session+level+icepwd\r\n"
2382 "a=ice-ufrag:session+level+iceufrag\r\n",
2383 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002385 InjectAfter(
2386 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2388 &sdp_with_ufrag_pwd);
2389 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002390 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2391 "media+level+icepwd"));
2392 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2393 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2395 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2396}
2397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002399 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400}
2401
2402TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002403 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404}
2405
2406TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002407 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408}
2409
2410TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2411 EXPECT_TRUE(TestDeserializeRejected(true, false));
2412}
2413
2414TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2415 EXPECT_TRUE(TestDeserializeRejected(false, true));
2416}
2417
2418TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2419 EXPECT_TRUE(TestDeserializeRejected(true, true));
2420}
2421
2422// Tests that we can still handle the sdp uses mslabel and label instead of
2423// msid for backward compatibility.
2424TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002425 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002426 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 std::string sdp_without_msid = kSdpFullString;
2428 Replace("msid", "xmsid", &sdp_without_msid);
2429 // Deserialize
2430 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2431 // Verify
2432 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2433}
2434
2435TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2436 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2437
2438 std::string sdp = kSdpOneCandidate;
2439 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2440 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2441 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2442 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002443 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444
2445 // Candidate line without generation extension.
2446 sdp = kSdpOneCandidate;
2447 Replace(" generation 2", "", &sdp);
2448 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2449 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2450 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2451 Candidate expected = jcandidate_->candidate();
2452 expected.set_generation(0);
2453 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2454
honghaiza0c44ea2016-03-23 16:07:48 -07002455 // Candidate with network id and/or cost.
2456 sdp = kSdpOneCandidate;
2457 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2458 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2459 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2460 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2461 expected = jcandidate_->candidate();
2462 expected.set_network_id(2);
2463 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2464 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2465 // Add network cost
2466 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2467 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2468 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2469 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2470
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002471 sdp = kSdpTcpActiveCandidate;
2472 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2473 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002474 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002475 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2476 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2477 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002478 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2479 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002480 EXPECT_TRUE(
2481 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002482 sdp = kSdpTcpPassiveCandidate;
2483 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2484 sdp = kSdpTcpSOCandidate;
2485 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486}
2487
2488// This test verifies the deserialization of candidate-attribute
2489// as per RFC 5245. Candiate-attribute will be of the format
2490// candidate:<blah>. This format will be used when candidates
2491// are trickled.
2492TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2493 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2494
2495 std::string candidate_attribute = kRawCandidate;
2496 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2497 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2498 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2499 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2500 EXPECT_EQ(2u, jcandidate.candidate().generation());
2501
2502 // Candidate line without generation extension.
2503 candidate_attribute = kRawCandidate;
2504 Replace(" generation 2", "", &candidate_attribute);
2505 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2506 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2507 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2508 Candidate expected = jcandidate_->candidate();
2509 expected.set_generation(0);
2510 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2511
2512 // Candidate line without candidate:
2513 candidate_attribute = kRawCandidate;
2514 Replace("candidate:", "", &candidate_attribute);
2515 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2516
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002517 // Candidate line with IPV6 address.
2518 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002519
2520 // Candidate line with hostname address.
2521 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002522}
2523
2524// This test verifies that the deserialization of an invalid candidate string
2525// fails.
2526TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002527 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002528
2529 std::string candidate_attribute = kRawCandidate;
2530 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002532
2533 candidate_attribute = kSdpOneCandidate;
2534 candidate_attribute.replace(0, 1, "x");
2535 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2536
2537 candidate_attribute = kRawCandidate;
2538 candidate_attribute.append("\r\n");
2539 candidate_attribute.append(kRawCandidate);
2540 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2541
2542 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543}
2544
2545TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2546 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002547 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2549
2550 std::string sdp_with_data = kSdpString;
2551 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002552 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553
2554 // Deserialize
2555 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2556 // Verify
2557 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2558}
2559
2560TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002561 bool use_sctpmap = true;
2562 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002563 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2565
2566 std::string sdp_with_data = kSdpString;
2567 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002568 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569
lally@webrtc.org36300852015-02-24 20:19:35 +00002570 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2571 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2572 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2573
2574 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002575 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2576 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002577 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2578 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2579
2580 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002581 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2582 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2584 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2585}
2586
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002587TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002588 bool use_sctpmap = false;
2589 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002590 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002591 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2592
2593 std::string sdp_with_data = kSdpString;
2594 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002595 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002596
lally@webrtc.org36300852015-02-24 20:19:35 +00002597 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002598 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2599 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002600
lally@webrtc.org36300852015-02-24 20:19:35 +00002601 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002602 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2603 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002604 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2605 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002606
lally@webrtc.org36300852015-02-24 20:19:35 +00002607 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002608 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2609 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002610 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2611 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2612}
2613
lally69f57602015-10-08 10:15:04 -07002614TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002615 bool use_sctpmap = false;
2616 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002617 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002618 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2619
2620 std::string sdp_with_data = kSdpString;
2621 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002622 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002623
2624 // Verify with DTLS/SCTP.
2625 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2626 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2627
2628 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002629 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2630 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002631 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2632 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2633
2634 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002635 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2636 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002637 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2638 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2639}
2640
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002641// Test to check the behaviour if sctp-port is specified
2642// on the m= line and in a=sctp-port.
2643TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002644 bool use_sctpmap = true;
2645 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002646 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002647 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2648
2649 std::string sdp_with_data = kSdpString;
2650 // Append m= attributes
2651 sdp_with_data.append(kSdpSctpDataChannelString);
2652 // Append a=sctp-port attribute
2653 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002654 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002655
2656 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2657}
2658
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002659// For crbug/344475.
2660TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2661 std::string sdp_with_data = kSdpString;
2662 sdp_with_data.append(kSdpSctpDataChannelString);
2663 // Remove the "\n" at the end.
2664 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002665 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002666
2667 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2668 // No crash is a pass.
2669}
2670
Steve Anton36b29d12017-10-30 09:57:42 -07002671void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002672 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002673 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002674 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002675 DataContentDescription* dcdesc =
2676 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002677 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002678 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002679 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002680 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002681 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002682
2683 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002684 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002685 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002686}
2687
2688TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2689 bool use_sctpmap = true;
2690 AddSctpDataChannel(use_sctpmap);
2691
2692 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002693 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002694 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002695
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002696 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002697 std::string sdp_with_data = kSdpString;
2698 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002699 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2700 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2701 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002702 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002703
2704 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2705 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002706}
2707
2708TEST_F(WebRtcSdpTest,
2709 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2710 bool use_sctpmap = false;
2711 AddSctpDataChannel(use_sctpmap);
2712
Steve Antona3a92c22017-12-07 10:27:41 -08002713 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002714 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002715
2716 // We need to test the deserialized JsepSessionDescription from
2717 // kSdpSctpDataChannelStringWithSctpPort for
2718 // draft-ietf-mmusic-sctp-sdp-07
2719 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002720 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002721 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002722 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2723 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2724 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002725 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002726
2727 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2728 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002729}
2730
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002731TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002732 // We want to test that deserializing data content limits bandwidth
2733 // settings (it should never be greater than the default).
2734 // This should prevent someone from using unlimited data bandwidth through
2735 // JS and "breaking the Internet".
2736 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002737 std::string sdp_with_bandwidth = kSdpString;
2738 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002739 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002740 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002741 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002742
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002743 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2744}
2745
2746TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002747 bool use_sctpmap = true;
2748 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002749 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002750 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002751 dcd->set_bandwidth(100 * 1000);
2752 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2753
2754 std::string sdp_with_bandwidth = kSdpString;
2755 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002756 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002757 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002758 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002759
2760 // SCTP has congestion control, so we shouldn't limit the bandwidth
2761 // as we do for RTP.
2762 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002763 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2764}
2765
Yves Gerey665174f2018-06-19 15:03:05 +02002766class WebRtcSdpExtmapTest : public WebRtcSdpTest,
2767 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07002768
2769TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02002770 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002771 bool encrypted = GetParam();
2772 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773}
2774
Yves Gerey665174f2018-06-19 15:03:05 +02002775TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002776 bool encrypted = GetParam();
2777 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778}
2779
Yves Gerey665174f2018-06-19 15:03:05 +02002780TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002781 bool encrypted = GetParam();
2782 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783}
2784
jbauch5869f502017-06-29 12:31:36 -07002785INSTANTIATE_TEST_CASE_P(Encrypted,
2786 WebRtcSdpExtmapTest,
2787 ::testing::Values(false, true));
2788
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002789TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08002790 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002791 std::string sdp = kSdpFullString;
2792 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2793 // Deserialize
2794 SdpParseError error;
2795 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08002796 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002797 EXPECT_EQ(lastline, error.line);
2798 EXPECT_EQ("Invalid SDP line.", error.description);
2799}
2800
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002801TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2802 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2803 std::string new_sdp = kSdpOneCandidate;
2804 Replace("udp", "unsupported_transport", &new_sdp);
2805 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2806 new_sdp = kSdpOneCandidate;
2807 Replace("udp", "uDP", &new_sdp);
2808 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2809 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2810 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2811 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2812}
2813
honghaiza54a0802015-12-16 18:37:23 -08002814TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08002816 EXPECT_TRUE(
2817 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2819 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2820 Candidate ref_candidate = jcandidate_->candidate();
2821 ref_candidate.set_username("user_rtp");
2822 ref_candidate.set_password("password_rtp");
2823 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2824}
2825
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002826TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002827 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002828
2829 // Deserialize
2830 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2831
2832 // Verify
2833 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002834 jdesc.description()
2835 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2836 ->as_audio();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002837 EXPECT_TRUE(audio->conference_mode());
2838
2839 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002840 jdesc.description()
2841 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2842 ->as_video();
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002843 EXPECT_TRUE(video->conference_mode());
2844}
2845
deadbeefd45aea82017-09-16 01:24:29 -07002846TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08002847 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07002848
2849 // We tested deserialization already above, so just test that if we serialize
2850 // and deserialize the flag doesn't disappear.
2851 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08002852 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07002853 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2854
2855 // Verify.
2856 cricket::AudioContentDescription* audio =
Steve Antonb1c1de12017-12-21 15:14:30 -08002857 jdesc.description()
2858 ->GetContentDescriptionByName(cricket::CN_AUDIO)
2859 ->as_audio();
deadbeefd45aea82017-09-16 01:24:29 -07002860 EXPECT_TRUE(audio->conference_mode());
2861
2862 cricket::VideoContentDescription* video =
Steve Antonb1c1de12017-12-21 15:14:30 -08002863 jdesc.description()
2864 ->GetContentDescriptionByName(cricket::CN_VIDEO)
2865 ->as_video();
deadbeefd45aea82017-09-16 01:24:29 -07002866 EXPECT_TRUE(video->conference_mode());
2867}
2868
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2870 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002871 const char kSdpEmptyType[] = " =candidate";
2872 const char kSdpEqualAsPlus[] = "a+candidate";
2873 const char kSdpSpaceAfterEqual[] = "a= candidate";
2874 const char kSdpUpperType[] = "A=candidate";
2875 const char kSdpEmptyLine[] = "";
2876 const char kSdpMissingValue[] = "a=";
2877
Yves Gerey665174f2018-06-19 15:03:05 +02002878 const char kSdpBrokenFingerprint[] =
2879 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 15:03:05 +02002881 const char kSdpExtraField[] =
2882 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
Yves Gerey665174f2018-06-19 15:03:05 +02002884 const char kSdpMissingSpace[] =
2885 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002887 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02002888 const char kSdpMd5[] =
2889 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002890 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891
2892 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002893 ExpectParseFailure("v=", kSdpDestroyer);
2894 ExpectParseFailure("o=", kSdpDestroyer);
2895 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002897 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898
2899 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002900 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2901 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902
2903 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002904 ExpectParseFailure("a=candidate", kSdpEmptyType);
2905 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2906 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2907 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908
2909 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2910 // because it's orthogonal to what we are replacing and hence
2911 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00002912 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2913 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2914 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2915 ExpectParseFailure("a=sendrecv", kSdpMd5);
2916
2917 // Empty Line
2918 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2919 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002920}
2921
2922TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2923 // ssrc
2924 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08002925 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002926 // crypto
2927 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2928 // rtpmap
2929 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2930 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2931 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2932 // candidate
2933 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2934 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2935 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2936 ExpectParseFailure("rport 2346", "rport badvalue");
2937 ExpectParseFailure("rport 2346 generation 2",
2938 "rport 2346 generation badvalue");
2939 // m line
2940 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2941 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2942
2943 // bandwidth
2944 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002945 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00002946 // rtcp-fb
2947 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2948 "a=rtcp-fb:badvalue nack\r\n",
2949 "a=rtcp-fb:badvalue nack");
2950 // extmap
2951 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2952 "a=extmap:badvalue http://example.com\r\n",
2953 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954}
2955
2956TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08002957 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958
2959 const char kSdpWithReorderedPlTypesString[] =
2960 "v=0\r\n"
2961 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2962 "s=-\r\n"
2963 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00002964 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02002965 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2966 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002968 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002969
2970 // Deserialize
2971 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2972
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002974 GetFirstAudioContentDescription(jdesc_output.description());
2975 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002977 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2978 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 EXPECT_EQ(104, acd->codecs()[0].id);
2980}
2981
2982TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08002983 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 CodecParams params;
2985 params.max_ptime = 40;
2986 params.ptime = 30;
2987 params.min_ptime = 10;
2988 params.sprop_stereo = 1;
2989 params.stereo = 1;
2990 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002991 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08002993 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994}
2995
2996TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2997 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08002998 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003000 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001}
3002
3003TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3004 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003005 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003007 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008}
3009
3010TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003011 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012
3013 const char kSdpWithFmtpString[] =
3014 "v=0\r\n"
3015 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3016 "s=-\r\n"
3017 "t=0 0\r\n"
3018 "m=video 3457 RTP/SAVPF 120\r\n"
3019 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003020 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3021
3022 // Deserialize
3023 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003024 EXPECT_TRUE(
3025 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003026
Donald Curtis0e07f922015-05-15 09:21:23 -07003027 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003028 GetFirstVideoContentDescription(jdesc_output.description());
3029 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003030 ASSERT_FALSE(vcd->codecs().empty());
3031 cricket::VideoCodec vp8 = vcd->codecs()[0];
3032 EXPECT_EQ("VP8", vp8.name);
3033 EXPECT_EQ(120, vp8.id);
3034 cricket::CodecParameterMap::iterator found =
3035 vp8.params.find("x-google-min-bitrate");
3036 ASSERT_TRUE(found != vp8.params.end());
3037 EXPECT_EQ(found->second, "10");
3038 found = vp8.params.find("x-google-max-quantization");
3039 ASSERT_TRUE(found != vp8.params.end());
3040 EXPECT_EQ(found->second, "40");
3041}
3042
johan2d8d23e2016-06-03 01:22:42 -07003043TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003044 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003045
3046 const char kSdpWithFmtpString[] =
3047 "v=0\r\n"
3048 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3049 "s=-\r\n"
3050 "t=0 0\r\n"
3051 "m=video 49170 RTP/AVP 98\r\n"
3052 "a=rtpmap:98 H264/90000\r\n"
3053 "a=fmtp:98 profile-level-id=42A01E; "
3054 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3055
3056 // Deserialize.
3057 SdpParseError error;
3058 EXPECT_TRUE(
3059 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3060
johan2d8d23e2016-06-03 01:22:42 -07003061 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003062 GetFirstVideoContentDescription(jdesc_output.description());
3063 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003064 ASSERT_FALSE(vcd->codecs().empty());
3065 cricket::VideoCodec h264 = vcd->codecs()[0];
3066 EXPECT_EQ("H264", h264.name);
3067 EXPECT_EQ(98, h264.id);
3068 cricket::CodecParameterMap::const_iterator found =
3069 h264.params.find("profile-level-id");
3070 ASSERT_TRUE(found != h264.params.end());
3071 EXPECT_EQ(found->second, "42A01E");
3072 found = h264.params.find("sprop-parameter-sets");
3073 ASSERT_TRUE(found != h264.params.end());
3074 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3075}
3076
Donald Curtis0e07f922015-05-15 09:21:23 -07003077TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003078 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003079
3080 const char kSdpWithFmtpString[] =
3081 "v=0\r\n"
3082 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3083 "s=-\r\n"
3084 "t=0 0\r\n"
3085 "m=video 3457 RTP/SAVPF 120\r\n"
3086 "a=rtpmap:120 VP8/90000\r\n"
3087 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088
3089 // Deserialize
3090 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003091 EXPECT_TRUE(
3092 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003095 GetFirstVideoContentDescription(jdesc_output.description());
3096 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097 ASSERT_FALSE(vcd->codecs().empty());
3098 cricket::VideoCodec vp8 = vcd->codecs()[0];
3099 EXPECT_EQ("VP8", vp8.name);
3100 EXPECT_EQ(120, vp8.id);
3101 cricket::CodecParameterMap::iterator found =
3102 vp8.params.find("x-google-min-bitrate");
3103 ASSERT_TRUE(found != vp8.params.end());
3104 EXPECT_EQ(found->second, "10");
3105 found = vp8.params.find("x-google-max-quantization");
3106 ASSERT_TRUE(found != vp8.params.end());
3107 EXPECT_EQ(found->second, "40");
3108}
3109
ossuaa4b0772017-01-30 07:41:18 -08003110TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003111 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003112
3113 cricket::AudioCodecs codecs = acd->codecs();
3114 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3115 acd->set_codecs(codecs);
3116
Yves Gerey665174f2018-06-19 15:03:05 +02003117 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003118 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003119 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003120 std::string sdp_with_fmtp = kSdpFullString;
3121 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3122 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3123 &sdp_with_fmtp);
3124 EXPECT_EQ(sdp_with_fmtp, message);
3125}
3126
3127TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003128 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003129
3130 cricket::AudioCodecs codecs = acd->codecs();
3131 codecs[0].params["stereo"] = "1";
3132 acd->set_codecs(codecs);
3133
Yves Gerey665174f2018-06-19 15:03:05 +02003134 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003135 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003136 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003137 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003138 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003139 &sdp_with_fmtp);
3140 EXPECT_EQ(sdp_with_fmtp, message);
3141}
3142
3143TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003144 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003145
3146 cricket::AudioCodecs codecs = acd->codecs();
3147 codecs[0].params["ptime"] = "20";
3148 codecs[0].params["maxptime"] = "120";
3149 acd->set_codecs(codecs);
3150
Yves Gerey665174f2018-06-19 15:03:05 +02003151 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003152 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003153 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003154 std::string sdp_with_fmtp = kSdpFullString;
3155 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3156 "a=maxptime:120\r\n" // No comma here. String merging!
3157 "a=ptime:20\r\n",
3158 &sdp_with_fmtp);
3159 EXPECT_EQ(sdp_with_fmtp, message);
3160}
3161
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003163 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164
3165 cricket::VideoCodecs codecs = vcd->codecs();
3166 codecs[0].params["x-google-min-bitrate"] = "10";
3167 vcd->set_codecs(codecs);
3168
Yves Gerey665174f2018-06-19 15:03:05 +02003169 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003170 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003171 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003172 std::string sdp_with_fmtp = kSdpFullString;
3173 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003174 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003175 EXPECT_EQ(sdp_with_fmtp, message);
3176}
3177
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003178TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3179 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003180 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181 std::string sdp_with_icelite = kSdpFullString;
3182 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3183 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3184 const cricket::TransportInfo* tinfo1 =
3185 desc->GetTransportInfoByName("audio_content_name");
3186 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3187 const cricket::TransportInfo* tinfo2 =
3188 desc->GetTransportInfoByName("video_content_name");
3189 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003190
3191 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003192 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3194 desc = jdesc_with_icelite.description();
3195 const cricket::TransportInfo* atinfo =
3196 desc->GetTransportInfoByName("audio_content_name");
3197 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3198 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003199 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003201
3202 // Now that we know deserialization works, we can use TestSerialize to test
3203 // serialization.
3204 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205}
3206
3207// Verifies that the candidates in the input SDP are parsed and serialized
3208// correctly in the output SDP.
3209TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3210 std::string sdp_with_data = kSdpString;
3211 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003212 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213
3214 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003215 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003217
3218TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3219 AddFingerprint();
3220 TransportInfo audio_transport_info =
3221 *(desc_.GetTransportInfoByName(kAudioContentName));
3222 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3223 audio_transport_info.description.connection_role);
3224 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003225 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003226
3227 TransportInfo video_transport_info =
3228 *(desc_.GetTransportInfoByName(kVideoContentName));
3229 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3230 video_transport_info.description.connection_role);
3231 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003232 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003233
3234 desc_.RemoveTransportInfoByName(kAudioContentName);
3235 desc_.RemoveTransportInfoByName(kVideoContentName);
3236
3237 desc_.AddTransportInfo(audio_transport_info);
3238 desc_.AddTransportInfo(video_transport_info);
3239
Yves Gerey665174f2018-06-19 15:03:05 +02003240 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003241 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003242 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003243 std::string sdp_with_dtlssetup = kSdpFullString;
3244
3245 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003246 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3247 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003248 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003249 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003250 EXPECT_EQ(sdp_with_dtlssetup, message);
3251}
3252
3253TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003254 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003255 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003256 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003257 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3258 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3259 const cricket::TransportInfo* atinfo =
3260 desc->GetTransportInfoByName("audio_content_name");
3261 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3262 atinfo->description.connection_role);
3263 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003264 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003265 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3266 vtinfo->description.connection_role);
3267}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003268
3269// Verifies that the order of the serialized m-lines follows the order of the
3270// ContentInfo in SessionDescription, and vise versa for deserialization.
3271TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003272 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003273 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3274 kSdpSctpDataChannelString};
3275 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3276 cricket::MEDIA_TYPE_VIDEO,
3277 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003278
3279 // Verifies all 6 permutations.
3280 for (size_t i = 0; i < 6; ++i) {
3281 size_t media_content_in_sdp[3];
3282 // The index of the first media content.
3283 media_content_in_sdp[0] = i / 2;
3284 // The index of the second media content.
3285 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3286 // The index of the third media content.
3287 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3288
3289 std::string sdp_string = kSdpSessionString;
3290 for (size_t i = 0; i < 3; ++i)
3291 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3292
3293 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3294 cricket::SessionDescription* desc = jdesc.description();
3295 EXPECT_EQ(3u, desc->contents().size());
3296
3297 for (size_t i = 0; i < 3; ++i) {
3298 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003299 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003300 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3301 }
3302
Steve Antone831b8c2018-02-01 12:22:16 -08003303 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003304 EXPECT_EQ(sdp_string, serialized_sdp);
3305 }
3306}
deadbeef9d3584c2016-02-16 17:54:10 -08003307
deadbeef25ed4352016-12-12 18:37:36 -08003308TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3309 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003310 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003311 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003312 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3313 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3314}
3315
deadbeef12771a12017-01-03 13:53:47 -08003316// The semantics of "a=bundle-only" are only defined when it's used in
3317// combination with a 0 port on the m= line. We should ignore it if used with a
3318// nonzero port.
3319TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3320 // Make the base bundle-only description but unset the bundle-only flag.
3321 MakeBundleOnlyDescription();
3322 jdesc_.description()->contents()[1].bundle_only = false;
3323
3324 std::string modified_sdp = kBundleOnlySdpFullString;
3325 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003326 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003327 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3328 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003329}
3330
3331TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3332 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003333 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003334}
3335
deadbeef9d3584c2016-02-16 17:54:10 -08003336TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3337 MakePlanBDescription();
3338
Steve Antona3a92c22017-12-07 10:27:41 -08003339 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003340 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3341
3342 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3343}
3344
3345TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3346 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003347 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003348}
3349
3350TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3351 MakeUnifiedPlanDescription();
3352
Steve Antona3a92c22017-12-07 10:27:41 -08003353 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003354 EXPECT_TRUE(
3355 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3356
3357 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3358}
3359
3360TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3361 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003362 TestSerialize(jdesc_);
3363}
3364
Seth Hampson5b4f0752018-04-02 16:31:36 -07003365// This tests deserializing a Unified Plan SDP that is compatible with both
3366// Unified Plan and Plan B style SDP. It tests the case for audio/video tracks
3367// with no stream ids and multiple stream ids. For parsing this, the Unified
3368// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3369// lines do not support multiple stream ids and no stream ids.
3370TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionSpecialMsid) {
3371 MakeUnifiedPlanDescriptionMultipleStreamIds();
3372
3373 JsepSessionDescription deserialized_description(kDummyType);
3374 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3375 &deserialized_description));
3376
3377 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3378}
3379
3380TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionSpecialMsid) {
3381 MakeUnifiedPlanDescriptionMultipleStreamIds();
3382 TestSerialize(jdesc_);
3383}
3384
Seth Hampson5897a6e2018-04-03 11:16:33 -07003385// This tests that a Unified Plan SDP with no a=ssrc lines is
3386// serialized/deserialized appropriately. In this case the
3387// MediaContentDescription will contain a StreamParams object that doesn't have
3388// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3389// SSRC lines.
3390TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3391 MakeUnifiedPlanDescription();
3392 RemoveSsrcSignalingFromStreamParams();
3393 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3394 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3395
3396 JsepSessionDescription deserialized_description(kDummyType);
3397 EXPECT_TRUE(
3398 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3399 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3400}
3401
3402TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3403 MakeUnifiedPlanDescription();
3404 RemoveSsrcSignalingFromStreamParams();
3405
3406 TestSerialize(jdesc_);
3407}
3408
Steve Antone831b8c2018-02-01 12:22:16 -08003409TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3410 JsepSessionDescription jsep_desc(kDummyType);
3411 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3412 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3413}
3414
3415TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3416 JsepSessionDescription jsep_desc(kDummyType);
3417 std::string sdp = kSdpSessionString;
3418 sdp += kSdpSctpDataChannelString;
3419 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3420 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3421}
3422
3423TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3424 JsepSessionDescription jsep_desc(kDummyType);
3425 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3426 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3427 jsep_desc.description()->msid_signaling());
3428}
3429
3430TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3431 JsepSessionDescription jsep_desc(kDummyType);
3432 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3433 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3434 jsep_desc.description()->msid_signaling());
3435}
3436
3437const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3438const char kSsrcAttributeMsidLine[] =
3439 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3440
3441TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3442 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3443 std::string sdp = webrtc::SdpSerialize(jdesc_);
3444
3445 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3446 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3447}
3448
3449TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3450 jdesc_.description()->set_msid_signaling(
3451 cricket::kMsidSignalingSsrcAttribute);
3452 std::string sdp = webrtc::SdpSerialize(jdesc_);
3453
3454 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3455 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3456}
3457
3458TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3459 jdesc_.description()->set_msid_signaling(
3460 cricket::kMsidSignalingMediaSection |
3461 cricket::kMsidSignalingSsrcAttribute);
3462 std::string sdp = webrtc::SdpSerialize(jdesc_);
3463
3464 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3465 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003466}
deadbeef7e146cb2016-09-28 10:04:34 -07003467
3468// Regression test for heap overflow bug:
3469// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3470TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003471 // The issue occurs when the sctp-port attribute is found in a video
3472 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003473 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003474 "v=0\r\n"
3475 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3476 "s=-\r\n"
3477 "t=0 0\r\n"
3478 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3479 "a=sctp-port 5000\r\n"
3480 "a=fmtp:108 foo=10\r\n";
3481
3482 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3483 "sctp-port");
3484}
deadbeefb2362572016-12-13 16:37:06 -08003485
3486// Regression test for integer overflow bug:
3487// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3488TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003489 // Bandwidth attribute is the max signed 32-bit int, which will get
3490 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003491 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003492 "v=0\r\n"
3493 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3494 "s=-\r\n"
3495 "t=0 0\r\n"
3496 "m=video 3457 RTP/SAVPF 120\r\n"
3497 "b=AS:2147483647\r\n"
3498 "foo=fail\r\n";
3499
3500 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3501}
deadbeef7bcdb692017-01-20 12:43:58 -08003502
deadbeefbc88c6b2017-08-02 11:26:34 -07003503// Similar to the above, except that negative values are illegal, not just
3504// error-prone as large values are.
3505// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3506TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3507 static const char kSdpWithNegativeBandwidth[] =
3508 "v=0\r\n"
3509 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3510 "s=-\r\n"
3511 "t=0 0\r\n"
3512 "m=video 3457 RTP/SAVPF 120\r\n"
3513 "b=AS:-1000\r\n";
3514
3515 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3516}
3517
deadbeef3e8016e2017-08-03 17:49:30 -07003518// An exception to the above rule: a value of -1 for b=AS should just be
3519// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3520// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3521// limit", but this is now what ommitting the attribute entirely will do, so
3522// ignoring it will have the intended effect.
3523TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3524 static const char kSdpWithBandwidthOfNegativeOne[] =
3525 "v=0\r\n"
3526 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3527 "s=-\r\n"
3528 "t=0 0\r\n"
3529 "m=video 3457 RTP/SAVPF 120\r\n"
3530 "b=AS:-1\r\n";
3531
Steve Antona3a92c22017-12-07 10:27:41 -08003532 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003533 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003534 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003535 GetFirstVideoContentDescription(jdesc_output.description());
3536 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003537 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3538}
3539
deadbeef7bcdb692017-01-20 12:43:58 -08003540// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3541// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3542// Regression test for:
3543// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3544TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3545 // Important piece is "ufrag foo pwd bar".
3546 static const char kSdpWithIceCredentialsInCandidateString[] =
3547 "v=0\r\n"
3548 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3549 "s=-\r\n"
3550 "t=0 0\r\n"
3551 "m=audio 9 RTP/SAVPF 111\r\n"
3552 "c=IN IP4 0.0.0.0\r\n"
3553 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3554 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3555 "a=rtpmap:111 opus/48000/2\r\n"
3556 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3557 "generation 2 ufrag foo pwd bar\r\n";
3558
Steve Antona3a92c22017-12-07 10:27:41 -08003559 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003560 EXPECT_TRUE(
3561 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3562 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3563 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003564 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003565 cricket::Candidate c = candidates->at(0)->candidate();
3566 EXPECT_EQ("ufrag_voice", c.username());
3567 EXPECT_EQ("pwd_voice", c.password());
3568}
deadbeef90f1e1e2017-02-10 12:35:05 -08003569
Johannes Kron211856b2018-09-06 12:12:28 +02003570// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3571// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3572// Regression test for:
3573// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3574TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3575 static const char kSdpWithFooIceCredentials[] =
3576 "v=0\r\n"
3577 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3578 "s=-\r\n"
3579 "t=0 0\r\n"
3580 "m=audio 9 RTP/SAVPF 111\r\n"
3581 "c=IN IP4 0.0.0.0\r\n"
3582 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3583 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3584 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3585 "a=rtpmap:111 opus/48000/2\r\n"
3586 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3587 "generation 2\r\n";
3588
3589 JsepSessionDescription jdesc_output(kDummyType);
3590 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3591 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3592 ASSERT_NE(nullptr, candidates);
3593 ASSERT_EQ(1U, candidates->count());
3594 cricket::Candidate c = candidates->at(0)->candidate();
3595 EXPECT_EQ("ufrag_voice", c.username());
3596 EXPECT_EQ("pwd_voice", c.password());
3597}
3598
deadbeef90f1e1e2017-02-10 12:35:05 -08003599// Test that SDP with an invalid port number in "a=candidate" lines is
3600// rejected, without crashing.
3601// Regression test for:
3602// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3603TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3604 static const char kSdpWithInvalidCandidatePort[] =
3605 "v=0\r\n"
3606 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3607 "s=-\r\n"
3608 "t=0 0\r\n"
3609 "m=audio 9 RTP/SAVPF 111\r\n"
3610 "c=IN IP4 0.0.0.0\r\n"
3611 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3612 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3613 "a=rtpmap:111 opus/48000/2\r\n"
3614 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3615 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3616
Steve Antona3a92c22017-12-07 10:27:41 -08003617 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003618 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3619}
deadbeefa4549d62017-02-10 17:26:22 -08003620
3621// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3622// Regression test for:
3623// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3624TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3625 static const char kSdpWithMissingTrackId[] =
3626 "v=0\r\n"
3627 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3628 "s=-\r\n"
3629 "t=0 0\r\n"
3630 "m=audio 9 RTP/SAVPF 111\r\n"
3631 "c=IN IP4 0.0.0.0\r\n"
3632 "a=rtpmap:111 opus/48000/2\r\n"
3633 "a=msid:stream_id \r\n";
3634
Steve Antona3a92c22017-12-07 10:27:41 -08003635 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003636 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3637}
3638
3639TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3640 static const char kSdpWithMissingStreamId[] =
3641 "v=0\r\n"
3642 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3643 "s=-\r\n"
3644 "t=0 0\r\n"
3645 "m=audio 9 RTP/SAVPF 111\r\n"
3646 "c=IN IP4 0.0.0.0\r\n"
3647 "a=rtpmap:111 opus/48000/2\r\n"
3648 "a=msid: track_id\r\n";
3649
Steve Antona3a92c22017-12-07 10:27:41 -08003650 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003651 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3652}
zhihuang38989e52017-03-21 11:04:53 -07003653
3654// Tests that if both session-level address and media-level address exist, use
3655// the media-level address.
3656TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003657 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003658
3659 // Sesssion-level address.
3660 std::string sdp = kSdpFullString;
3661 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3662 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3663
3664 const auto& content1 = jsep_desc.description()->contents()[0];
3665 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003666 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003667 const auto& content2 = jsep_desc.description()->contents()[1];
3668 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003669 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003670}
3671
3672// Tests that the session-level connection address will be used if the media
3673// level-addresses are not specified.
3674TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003675 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003676
3677 // Sesssion-level address.
3678 std::string sdp = kSdpString;
3679 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3680 // Remove the media level addresses.
3681 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3682 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3683 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3684
3685 const auto& content1 = jsep_desc.description()->contents()[0];
3686 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003687 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003688 const auto& content2 = jsep_desc.description()->contents()[1];
3689 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003690 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003691}
3692
3693TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003694 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003695
3696 std::string sdp = kSdpString;
3697 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3698 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3699 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3700 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3701 &sdp);
3702 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3703 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3704 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3705 &sdp);
3706 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3707 const auto& content1 = jsep_desc.description()->contents()[0];
3708 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003709 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003710 const auto& content2 = jsep_desc.description()->contents()[1];
3711 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003712 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003713}
3714
3715// Test that the invalid or unsupprted connection data cannot be parsed.
3716TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003717 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003718 std::string sdp = kSdpString;
3719 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3720
3721 // Unsupported multicast IPv4 address.
3722 sdp = kSdpFullString;
3723 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3724 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3725
3726 // Unsupported multicast IPv6 address.
3727 sdp = kSdpFullString;
3728 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3729 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3730
3731 // Mismatched address type.
3732 sdp = kSdpFullString;
3733 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3734 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3735
3736 sdp = kSdpFullString;
3737 Replace("c=IN IP4 74.125.224.39\r\n",
3738 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3739 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3740}
3741
3742TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08003743 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003744 MakeDescriptionWithoutCandidates(&expected_jsep);
3745 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08003746 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07003747 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08003748 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003749 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08003750 auto audio_desc = jdesc.description()
3751 ->GetContentByName(kAudioContentName)
3752 ->media_description();
3753 auto video_desc = jdesc.description()
3754 ->GetContentByName(kVideoContentName)
3755 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07003756 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3757 audio_desc->connection_address().ToString());
3758 EXPECT_EQ(video_desc_->connection_address().ToString(),
3759 video_desc->connection_address().ToString());
3760}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07003761
3762// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
3763// used (i.e., a single space as the session name)." So we should accept that.
3764TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
3765 JsepSessionDescription jsep_desc(kDummyType);
3766 std::string sdp = kSdpString;
3767 Replace("s=-\r\n", "s= \r\n", &sdp);
3768 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3769}