blob: 654246e24311882404e2bbb2a8ff805aa1f4156e [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
13#include <cstdint>
14#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto_params.h"
22#include "api/jsep_session_description.h"
23#include "api/media_types.h"
24#include "api/rtp_parameters.h"
25#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "media/base/media_constants.h"
28#include "media/base/stream_params.h"
29#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 15:03:05 +020030#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "p2p/base/transport_description.h"
32#include "p2p/base/transport_info.h"
33#include "pc/media_session.h"
34#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "rtc_base/message_digest.h"
37#include "rtc_base/socket_address.h"
38#include "rtc_base/ssl_fingerprint.h"
39#include "rtc_base/string_encode.h"
40#include "rtc_base/string_utils.h"
Steve Anton06817cd2018-12-18 15:55:30 -080041#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010042#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020043
ossu7bb87ee2017-01-23 04:56:25 -080044#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080045#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080046#endif
Steve Anton10542f22019-01-11 09:11:00 -080047#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048
49using cricket::AudioCodec;
50using cricket::AudioContentDescription;
51using cricket::Candidate;
Steve Anton06817cd2018-12-18 15:55:30 -080052using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053using cricket::ContentInfo;
54using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055using cricket::DataCodec;
56using cricket::DataContentDescription;
57using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
58using cricket::ICE_CANDIDATE_COMPONENT_RTP;
59using cricket::kFecSsrcGroupSemantics;
60using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-20 16:34:00 -080061using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 15:55:30 -080062using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080063using cricket::RidDescription;
64using cricket::RidDirection;
Steve Anton06817cd2018-12-18 15:55:30 -080065using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 11:35:05 -080066using cricket::SimulcastDescription;
67using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using cricket::StreamParams;
69using cricket::STUN_PORT_TYPE;
70using cricket::TransportDescription;
71using cricket::TransportInfo;
72using cricket::VideoCodec;
73using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 15:55:30 -080074using ::testing::ElementsAre;
75using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using webrtc::IceCandidateCollection;
77using webrtc::IceCandidateInterface;
78using webrtc::JsepIceCandidate;
79using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 11:24:55 -070080using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 14:57:10 -080081using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 10:27:41 -080083using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::SessionDescriptionInterface;
85
86typedef std::vector<AudioCodec> AudioCodecs;
87typedef std::vector<Candidate> Candidates;
88
Peter Boström0c4e06b2015-10-07 12:23:21 +020089static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-17 19:48:38 -080090static const char kDefaultSctpPortStr[] = "5000";
91static const uint16_t kUnusualSctpPort = 9556;
92static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020094static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 15:17:14 -080095static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 15:17:14 -080097static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 12:23:21 +020099static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100static const char kCandidateFoundation1[] = "a0+B/1";
101static const char kCandidateFoundation2[] = "a0+B/2";
102static const char kCandidateFoundation3[] = "a0+B/3";
103static const char kCandidateFoundation4[] = "a0+B/4";
104static const char kAttributeCryptoVoice[] =
105 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
106 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
107 "dummy_session_params\r\n";
108static const char kAttributeCryptoVideo[] =
109 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
110 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 15:03:05 +0200111static const char kFingerprint[] =
112 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
Johannes Kron0854eb62018-10-10 22:33:20 +0200114static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115static const int kExtmapId = 1;
116static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
117static const char kExtmap[] =
118 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
119static const char kExtmapWithDirectionAndAttribute[] =
120 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 12:31:36 -0700121static const char kExtmapWithDirectionAndAttributeEncrypted[] =
122 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
123 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124
Peter Boström0c4e06b2015-10-07 12:23:21 +0200125static const uint8_t kIdentityDigest[] = {
126 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
127 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128
lally@webrtc.org34807282015-02-24 20:19:39 +0000129static const char kDtlsSctp[] = "DTLS/SCTP";
130static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
131static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35 +0000132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133struct CodecParams {
134 int max_ptime;
135 int ptime;
136 int min_ptime;
137 int sprop_stereo;
138 int stereo;
139 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000140 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141};
142
deadbeef9d3584c2016-02-16 17:54:10 -0800143// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
144// instead of "a=crypto", and have an explicit test for adding "a=crypto".
145// Currently it's the other way around.
146
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147// Reference sdp string
148static const char kSdpFullString[] =
149 "v=0\r\n"
150 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
151 "s=-\r\n"
152 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800153 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
155 "c=IN IP4 74.125.127.126\r\n"
156 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
157 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
158 "generation 2\r\n"
159 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
160 "generation 2\r\n"
161 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
162 "generation 2\r\n"
163 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
166 "raddr 192.168.1.5 rport 2346 "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
169 "raddr 192.168.1.5 rport 2348 "
170 "generation 2\r\n"
171 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
172 "a=mid:audio_content_name\r\n"
173 "a=sendrecv\r\n"
174 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800175 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
177 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
178 "dummy_session_params\r\n"
179 "a=rtpmap:111 opus/48000/2\r\n"
180 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000181 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 "a=ssrc:1 cname:stream_1_cname\r\n"
183 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
184 "a=ssrc:1 mslabel:local_stream_1\r\n"
185 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 "m=video 3457 RTP/SAVPF 120\r\n"
187 "c=IN IP4 74.125.224.39\r\n"
188 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
189 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
190 "generation 2\r\n"
191 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
192 "generation 2\r\n"
193 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
194 "generation 2\r\n"
195 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
196 "generation 2\r\n"
197 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
198 "generation 2\r\n"
199 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
200 "generation 2\r\n"
201 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
202 "a=mid:video_content_name\r\n"
203 "a=sendrecv\r\n"
204 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
205 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
206 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800207 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 "a=ssrc:2 cname:stream_1_cname\r\n"
209 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
210 "a=ssrc:2 mslabel:local_stream_1\r\n"
211 "a=ssrc:2 label:video_track_id_1\r\n"
212 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800213 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800215 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216
217// SDP reference string without the candidates.
218static const char kSdpString[] =
219 "v=0\r\n"
220 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
221 "s=-\r\n"
222 "t=0 0\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800223 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000224 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000225 "c=IN IP4 0.0.0.0\r\n"
226 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
228 "a=mid:audio_content_name\r\n"
229 "a=sendrecv\r\n"
230 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 12:37:51 -0800231 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
233 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
234 "dummy_session_params\r\n"
235 "a=rtpmap:111 opus/48000/2\r\n"
236 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +0000237 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 "a=ssrc:1 cname:stream_1_cname\r\n"
239 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
240 "a=ssrc:1 mslabel:local_stream_1\r\n"
241 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000242 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000243 "c=IN IP4 0.0.0.0\r\n"
244 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
246 "a=mid:video_content_name\r\n"
247 "a=sendrecv\r\n"
248 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
249 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
250 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800251 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 "a=ssrc:2 cname:stream_1_cname\r\n"
253 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
254 "a=ssrc:2 mslabel:local_stream_1\r\n"
255 "a=ssrc:2 label:video_track_id_1\r\n"
256 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800257 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-16 17:54:10 -0800259 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260
261static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000262 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000263 "c=IN IP4 0.0.0.0\r\n"
264 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 "a=ice-ufrag:ufrag_data\r\n"
266 "a=ice-pwd:pwd_data\r\n"
267 "a=mid:data_content_name\r\n"
268 "a=sendrecv\r\n"
269 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
270 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
271 "a=rtpmap:101 google-data/90000\r\n"
272 "a=ssrc:10 cname:data_channel_cname\r\n"
273 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
274 "a=ssrc:10 mslabel:data_channel\r\n"
275 "a=ssrc:10 label:data_channeld0\r\n";
276
277static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000278 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000279 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 "a=ice-ufrag:ufrag_data\r\n"
281 "a=ice-pwd:pwd_data\r\n"
282 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000283 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
lally@webrtc.orgec97c652015-02-24 20:18:48 +0000285// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +0000286static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26 +0000287 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
288 "a=max-message-size=100000\r\n"
289 "a=sctp-port 5000\r\n"
290 "c=IN IP4 0.0.0.0\r\n"
291 "a=ice-ufrag:ufrag_data\r\n"
292 "a=ice-pwd:pwd_data\r\n"
293 "a=mid:data_content_name\r\n";
294
lally69f57602015-10-08 10:15:04 -0700295static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
296 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
297 "a=max-message-size=100000\r\n"
298 "a=sctp-port:5000\r\n"
299 "c=IN IP4 0.0.0.0\r\n"
300 "a=ice-ufrag:ufrag_data\r\n"
301 "a=ice-pwd:pwd_data\r\n"
302 "a=mid:data_content_name\r\n";
303
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304static const char kSdpSctpDataChannelWithCandidatesString[] =
305 "m=application 2345 DTLS/SCTP 5000\r\n"
306 "c=IN IP4 74.125.127.126\r\n"
307 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
308 "generation 2\r\n"
309 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
310 "generation 2\r\n"
311 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
312 "raddr 192.168.1.5 rport 2346 "
313 "generation 2\r\n"
314 "a=ice-ufrag:ufrag_data\r\n"
315 "a=ice-pwd:pwd_data\r\n"
316 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33 +0000317 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000319static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 "v=0\r\n"
321 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
322 "s=-\r\n"
323 "t=0 0\r\n"
324 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000325 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000326 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000327 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000328 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000329 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000330 "a=x-google-flag:conference\r\n";
331
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000332static const char kSdpSessionString[] =
333 "v=0\r\n"
334 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
335 "s=-\r\n"
336 "t=0 0\r\n"
337 "a=msid-semantic: WMS local_stream\r\n";
338
339static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000340 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000341 "c=IN IP4 0.0.0.0\r\n"
342 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000343 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
344 "a=mid:audio_content_name\r\n"
345 "a=sendrecv\r\n"
346 "a=rtpmap:111 opus/48000/2\r\n"
347 "a=ssrc:1 cname:stream_1_cname\r\n"
348 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
349 "a=ssrc:1 mslabel:local_stream\r\n"
350 "a=ssrc:1 label:audio_track_id_1\r\n";
351
352static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +0000353 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +0000354 "c=IN IP4 0.0.0.0\r\n"
355 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000356 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
357 "a=mid:video_content_name\r\n"
358 "a=sendrecv\r\n"
359 "a=rtpmap:120 VP8/90000\r\n"
360 "a=ssrc:2 cname:stream_1_cname\r\n"
361 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
362 "a=ssrc:2 mslabel:local_stream\r\n"
363 "a=ssrc:2 label:video_track_id_1\r\n";
364
deadbeef25ed4352016-12-12 18:37:36 -0800365// Reference sdp string using bundle-only.
366static const char kBundleOnlySdpFullString[] =
367 "v=0\r\n"
368 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
369 "s=-\r\n"
370 "t=0 0\r\n"
371 "a=group:BUNDLE audio_content_name video_content_name\r\n"
372 "a=msid-semantic: WMS local_stream_1\r\n"
373 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
374 "c=IN IP4 74.125.127.126\r\n"
375 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
376 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
377 "generation 2\r\n"
378 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
379 "generation 2\r\n"
380 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
381 "generation 2\r\n"
382 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
383 "generation 2\r\n"
384 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
385 "raddr 192.168.1.5 rport 2346 "
386 "generation 2\r\n"
387 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
388 "raddr 192.168.1.5 rport 2348 "
389 "generation 2\r\n"
390 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
391 "a=mid:audio_content_name\r\n"
392 "a=sendrecv\r\n"
393 "a=rtcp-mux\r\n"
394 "a=rtcp-rsize\r\n"
395 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
396 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
397 "dummy_session_params\r\n"
398 "a=rtpmap:111 opus/48000/2\r\n"
399 "a=rtpmap:103 ISAC/16000\r\n"
400 "a=rtpmap:104 ISAC/32000\r\n"
401 "a=ssrc:1 cname:stream_1_cname\r\n"
402 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
403 "a=ssrc:1 mslabel:local_stream_1\r\n"
404 "a=ssrc:1 label:audio_track_id_1\r\n"
405 "m=video 0 RTP/SAVPF 120\r\n"
406 "c=IN IP4 0.0.0.0\r\n"
407 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
408 "a=bundle-only\r\n"
409 "a=mid:video_content_name\r\n"
410 "a=sendrecv\r\n"
411 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
412 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
413 "a=rtpmap:120 VP8/90000\r\n"
414 "a=ssrc-group:FEC 2 3\r\n"
415 "a=ssrc:2 cname:stream_1_cname\r\n"
416 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
417 "a=ssrc:2 mslabel:local_stream_1\r\n"
418 "a=ssrc:2 label:video_track_id_1\r\n"
419 "a=ssrc:3 cname:stream_1_cname\r\n"
420 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
421 "a=ssrc:3 mslabel:local_stream_1\r\n"
422 "a=ssrc:3 label:video_track_id_1\r\n";
423
deadbeef9d3584c2016-02-16 17:54:10 -0800424// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
425// tracks.
426static const char kPlanBSdpFullString[] =
427 "v=0\r\n"
428 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
429 "s=-\r\n"
430 "t=0 0\r\n"
431 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
432 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
433 "c=IN IP4 74.125.127.126\r\n"
434 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
435 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
436 "generation 2\r\n"
437 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
438 "generation 2\r\n"
439 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
440 "generation 2\r\n"
441 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
442 "generation 2\r\n"
443 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
444 "raddr 192.168.1.5 rport 2346 "
445 "generation 2\r\n"
446 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
447 "raddr 192.168.1.5 rport 2348 "
448 "generation 2\r\n"
449 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
450 "a=mid:audio_content_name\r\n"
451 "a=sendrecv\r\n"
452 "a=rtcp-mux\r\n"
453 "a=rtcp-rsize\r\n"
454 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
455 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
456 "dummy_session_params\r\n"
457 "a=rtpmap:111 opus/48000/2\r\n"
458 "a=rtpmap:103 ISAC/16000\r\n"
459 "a=rtpmap:104 ISAC/32000\r\n"
460 "a=ssrc:1 cname:stream_1_cname\r\n"
461 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
462 "a=ssrc:1 mslabel:local_stream_1\r\n"
463 "a=ssrc:1 label:audio_track_id_1\r\n"
464 "a=ssrc:4 cname:stream_2_cname\r\n"
465 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
466 "a=ssrc:4 mslabel:local_stream_2\r\n"
467 "a=ssrc:4 label:audio_track_id_2\r\n"
468 "m=video 3457 RTP/SAVPF 120\r\n"
469 "c=IN IP4 74.125.224.39\r\n"
470 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
471 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
472 "generation 2\r\n"
473 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
474 "generation 2\r\n"
475 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
476 "generation 2\r\n"
477 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
478 "generation 2\r\n"
479 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
480 "generation 2\r\n"
481 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
482 "generation 2\r\n"
483 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
484 "a=mid:video_content_name\r\n"
485 "a=sendrecv\r\n"
486 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
487 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
488 "a=rtpmap:120 VP8/90000\r\n"
489 "a=ssrc-group:FEC 2 3\r\n"
490 "a=ssrc:2 cname:stream_1_cname\r\n"
491 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
492 "a=ssrc:2 mslabel:local_stream_1\r\n"
493 "a=ssrc:2 label:video_track_id_1\r\n"
494 "a=ssrc:3 cname:stream_1_cname\r\n"
495 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
496 "a=ssrc:3 mslabel:local_stream_1\r\n"
497 "a=ssrc:3 label:video_track_id_1\r\n"
498 "a=ssrc:5 cname:stream_2_cname\r\n"
499 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
500 "a=ssrc:5 mslabel:local_stream_2\r\n"
501 "a=ssrc:5 label:video_track_id_2\r\n"
502 "a=ssrc:6 cname:stream_2_cname\r\n"
503 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
504 "a=ssrc:6 mslabel:local_stream_2\r\n"
505 "a=ssrc:6 label:video_track_id_3\r\n";
506
507// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
508// tracks.
509static const char kUnifiedPlanSdpFullString[] =
510 "v=0\r\n"
511 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
512 "s=-\r\n"
513 "t=0 0\r\n"
514 "a=msid-semantic: WMS local_stream_1\r\n"
515 // Audio track 1, stream 1 (with candidates).
516 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
517 "c=IN IP4 74.125.127.126\r\n"
518 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
519 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
520 "generation 2\r\n"
521 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
522 "generation 2\r\n"
523 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
524 "generation 2\r\n"
525 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
526 "generation 2\r\n"
527 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
528 "raddr 192.168.1.5 rport 2346 "
529 "generation 2\r\n"
530 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
531 "raddr 192.168.1.5 rport 2348 "
532 "generation 2\r\n"
533 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
534 "a=mid:audio_content_name\r\n"
535 "a=msid:local_stream_1 audio_track_id_1\r\n"
536 "a=sendrecv\r\n"
537 "a=rtcp-mux\r\n"
538 "a=rtcp-rsize\r\n"
539 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
540 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
541 "dummy_session_params\r\n"
542 "a=rtpmap:111 opus/48000/2\r\n"
543 "a=rtpmap:103 ISAC/16000\r\n"
544 "a=rtpmap:104 ISAC/32000\r\n"
545 "a=ssrc:1 cname:stream_1_cname\r\n"
546 // Video track 1, stream 1 (with candidates).
547 "m=video 3457 RTP/SAVPF 120\r\n"
548 "c=IN IP4 74.125.224.39\r\n"
549 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
550 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
551 "generation 2\r\n"
552 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
553 "generation 2\r\n"
554 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
555 "generation 2\r\n"
556 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
557 "generation 2\r\n"
558 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
559 "generation 2\r\n"
560 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
561 "generation 2\r\n"
562 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
563 "a=mid:video_content_name\r\n"
564 "a=msid:local_stream_1 video_track_id_1\r\n"
565 "a=sendrecv\r\n"
566 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
567 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
568 "a=rtpmap:120 VP8/90000\r\n"
569 "a=ssrc-group:FEC 2 3\r\n"
570 "a=ssrc:2 cname:stream_1_cname\r\n"
571 "a=ssrc:3 cname:stream_1_cname\r\n"
572 // Audio track 2, stream 2.
573 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
574 "c=IN IP4 0.0.0.0\r\n"
575 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
576 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
577 "a=mid:audio_content_name_2\r\n"
578 "a=msid:local_stream_2 audio_track_id_2\r\n"
579 "a=sendrecv\r\n"
580 "a=rtcp-mux\r\n"
581 "a=rtcp-rsize\r\n"
582 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
583 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
584 "dummy_session_params\r\n"
585 "a=rtpmap:111 opus/48000/2\r\n"
586 "a=rtpmap:103 ISAC/16000\r\n"
587 "a=rtpmap:104 ISAC/32000\r\n"
588 "a=ssrc:4 cname:stream_2_cname\r\n"
589 // Video track 2, stream 2.
590 "m=video 9 RTP/SAVPF 120\r\n"
591 "c=IN IP4 0.0.0.0\r\n"
592 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
593 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
594 "a=mid:video_content_name_2\r\n"
595 "a=msid:local_stream_2 video_track_id_2\r\n"
596 "a=sendrecv\r\n"
597 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
598 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
599 "a=rtpmap:120 VP8/90000\r\n"
600 "a=ssrc:5 cname:stream_2_cname\r\n"
601 // Video track 3, stream 2.
602 "m=video 9 RTP/SAVPF 120\r\n"
603 "c=IN IP4 0.0.0.0\r\n"
604 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
605 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
606 "a=mid:video_content_name_3\r\n"
607 "a=msid:local_stream_2 video_track_id_3\r\n"
608 "a=sendrecv\r\n"
609 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
610 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
611 "a=rtpmap:120 VP8/90000\r\n"
612 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613
Seth Hampson5b4f0752018-04-02 16:31:36 -0700614// Unified Plan SDP reference string:
615// - audio track 1 has 1 a=msid lines
616// - audio track 2 has 2 a=msid lines
617// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
618// there are 0 media stream ids.
619// This Unified Plan SDP represents a SDP that signals the msid using both
620// a=msid and a=ssrc msid semantics.
621static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
622 "v=0\r\n"
623 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
624 "s=-\r\n"
625 "t=0 0\r\n"
626 "a=msid-semantic: WMS local_stream_1\r\n"
627 // Audio track 1, with 1 stream id.
628 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
629 "c=IN IP4 74.125.127.126\r\n"
630 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
631 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
632 "generation 2\r\n"
633 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
634 "generation 2\r\n"
635 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
636 "generation 2\r\n"
637 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
638 "generation 2\r\n"
639 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
640 "raddr 192.168.1.5 rport 2346 "
641 "generation 2\r\n"
642 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
643 "raddr 192.168.1.5 rport 2348 "
644 "generation 2\r\n"
645 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
646 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700647 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700648 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700649 "a=rtcp-mux\r\n"
650 "a=rtcp-rsize\r\n"
651 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
652 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
653 "dummy_session_params\r\n"
654 "a=rtpmap:111 opus/48000/2\r\n"
655 "a=rtpmap:103 ISAC/16000\r\n"
656 "a=rtpmap:104 ISAC/32000\r\n"
657 "a=ssrc:1 cname:stream_1_cname\r\n"
658 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
659 "a=ssrc:1 mslabel:local_stream_1\r\n"
660 "a=ssrc:1 label:audio_track_id_1\r\n"
661 // Audio track 2, with two stream ids.
662 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
663 "c=IN IP4 0.0.0.0\r\n"
664 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
665 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
666 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700667 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700668 "a=msid:local_stream_1 audio_track_id_2\r\n"
669 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700670 "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:4 cname:stream_1_cname\r\n"
679 // The support for Plan B msid signaling only includes the
680 // first media stream id "local_stream_1."
681 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
682 "a=ssrc:4 mslabel:local_stream_1\r\n"
683 "a=ssrc:4 label:audio_track_id_2\r\n"
684 // Audio track 3, with no stream ids.
685 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
686 "c=IN IP4 0.0.0.0\r\n"
687 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
688 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
689 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700690 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700691 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 16:31:36 -0700692 "a=rtcp-mux\r\n"
693 "a=rtcp-rsize\r\n"
694 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
695 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
696 "dummy_session_params\r\n"
697 "a=rtpmap:111 opus/48000/2\r\n"
698 "a=rtpmap:103 ISAC/16000\r\n"
699 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 10:25:28 -0700700 "a=ssrc:7 cname:stream_2_cname\r\n"
701 "a=ssrc:7 msid:- audio_track_id_3\r\n"
702 "a=ssrc:7 mslabel:-\r\n"
703 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700704
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800705// SDP string for unified plan without SSRCs
706static const char kUnifiedPlanSdpFullStringNoSsrc[] =
707 "v=0\r\n"
708 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
709 "s=-\r\n"
710 "t=0 0\r\n"
711 "a=msid-semantic: WMS local_stream_1\r\n"
712 // Audio track 1, stream 1 (with candidates).
713 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
714 "c=IN IP4 74.125.127.126\r\n"
715 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
716 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
717 "generation 2\r\n"
718 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
719 "generation 2\r\n"
720 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
721 "generation 2\r\n"
722 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
723 "generation 2\r\n"
724 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
725 "raddr 192.168.1.5 rport 2346 "
726 "generation 2\r\n"
727 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
728 "raddr 192.168.1.5 rport 2348 "
729 "generation 2\r\n"
730 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
731 "a=mid:audio_content_name\r\n"
732 "a=msid:local_stream_1 audio_track_id_1\r\n"
733 "a=sendrecv\r\n"
734 "a=rtcp-mux\r\n"
735 "a=rtcp-rsize\r\n"
736 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
737 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
738 "dummy_session_params\r\n"
739 "a=rtpmap:111 opus/48000/2\r\n"
740 "a=rtpmap:103 ISAC/16000\r\n"
741 "a=rtpmap:104 ISAC/32000\r\n"
742 // Video track 1, stream 1 (with candidates).
743 "m=video 3457 RTP/SAVPF 120\r\n"
744 "c=IN IP4 74.125.224.39\r\n"
745 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
746 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
747 "generation 2\r\n"
748 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
749 "generation 2\r\n"
750 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
751 "generation 2\r\n"
752 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
753 "generation 2\r\n"
754 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
755 "generation 2\r\n"
756 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
757 "generation 2\r\n"
758 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
759 "a=mid:video_content_name\r\n"
760 "a=msid:local_stream_1 video_track_id_1\r\n"
761 "a=sendrecv\r\n"
762 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
763 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
764 "a=rtpmap:120 VP8/90000\r\n"
765 // Audio track 2, stream 2.
766 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
767 "c=IN IP4 0.0.0.0\r\n"
768 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
769 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
770 "a=mid:audio_content_name_2\r\n"
771 "a=msid:local_stream_2 audio_track_id_2\r\n"
772 "a=sendrecv\r\n"
773 "a=rtcp-mux\r\n"
774 "a=rtcp-rsize\r\n"
775 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
776 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
777 "dummy_session_params\r\n"
778 "a=rtpmap:111 opus/48000/2\r\n"
779 "a=rtpmap:103 ISAC/16000\r\n"
780 "a=rtpmap:104 ISAC/32000\r\n"
781 // Video track 2, stream 2.
782 "m=video 9 RTP/SAVPF 120\r\n"
783 "c=IN IP4 0.0.0.0\r\n"
784 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
785 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
786 "a=mid:video_content_name_2\r\n"
787 "a=msid:local_stream_2 video_track_id_2\r\n"
788 "a=sendrecv\r\n"
789 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
790 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
791 "a=rtpmap:120 VP8/90000\r\n"
792 // Video track 3, stream 2.
793 "m=video 9 RTP/SAVPF 120\r\n"
794 "c=IN IP4 0.0.0.0\r\n"
795 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
796 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
797 "a=mid:video_content_name_3\r\n"
798 "a=msid:local_stream_2 video_track_id_3\r\n"
799 "a=sendrecv\r\n"
800 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
801 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
802 "a=rtpmap:120 VP8/90000\r\n";
803
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804// One candidate reference string as per W3c spec.
805// candidate:<blah> not a=candidate:<blah>CRLF
806static const char kRawCandidate[] =
807 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
808// One candidate reference string.
809static const char kSdpOneCandidate[] =
810 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
811 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000812
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +0000813static const char kSdpTcpActiveCandidate[] =
814 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
815 "tcptype active generation 2";
816static const char kSdpTcpPassiveCandidate[] =
817 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
818 "tcptype passive generation 2";
819static const char kSdpTcpSOCandidate[] =
820 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
821 "tcptype so generation 2";
822static const char kSdpTcpInvalidCandidate[] =
823 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
824 "tcptype invalid generation 2";
825
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +0000826// One candidate reference string with IPV6 address.
827static const char kRawIPV6Candidate[] =
828 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 12:04:36 -0700829 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830
831// One candidate reference string.
honghaiza54a0802015-12-16 18:37:23 -0800832static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-16 18:37:23 -0800834 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835
Zach Steinb336c272018-08-09 01:16:13 -0700836static const char kRawHostnameCandidate[] =
837 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839// Session id and version
840static const char kSessionId[] = "18446744069414584320";
841static const char kSessionVersion[] = "18446462598732840960";
842
deadbeef9d3584c2016-02-16 17:54:10 -0800843// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844static const char kIceOption1[] = "iceoption1";
845static const char kIceOption2[] = "iceoption2";
846static const char kIceOption3[] = "iceoption3";
847
deadbeef9d3584c2016-02-16 17:54:10 -0800848// ICE ufrags/passwords.
849static const char kUfragVoice[] = "ufrag_voice";
850static const char kPwdVoice[] = "pwd_voice";
851static const char kUfragVideo[] = "ufrag_video";
852static const char kPwdVideo[] = "pwd_video";
853static const char kUfragData[] = "ufrag_data";
854static const char kPwdData[] = "pwd_data";
855
856// Extra ufrags/passwords for extra unified plan m= sections.
857static const char kUfragVoice2[] = "ufrag_voice_2";
858static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700859static const char kUfragVoice3[] = "ufrag_voice_3";
860static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800861static const char kUfragVideo2[] = "ufrag_video_2";
862static const char kPwdVideo2[] = "pwd_video_2";
863static const char kUfragVideo3[] = "ufrag_video_3";
864static const char kPwdVideo3[] = "pwd_video_3";
865
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866// Content name
867static const char kAudioContentName[] = "audio_content_name";
868static const char kVideoContentName[] = "video_content_name";
869static const char kDataContentName[] = "data_content_name";
870
deadbeef9d3584c2016-02-16 17:54:10 -0800871// Extra content names for extra unified plan m= sections.
872static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 16:31:36 -0700873static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800874static const char kVideoContentName2[] = "video_content_name_2";
875static const char kVideoContentName3[] = "video_content_name_3";
876
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877// MediaStream 1
Seth Hampson845e8782018-03-02 11:34:10 -0800878static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879static const char kStream1Cname[] = "stream_1_cname";
880static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200881static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-16 17:54:10 -0800883static const uint32_t kVideoTrack1Ssrc1 = 2;
884static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885
886// MediaStream 2
Seth Hampson845e8782018-03-02 11:34:10 -0800887static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888static const char kStream2Cname[] = "stream_2_cname";
889static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200890static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-16 17:54:10 -0800891static const char kVideoTrackId2[] = "video_track_id_2";
892static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-16 17:54:10 -0800894static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 16:31:36 -0700895static const char kAudioTrackId3[] = "audio_track_id_3";
896static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897
898// DataChannel
899static const char kDataChannelLabel[] = "data_channel";
900static const char kDataChannelMsid[] = "data_channeld0";
901static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200902static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903
904// Candidate
905static const char kDummyMid[] = "dummy_mid";
906static const int kDummyIndex = 123;
907
908// Misc
Steve Antona3a92c22017-12-07 10:27:41 -0800909static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910
911// Helper functions
912
913static bool SdpDeserialize(const std::string& message,
914 JsepSessionDescription* jdesc) {
915 return webrtc::SdpDeserialize(message, jdesc, NULL);
916}
917
918static bool SdpDeserializeCandidate(const std::string& message,
919 JsepIceCandidate* candidate) {
920 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
921}
922
923// Add some extra |newlines| to the |message| after |line|.
924static void InjectAfter(const std::string& line,
925 const std::string& newlines,
926 std::string* message) {
927 const std::string tmp = line + newlines;
Yves Gerey665174f2018-06-19 15:03:05 +0200928 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
929 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930}
931
932static void Replace(const std::string& line,
933 const std::string& newlines,
934 std::string* message) {
Yves Gerey665174f2018-06-19 15:03:05 +0200935 rtc::replace_substrs(line.c_str(), line.length(), newlines.c_str(),
936 newlines.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937}
938
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000939// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
940// message.
941static void ExpectParseFailure(const std::string& bad_sdp,
942 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 10:27:41 -0800943 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000945 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09 +0000947 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
948}
949
950// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
951static void ExpectParseFailure(const char* good_part, const char* bad_part) {
952 std::string bad_sdp = kSdpFullString;
953 Replace(good_part, bad_part, &bad_sdp);
954 ExpectParseFailure(bad_sdp, bad_part);
955}
956
957// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
958static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
959 const std::string& newlines,
960 const std::string& bad_part) {
961 std::string bad_sdp = kSdpFullString;
962 InjectAfter(injectpoint, newlines, &bad_sdp);
963 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964}
965
Steve Anton4e70a722017-11-28 14:57:10 -0800966static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 std::string* message) {
968 std::string new_direction;
969 switch (direction) {
Steve Anton4e70a722017-11-28 14:57:10 -0800970 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 new_direction = "a=inactive";
972 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800973 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 new_direction = "a=sendonly";
975 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800976 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 new_direction = "a=recvonly";
978 break;
Steve Anton4e70a722017-11-28 14:57:10 -0800979 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 default:
981 new_direction = "a=sendrecv";
982 break;
983 }
984 Replace("a=sendrecv", new_direction, message);
985}
986
Yves Gerey665174f2018-06-19 15:03:05 +0200987static void ReplaceRejected(bool audio_rejected,
988 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 std::string* message) {
990 if (audio_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800991 Replace("m=audio 9", "m=audio 0", message);
992 Replace(kAttributeIceUfragVoice, "", message);
993 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 }
995 if (video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -0800996 Replace("m=video 9", "m=video 0", message);
997 Replace(kAttributeIceUfragVideo, "", message);
998 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 }
1000}
1001
1002// WebRtcSdpTest
1003
1004class WebRtcSdpTest : public testing::Test {
1005 public:
Steve Antona3a92c22017-12-07 10:27:41 -08001006 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 05:04:57 -08001007#ifdef WEBRTC_ANDROID
1008 webrtc::InitializeAndroidObjects();
1009#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 // AudioContentDescription
1011 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-16 17:54:10 -08001012 StreamParams audio_stream;
1013 audio_stream.id = kAudioTrackId1;
1014 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001015 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001016 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1017 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 11:04:53 -07001018 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1019 audio_desc_->set_connection_address(audio_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001020 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021
1022 // VideoContentDescription
deadbeef9d3584c2016-02-16 17:54:10 -08001023 video_desc_ = CreateVideoContentDescription();
1024 StreamParams video_stream;
1025 video_stream.id = kVideoTrackId1;
1026 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001027 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-16 17:54:10 -08001028 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1029 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1030 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1031 video_stream.ssrc_groups.push_back(ssrc_group);
1032 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 11:04:53 -07001033 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1034 video_desc_->set_connection_address(video_addr);
Steve Anton5adfafd2017-12-20 16:34:00 -08001035 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036
1037 // TransportInfo
Steve Anton06817cd2018-12-18 15:55:30 -08001038 desc_.AddTransportInfo(TransportInfo(
1039 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1040 desc_.AddTransportInfo(TransportInfo(
1041 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042
1043 // v4 host
1044 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001045 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001046 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001047 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1048 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001050 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001051 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1052 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001054 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001058 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001059 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1060 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061
1062 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001063 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001064 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1065 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001066 cricket::LOCAL_PORT_TYPE,
1067 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001069 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1070 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001071 cricket::LOCAL_PORT_TYPE,
1072 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001074 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1075 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001076 cricket::LOCAL_PORT_TYPE,
1077 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001079 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1080 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001081 cricket::LOCAL_PORT_TYPE,
1082 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083
1084 // stun
1085 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1087 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001088 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1089 address_stun, kCandidatePriority, "", "",
1090 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001091 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 candidate9.set_related_address(rel_address_stun);
1093
1094 address_stun.SetPort(port_stun++);
1095 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001096 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1097 address_stun, kCandidatePriority, "", "",
1098 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001099 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 candidate10.set_related_address(rel_address_stun);
1101
1102 // relay
1103 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001104 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001105 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1106 address_relay, kCandidatePriority, "", "",
1107 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001108 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00001110 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1111 address_relay, kCandidatePriority, "", "",
1112 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00001113 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114
1115 // voice
1116 candidates_.push_back(candidate1);
1117 candidates_.push_back(candidate2);
1118 candidates_.push_back(candidate5);
1119 candidates_.push_back(candidate6);
1120 candidates_.push_back(candidate9);
1121 candidates_.push_back(candidate10);
1122
1123 // video
1124 candidates_.push_back(candidate3);
1125 candidates_.push_back(candidate4);
1126 candidates_.push_back(candidate7);
1127 candidates_.push_back(candidate8);
1128 candidates_.push_back(candidate11);
1129 candidates_.push_back(candidate12);
1130
Yves Gerey665174f2018-06-19 15:03:05 +02001131 jcandidate_.reset(
1132 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133
1134 // Set up JsepSessionDescription.
1135 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
1136 std::string mline_id;
1137 int mline_index = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001138 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 // In this test, the audio m line index will be 0, and the video m line
1140 // will be 1.
1141 bool is_video = (i > 5);
1142 mline_id = is_video ? "video_content_name" : "audio_content_name";
1143 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001144 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 jdesc_.AddCandidate(&jice);
1146 }
1147 }
1148
Seth Hampson5b4f0752018-04-02 16:31:36 -07001149 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-12 18:37:36 -08001150 const IceCandidateCollection* video_candidates_collection =
1151 jdesc_.candidates(1);
1152 ASSERT_NE(nullptr, video_candidates_collection);
1153 std::vector<cricket::Candidate> video_candidates;
1154 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1155 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1156 c.set_transport_name("video_content_name");
1157 video_candidates.push_back(c);
1158 }
1159 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001160 }
1161
1162 // Turns the existing reference description into a description using
1163 // a=bundle-only. This means no transport attributes and a 0 port value on
1164 // the m= sections not associated with the BUNDLE-tag.
1165 void MakeBundleOnlyDescription() {
1166 RemoveVideoCandidates();
deadbeef25ed4352016-12-12 18:37:36 -08001167
1168 // And the rest of the transport attributes.
1169 desc_.transport_infos()[1].description.ice_ufrag.clear();
1170 desc_.transport_infos()[1].description.ice_pwd.clear();
1171 desc_.transport_infos()[1].description.connection_role =
1172 cricket::CONNECTIONROLE_NONE;
1173
1174 // Set bundle-only flag.
1175 desc_.contents()[1].bundle_only = true;
1176
1177 // Add BUNDLE group.
1178 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1179 group.AddContentName(kAudioContentName);
1180 group.AddContentName(kVideoContentName);
1181 desc_.AddGroup(group);
1182
1183 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1184 jdesc_.session_version()));
1185 }
1186
deadbeef9d3584c2016-02-16 17:54:10 -08001187 // Turns the existing reference description into a plan B description,
1188 // with 2 audio tracks and 3 video tracks.
1189 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 15:14:30 -08001190 audio_desc_ = audio_desc_->Copy();
1191 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-16 17:54:10 -08001192
1193 StreamParams audio_track_2;
1194 audio_track_2.id = kAudioTrackId2;
1195 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001196 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001197 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1198 audio_desc_->AddStream(audio_track_2);
1199
1200 StreamParams video_track_2;
1201 video_track_2.id = kVideoTrackId2;
1202 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001203 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001204 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1205 video_desc_->AddStream(video_track_2);
1206
1207 StreamParams video_track_3;
1208 video_track_3.id = kVideoTrackId3;
1209 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 11:34:10 -08001210 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-16 17:54:10 -08001211 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1212 video_desc_->AddStream(video_track_3);
1213
1214 desc_.RemoveContentByName(kAudioContentName);
1215 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001216 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1217 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001218
1219 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1220 jdesc_.session_version()));
1221 }
1222
1223 // Turns the existing reference description into a unified plan description,
1224 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001225 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-16 17:54:10 -08001226 // Audio track 2.
1227 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1228 StreamParams audio_track_2;
1229 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001230 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001231 if (use_ssrcs) {
1232 audio_track_2.cname = kStream2Cname;
1233 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1234 }
deadbeef9d3584c2016-02-16 17:54:10 -08001235 audio_desc_2->AddStream(audio_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001236 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001237 desc_.AddTransportInfo(TransportInfo(
1238 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001239 // Video track 2, in stream 2.
1240 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1241 StreamParams video_track_2;
1242 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 11:34:10 -08001243 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001244 if (use_ssrcs) {
1245 video_track_2.cname = kStream2Cname;
1246 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1247 }
deadbeef9d3584c2016-02-16 17:54:10 -08001248 video_desc_2->AddStream(video_track_2);
Steve Anton5adfafd2017-12-20 16:34:00 -08001249 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, video_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001250 desc_.AddTransportInfo(TransportInfo(
1251 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-16 17:54:10 -08001252
1253 // Video track 3, in stream 2.
1254 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1255 StreamParams video_track_3;
1256 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 11:34:10 -08001257 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001258 if (use_ssrcs) {
1259 video_track_3.cname = kStream2Cname;
1260 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1261 }
deadbeef9d3584c2016-02-16 17:54:10 -08001262 video_desc_3->AddStream(video_track_3);
Steve Anton5adfafd2017-12-20 16:34:00 -08001263 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, video_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001264 desc_.AddTransportInfo(TransportInfo(
1265 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 12:22:16 -08001266 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-16 17:54:10 -08001267
1268 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1269 jdesc_.session_version()));
1270 }
1271
1272 // Creates an audio content description with no streams, and some default
1273 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 AudioContentDescription* CreateAudioContentDescription() {
1275 AudioContentDescription* audio = new AudioContentDescription();
1276 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 12:37:51 -08001277 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 15:03:05 +02001278 audio->AddCrypto(CryptoParams(
1279 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1281 "dummy_session_params"));
1282 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 10:07:16 -07001283 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-16 17:54:10 -08001284 audio->AddCodec(opus);
ossue1405ad2017-01-23 08:55:48 -08001285 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1286 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 return audio;
1288 }
1289
Seth Hampson5b4f0752018-04-02 16:31:36 -07001290 // Turns the existing reference description into a unified plan description,
1291 // with 3 audio MediaContentDescriptions with special StreamParams that
1292 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1293 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001294 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001295 desc_.RemoveContentByName(kVideoContentName);
1296 desc_.RemoveTransportInfoByName(kVideoContentName);
1297 RemoveVideoCandidates();
1298
1299 // Audio track 2 has 2 media stream ids.
1300 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1301 StreamParams audio_track_2;
1302 audio_track_2.id = kAudioTrackId2;
1303 audio_track_2.cname = kStream1Cname;
1304 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1305 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1306 audio_desc_2->AddStream(audio_track_2);
1307 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, audio_desc_2);
Steve Anton06817cd2018-12-18 15:55:30 -08001308 desc_.AddTransportInfo(TransportInfo(
1309 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 16:31:36 -07001310
1311 // Audio track 3 has no stream ids.
1312 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1313 StreamParams audio_track_3;
1314 audio_track_3.id = kAudioTrackId3;
1315 audio_track_3.cname = kStream2Cname;
1316 audio_track_3.set_stream_ids({});
1317 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1318 audio_desc_3->AddStream(audio_track_3);
1319 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, audio_desc_3);
Steve Anton06817cd2018-12-18 15:55:30 -08001320 desc_.AddTransportInfo(TransportInfo(
1321 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001322 desc_.set_msid_signaling(msid_signaling);
Seth Hampson5b4f0752018-04-02 16:31:36 -07001323 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1324 jdesc_.session_version()));
1325 }
1326
Seth Hampson5897a6e2018-04-03 11:16:33 -07001327 // Turns the existing reference description into a unified plan description
1328 // with one audio MediaContentDescription that contains one StreamParams with
1329 // 0 ssrcs.
1330 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1331 desc_.RemoveContentByName(kVideoContentName);
1332 desc_.RemoveContentByName(kAudioContentName);
1333 desc_.RemoveTransportInfoByName(kVideoContentName);
1334 RemoveVideoCandidates();
1335
1336 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1337 StreamParams audio_track;
1338 audio_track.id = kAudioTrackId1;
1339 audio_track.set_stream_ids({kStreamId1});
1340 audio_desc->AddStream(audio_track);
1341 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc);
1342
1343 // Enable signaling a=msid lines.
1344 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
1345 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1346 jdesc_.session_version()));
1347 }
1348
deadbeef9d3584c2016-02-16 17:54:10 -08001349 // Creates a video content description with no streams, and some default
1350 // configuration.
1351 VideoContentDescription* CreateVideoContentDescription() {
1352 VideoContentDescription* video = new VideoContentDescription();
1353 video->AddCrypto(CryptoParams(
1354 1, "AES_CM_128_HMAC_SHA1_80",
1355 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1356 video->set_protocol(cricket::kMediaProtocolSavpf);
1357 video->AddCodec(
perkj26752742016-10-24 01:21:16 -07001358 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-16 17:54:10 -08001359 return video;
1360 }
1361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 template <class MCD>
Yves Gerey665174f2018-06-19 15:03:05 +02001363 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 // type
1365 EXPECT_EQ(cd1->type(), cd1->type());
1366
1367 // content direction
1368 EXPECT_EQ(cd1->direction(), cd2->direction());
1369
1370 // rtcp_mux
1371 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1372
deadbeef13871492015-12-09 12:37:51 -08001373 // rtcp_reduced_size
1374 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 // cryptos
1377 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1378 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1379 ADD_FAILURE();
1380 return;
1381 }
Yves Gerey665174f2018-06-19 15:03:05 +02001382 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 const CryptoParams c1 = cd1->cryptos().at(i);
1384 const CryptoParams c2 = cd2->cryptos().at(i);
1385 EXPECT_TRUE(c1.Matches(c2));
1386 EXPECT_EQ(c1.key_params, c2.key_params);
1387 EXPECT_EQ(c1.session_params, c2.session_params);
1388 }
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001391 // Use an equivalence class here, for old and new versions of the
1392 // protocol description.
Yves Gerey665174f2018-06-19 15:03:05 +02001393 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1394 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1395 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:35 +00001396 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 15:03:05 +02001397 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1398 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1399 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:35 +00001400 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:55 +00001401 } else {
1402 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1403 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404
1405 // codecs
1406 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1407
1408 // bandwidth
1409 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1410
1411 // streams
1412 EXPECT_EQ(cd1->streams(), cd2->streams());
1413
Johannes Kron0854eb62018-10-10 22:33:20 +02001414 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 10:17:39 +02001415 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 22:33:20 +02001416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 // extmap
1418 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1419 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 15:03:05 +02001420 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 11:24:55 -07001421 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1422 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 EXPECT_EQ(ext1.uri, ext2.uri);
1424 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 12:31:36 -07001425 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 }
1428
Amit Hilbuchc57d5732018-12-11 15:30:11 -08001429 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1430 const std::vector<std::string>& ids) {
1431 // Order of elements does not matter, only equivalence of sets.
1432 EXPECT_EQ(rids.size(), ids.size());
1433 for (const std::string& id : ids) {
1434 EXPECT_EQ(1l, std::count_if(rids.begin(), rids.end(),
1435 [id](const RidDescription& rid) {
1436 return rid.rid == id;
1437 }));
1438 }
1439 }
1440
Amit Hilbucha2012042018-12-03 11:35:05 -08001441 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1442 const SimulcastDescription& simulcast2) {
1443 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1444 EXPECT_EQ(simulcast1.receive_layers().size(),
1445 simulcast2.receive_layers().size());
1446 }
1447
zstein4b2e0822017-02-17 19:48:38 -08001448 void CompareDataContentDescription(const DataContentDescription* dcd1,
1449 const DataContentDescription* dcd2) {
1450 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1451 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1452 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453
1454 void CompareSessionDescription(const SessionDescription& desc1,
1455 const SessionDescription& desc2) {
1456 // Compare content descriptions.
1457 if (desc1.contents().size() != desc2.contents().size()) {
1458 ADD_FAILURE();
1459 return;
1460 }
Yves Gerey665174f2018-06-19 15:03:05 +02001461 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1463 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-12 18:37:36 -08001464 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-12 18:37:36 -08001466 EXPECT_EQ(c1.type, c2.type);
1467 EXPECT_EQ(c1.rejected, c2.rejected);
1468 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469
1470 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1471 if (IsAudioContent(&c1)) {
1472 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001473 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001475 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1477 }
1478
1479 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1480 if (IsVideoContent(&c1)) {
1481 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001482 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 15:14:30 -08001484 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1486 }
1487
1488 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1489 if (IsDataContent(&c1)) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001490 const DataContentDescription* dcd1 = c1.media_description()->as_data();
1491 const DataContentDescription* dcd2 = c2.media_description()->as_data();
zstein4b2e0822017-02-17 19:48:38 -08001492 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 }
Amit Hilbucha2012042018-12-03 11:35:05 -08001494
1495 CompareSimulcastDescription(
1496 c1.media_description()->simulcast_description(),
1497 c2.media_description()->simulcast_description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 }
1499
1500 // group
1501 const cricket::ContentGroups groups1 = desc1.groups();
1502 const cricket::ContentGroups groups2 = desc2.groups();
1503 EXPECT_EQ(groups1.size(), groups1.size());
1504 if (groups1.size() != groups2.size()) {
1505 ADD_FAILURE();
1506 return;
1507 }
1508 for (size_t i = 0; i < groups1.size(); ++i) {
1509 const cricket::ContentGroup group1 = groups1.at(i);
1510 const cricket::ContentGroup group2 = groups2.at(i);
1511 EXPECT_EQ(group1.semantics(), group2.semantics());
1512 const cricket::ContentNames names1 = group1.content_names();
1513 const cricket::ContentNames names2 = group2.content_names();
1514 EXPECT_EQ(names1.size(), names2.size());
1515 if (names1.size() != names2.size()) {
1516 ADD_FAILURE();
1517 return;
1518 }
1519 cricket::ContentNames::const_iterator iter1 = names1.begin();
1520 cricket::ContentNames::const_iterator iter2 = names2.begin();
1521 while (iter1 != names1.end()) {
1522 EXPECT_EQ(*iter1++, *iter2++);
1523 }
1524 }
1525
1526 // transport info
1527 const cricket::TransportInfos transports1 = desc1.transport_infos();
1528 const cricket::TransportInfos transports2 = desc2.transport_infos();
1529 EXPECT_EQ(transports1.size(), transports2.size());
1530 if (transports1.size() != transports2.size()) {
1531 ADD_FAILURE();
1532 return;
1533 }
1534 for (size_t i = 0; i < transports1.size(); ++i) {
1535 const cricket::TransportInfo transport1 = transports1.at(i);
1536 const cricket::TransportInfo transport2 = transports2.at(i);
1537 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 EXPECT_EQ(transport1.description.ice_ufrag,
1539 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 15:03:05 +02001540 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07001541 EXPECT_EQ(transport1.description.ice_mode,
1542 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 if (transport1.description.identity_fingerprint) {
1544 EXPECT_EQ(*transport1.description.identity_fingerprint,
1545 *transport2.description.identity_fingerprint);
1546 } else {
1547 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1548 transport2.description.identity_fingerprint.get());
1549 }
1550 EXPECT_EQ(transport1.description.transport_options,
1551 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 }
deadbeefc80741f2015-10-22 13:14:45 -07001553
1554 // global attributes
1555 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 10:17:39 +02001556 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 }
1558
Yves Gerey665174f2018-06-19 15:03:05 +02001559 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1560 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1562 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1563 CompareSessionDescription(*desc1.description(), *desc2.description());
1564 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1565 return false;
1566 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1567 const IceCandidateCollection* cc1 = desc1.candidates(i);
1568 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-12 18:37:36 -08001569 if (cc1->count() != cc2->count()) {
1570 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 return false;
deadbeef25ed4352016-12-12 18:37:36 -08001572 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 for (size_t j = 0; j < cc1->count(); ++j) {
1574 const IceCandidateInterface* c1 = cc1->at(j);
1575 const IceCandidateInterface* c2 = cc2->at(j);
1576 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1577 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1578 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1579 }
1580 }
1581 return true;
1582 }
1583
1584 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1585 // them with invalid keywords so that the parser will just ignore them.
1586 bool RemoveCandidateUfragPwd(std::string* sdp) {
1587 const char ice_ufrag[] = "a=ice-ufrag";
1588 const char ice_ufragx[] = "a=xice-ufrag";
1589 const char ice_pwd[] = "a=ice-pwd";
1590 const char ice_pwdx[] = "a=xice-pwd";
Yves Gerey665174f2018-06-19 15:03:05 +02001591 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), ice_ufragx,
1592 strlen(ice_ufragx), sdp);
1593 rtc::replace_substrs(ice_pwd, strlen(ice_pwd), ice_pwdx, strlen(ice_pwdx),
1594 sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 return true;
1596 }
1597
1598 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 15:03:05 +02001599 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1600 int mline_index,
1601 const std::string& ufrag,
1602 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 std::string content_name;
1604 if (mline_index == 0) {
1605 content_name = kAudioContentName;
1606 } else if (mline_index == 1) {
1607 content_name = kVideoContentName;
1608 } else {
nissec80e7412017-01-11 05:56:46 -08001609 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 }
Yves Gerey665174f2018-06-19 15:03:05 +02001611 TransportInfo transport_info(content_name,
1612 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 SessionDescription* desc =
1614 const_cast<SessionDescription*>(jdesc->description());
1615 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 15:55:30 -08001616 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1618 const IceCandidateCollection* cc = jdesc_.candidates(i);
1619 for (size_t j = 0; j < cc->count(); ++j) {
1620 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 15:03:05 +02001621 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1622 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 }
1624 }
1625 }
1626 return true;
1627 }
1628
1629 void AddIceOptions(const std::string& content_name,
1630 const std::vector<std::string>& transport_options) {
1631 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1632 cricket::TransportInfo transport_info =
1633 *(desc_.GetTransportInfoByName(content_name));
1634 desc_.RemoveTransportInfoByName(content_name);
1635 transport_info.description.transport_options = transport_options;
1636 desc_.AddTransportInfo(transport_info);
1637 }
1638
deadbeef3f7219b2015-12-28 15:17:14 -08001639 void SetIceUfragPwd(const std::string& content_name,
1640 const std::string& ice_ufrag,
1641 const std::string& ice_pwd) {
1642 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1643 cricket::TransportInfo transport_info =
1644 *(desc_.GetTransportInfoByName(content_name));
1645 desc_.RemoveTransportInfoByName(content_name);
1646 transport_info.description.ice_ufrag = ice_ufrag;
1647 transport_info.description.ice_pwd = ice_pwd;
1648 desc_.AddTransportInfo(transport_info);
1649 }
1650
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 void AddFingerprint() {
1652 desc_.RemoveTransportInfoByName(kAudioContentName);
1653 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-15 19:27:44 -07001654 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 15:55:30 -08001655 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001656 kAudioContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001657 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1658 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001659 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1660 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 13:24:37 -08001661 kVideoContentName,
deadbeef9d3584c2016-02-16 17:54:10 -08001662 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1663 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 15:55:30 -08001664 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 }
1666
jbauch5869f502017-06-29 12:31:36 -07001667 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001668 audio_desc_ = audio_desc_->Copy();
1669 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 12:31:36 -07001670 audio_desc_->AddRtpHeaderExtension(
1671 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1672 video_desc_->AddRtpHeaderExtension(
1673 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 desc_.RemoveContentByName(kAudioContentName);
1675 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001676 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_desc_);
1677 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 }
1679
1680 void RemoveCryptos() {
1681 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1682 video_desc_->set_cryptos(std::vector<CryptoParams>());
1683 }
1684
Seth Hampson5897a6e2018-04-03 11:16:33 -07001685 // Removes everything in StreamParams from the session description that is
1686 // used for a=ssrc lines.
1687 void RemoveSsrcSignalingFromStreamParams() {
1688 for (cricket::ContentInfo content_info : jdesc_.description()->contents()) {
1689 // With Unified Plan there should be one StreamParams per m= section.
1690 StreamParams& stream =
1691 content_info.media_description()->mutable_streams()[0];
1692 stream.ssrcs.clear();
1693 stream.ssrc_groups.clear();
1694 stream.cname.clear();
1695 }
1696 }
1697
Seth Hampson7fa6ee62018-10-17 10:25:28 -07001698 // Removes all a=ssrc lines from the SDP string, except for the
1699 // "a=ssrc:... cname:..." lines.
1700 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1701 const char kAttributeSsrc[] = "a=ssrc";
1702 const char kAttributeCname[] = "cname";
1703 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1704 while (ssrc_line_pos != std::string::npos) {
1705 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1706 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1707 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1708 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1709 // Only erase a=ssrc lines that don't contain "cname".
1710 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1711 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1712 } else {
1713 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1714 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1715 }
1716 }
1717 }
1718
Seth Hampson5897a6e2018-04-03 11:16:33 -07001719 // Removes all a=ssrc lines from the SDP string.
1720 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1721 const char kAttributeSsrc[] = "a=ssrc";
1722 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1723 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1724 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1725 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1726 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1727 }
1728 }
1729
Steve Anton4e70a722017-11-28 14:57:10 -08001730 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 audio_desc_->set_direction(direction);
1732 video_desc_->set_direction(direction);
1733 std::string new_sdp = kSdpFullString;
1734 ReplaceDirection(direction, &new_sdp);
1735
Yves Gerey665174f2018-06-19 15:03:05 +02001736 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 jdesc_.session_version())) {
1738 return false;
1739 }
Steve Antone831b8c2018-02-01 12:22:16 -08001740 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 EXPECT_EQ(new_sdp, message);
1742 return true;
1743 }
1744
1745 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001746 audio_desc_ = audio_desc_->Copy();
1747 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 11:04:53 -07001748
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 desc_.RemoveContentByName(kAudioContentName);
1750 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001751 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001753 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001755 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1756 audio_rejected ? "" : kPwdVoice);
1757 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1758 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 15:17:14 -08001759
1760 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1762
Steve Antona3a92c22017-12-07 10:27:41 -08001763 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07001764 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08001765 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 EXPECT_EQ(new_sdp, message);
1767 return true;
1768 }
1769
zstein4b2e0822017-02-17 19:48:38 -08001770 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 06:47:29 -07001771 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 data_desc_ = data.get();
zstein4b2e0822017-02-17 19:48:38 -08001773 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 13:02:44 -07001775 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07001776 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:02 +00001777 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1778 data_desc_->AddCodec(codec);
Steve Anton5adfafd2017-12-20 16:34:00 -08001779 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
1780 data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001781 desc_.AddTransportInfo(TransportInfo(
1782 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 }
1784
1785 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 06:47:29 -07001786 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 data_desc_ = data.get();
1788
deadbeef67cf2c12016-04-13 10:07:16 -07001789 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 StreamParams data_stream;
1791 data_stream.id = kDataChannelMsid;
1792 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 11:34:10 -08001793 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 data_stream.ssrcs.push_back(kDataChannelSsrc);
1795 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 15:03:05 +02001796 data_desc_->AddCrypto(
1797 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1798 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Steve Anton5adfafd2017-12-20 16:34:00 -08001800 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp, data.release());
Steve Anton06817cd2018-12-18 15:55:30 -08001801 desc_.AddTransportInfo(TransportInfo(
1802 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 }
1804
Steve Anton4e70a722017-11-28 14:57:10 -08001805 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 std::string new_sdp = kSdpFullString;
1807 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001808 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809
1810 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1811
1812 audio_desc_->set_direction(direction);
1813 video_desc_->set_direction(direction);
Yves Gerey665174f2018-06-19 15:03:05 +02001814 if (!jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 jdesc_.session_version())) {
1816 return false;
1817 }
1818 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1819 return true;
1820 }
1821
1822 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 15:17:14 -08001823 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08001825 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 15:17:14 -08001827
Steve Antonb1c1de12017-12-21 15:14:30 -08001828 audio_desc_ = audio_desc_->Copy();
1829 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 desc_.RemoveContentByName(kAudioContentName);
1831 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-20 16:34:00 -08001832 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 audio_desc_);
Steve Anton5adfafd2017-12-20 16:34:00 -08001834 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 video_desc_);
deadbeef9d3584c2016-02-16 17:54:10 -08001836 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1837 audio_rejected ? "" : kPwdVoice);
1838 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1839 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 10:27:41 -08001840 JsepSessionDescription jdesc_no_candidates(kDummyType);
deadbeef3f7219b2015-12-28 15:17:14 -08001841 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1842 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 return false;
1844 }
deadbeef3f7219b2015-12-28 15:17:14 -08001845 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 return true;
1847 }
1848
Yves Gerey665174f2018-06-19 15:03:05 +02001849 void TestDeserializeExtmap(bool session_level,
1850 bool media_level,
1851 bool encrypted) {
jbauch5869f502017-06-29 12:31:36 -07001852 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08001853 JsepSessionDescription new_jdesc(SdpType::kOffer);
Yves Gerey665174f2018-06-19 15:03:05 +02001854 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 10:27:41 -08001856 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 std::string sdp_with_extmap = kSdpString;
1858 if (session_level) {
jbauch5869f502017-06-29 12:31:36 -07001859 InjectAfter(kSessionTime,
1860 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1861 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 &sdp_with_extmap);
1863 }
1864 if (media_level) {
jbauch5869f502017-06-29 12:31:36 -07001865 InjectAfter(kAttributeIcePwdVoice,
1866 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1867 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 &sdp_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07001869 InjectAfter(kAttributeIcePwdVideo,
1870 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1871 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 &sdp_with_extmap);
1873 }
1874 // The extmap can't be present at the same time in both session level and
1875 // media level.
1876 if (session_level && media_level) {
1877 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02001878 EXPECT_FALSE(
1879 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1881 } else {
1882 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1883 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1884 }
1885 }
1886
1887 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 15:03:05 +02001888 const std::string& name,
1889 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 cricket::CodecParameterMap::const_iterator found = params.find(name);
1891 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001892 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 }
1894
1895 void TestDeserializeCodecParams(const CodecParams& params,
1896 JsepSessionDescription* jdesc_output) {
1897 std::string sdp =
1898 "v=0\r\n"
1899 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1900 "s=-\r\n"
1901 "t=0 0\r\n"
1902 // Include semantics for WebRTC Media Streams since it is supported by
1903 // this parser, and will be added to the SDP when serializing a session
1904 // description.
1905 "a=msid-semantic: WMS\r\n"
1906 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001907 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 // Pltype 111 listed before 103 and 104 in the map.
1909 "a=rtpmap:111 opus/48000/2\r\n"
1910 // Pltype 103 listed before 104.
1911 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001912 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001913 "a=fmtp:111 0-15,66,70\r\n"
1914 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 std::ostringstream os;
Donald Curtis144d0182015-05-15 13:14:24 -07001916 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:15 +00001917 << "; sprop-stereo=" << params.sprop_stereo
1918 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 09:21:23 -07001919 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 << "a=ptime:" << params.ptime << "\r\n"
1921 << "a=maxptime:" << params.max_ptime << "\r\n";
1922 sdp += os.str();
1923
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001924 os.clear();
1925 os.str("");
1926 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001927 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001928 << "a=rtpmap:99 VP8/90000\r\n"
1929 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07001930 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001931 sdp += os.str();
1932
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 // Deserialize
1934 SdpParseError error;
1935 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1936
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001938 GetFirstAudioContentDescription(jdesc_output->description());
1939 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 ASSERT_FALSE(acd->codecs().empty());
1941 cricket::AudioCodec opus = acd->codecs()[0];
1942 EXPECT_EQ("opus", opus.name);
1943 EXPECT_EQ(111, opus.id);
1944 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1945 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1946 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1947 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001948 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1949 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1951 cricket::AudioCodec codec = acd->codecs()[i];
1952 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1953 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 }
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001955
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001956 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001957 GetFirstVideoContentDescription(jdesc_output->description());
1958 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:39 +00001959 ASSERT_FALSE(vcd->codecs().empty());
1960 cricket::VideoCodec vp8 = vcd->codecs()[0];
1961 EXPECT_EQ("VP8", vp8.name);
1962 EXPECT_EQ(99, vp8.id);
1963 cricket::VideoCodec rtx = vcd->codecs()[1];
1964 EXPECT_EQ("RTX", rtx.name);
1965 EXPECT_EQ(95, rtx.id);
1966 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 }
1968
1969 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1970 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001971 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 "v=0\r\n"
1973 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1974 "s=-\r\n"
1975 "t=0 0\r\n"
1976 // Include semantics for WebRTC Media Streams since it is supported by
1977 // this parser, and will be added to the SDP when serializing a session
1978 // description.
1979 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00001980 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001981 "a=rtpmap:111 opus/48000/2\r\n";
1982 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 "m=video 3457 RTP/SAVPF 101\r\n"
1984 "a=rtpmap:101 VP8/90000\r\n"
1985 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001986 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001987 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001989 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 15:03:05 +02001990 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001991 os << sdp_video;
Yves Gerey665174f2018-06-19 15:03:05 +02001992 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:46 +00001993 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 // Deserialize
1995 SdpParseError error;
1996 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08001998 GetFirstAudioContentDescription(jdesc_output->description());
1999 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 ASSERT_FALSE(acd->codecs().empty());
2001 cricket::AudioCodec opus = acd->codecs()[0];
2002 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002003 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2004 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08002007 GetFirstVideoContentDescription(jdesc_output->description());
2008 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 ASSERT_FALSE(vcd->codecs().empty());
2010 cricket::VideoCodec vp8 = vcd->codecs()[0];
2011 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2012 vp8.name.c_str());
2013 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002014 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2015 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2016 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2017 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2018 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2019 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2020 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2021 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 }
2023
2024 // Two SDP messages can mean the same thing but be different strings, e.g.
2025 // some of the lines can be serialized in different order.
2026 // However, a deserialized description can be compared field by field and has
2027 // no order. If deserializer has already been tested, serializing then
2028 // deserializing and comparing JsepSessionDescription will test
2029 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 12:22:16 -08002030 void TestSerialize(const JsepSessionDescription& jdesc) {
2031 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 10:27:41 -08002032 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 SdpParseError error;
2034 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2035 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2036 }
2037
zhihuang38989e52017-03-21 11:04:53 -07002038 // Calling 'Initialize' with a copy of the inner SessionDescription will
2039 // create a copy of the JsepSessionDescription without candidates. The
2040 // 'connection address' field, previously set from the candidates, must also
2041 // be reset.
2042 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2043 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2044 rtc::SocketAddress video_addr("0.0.0.0", 9);
2045 audio_desc_->set_connection_address(audio_addr);
2046 video_desc_->set_connection_address(video_addr);
2047 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2048 }
2049
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 protected:
2051 SessionDescription desc_;
2052 AudioContentDescription* audio_desc_;
2053 VideoContentDescription* video_desc_;
2054 DataContentDescription* data_desc_;
2055 Candidates candidates_;
kwibergd1fe2812016-04-27 06:47:29 -07002056 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 JsepSessionDescription jdesc_;
2058};
2059
2060void TestMismatch(const std::string& string1, const std::string& string2) {
2061 int position = 0;
2062 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2063 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002064 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 break;
2066 }
2067 }
2068 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2069 << " character\n"
2070 << " 1: " << string1.substr(position, 20) << "\n"
2071 << " 2: " << string2.substr(position, 20) << "\n";
2072}
2073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2075 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 12:22:16 -08002076 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 TestMismatch(std::string(kSdpFullString), message);
2078}
2079
2080TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 10:27:41 -08002081 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 12:22:16 -08002082 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083}
2084
2085// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2086// the case in a DTLS offer.
2087TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2088 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002089 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002090 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002091 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
2093 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002094 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2095 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
2097 EXPECT_EQ(sdp_with_fingerprint, message);
2098}
2099
2100// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2101// be the case in a DTLS answer.
2102TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2103 AddFingerprint();
2104 RemoveCryptos();
Steve Antona3a92c22017-12-07 10:27:41 -08002105 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002106 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 12:22:16 -08002107 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 std::string sdp_with_fingerprint = kSdpString;
2110 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2111 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 15:03:05 +02002112 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2113 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 EXPECT_EQ(sdp_with_fingerprint, message);
2116}
2117
2118TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2119 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002120 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002121 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 12:22:16 -08002122 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 EXPECT_EQ(std::string(kSdpString), message);
2124}
2125
2126TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2127 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2128 group.AddContentName(kAudioContentName);
2129 group.AddContentName(kVideoContentName);
2130 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002131 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002133 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 std::string sdp_with_bundle = kSdpFullString;
2135 InjectAfter(kSessionTime,
2136 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2137 &sdp_with_bundle);
2138 EXPECT_EQ(sdp_with_bundle, message);
2139}
2140
2141TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 15:14:30 -08002142 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002144 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002146 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002148 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002150 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002152 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 &sdp_with_bandwidth);
2154 EXPECT_EQ(sdp_with_bandwidth, message);
2155}
2156
2157TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2158 std::vector<std::string> transport_options;
2159 transport_options.push_back(kIceOption1);
2160 transport_options.push_back(kIceOption3);
2161 AddIceOptions(kAudioContentName, transport_options);
2162 transport_options.clear();
2163 transport_options.push_back(kIceOption2);
2164 transport_options.push_back(kIceOption3);
2165 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002166 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08002168 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002170 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002172 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 &sdp_with_ice_options);
2174 EXPECT_EQ(sdp_with_ice_options, message);
2175}
2176
2177TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002178 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179}
2180
2181TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002182 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183}
2184
2185TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002186 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187}
2188
2189TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2190 EXPECT_TRUE(TestSerializeRejected(true, false));
2191}
2192
2193TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2194 EXPECT_TRUE(TestSerializeRejected(false, true));
2195}
2196
2197TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2198 EXPECT_TRUE(TestSerializeRejected(true, true));
2199}
2200
2201TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2202 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002203 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204
zhihuang38989e52017-03-21 11:04:53 -07002205 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002206 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207
2208 std::string expected_sdp = kSdpString;
2209 expected_sdp.append(kSdpRtpDataChannelString);
2210 EXPECT_EQ(expected_sdp, message);
2211}
2212
2213TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-17 19:48:38 -08002214 bool use_sctpmap = true;
2215 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002216 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
zhihuang38989e52017-03-21 11:04:53 -07002218 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002219 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220
2221 std::string expected_sdp = kSdpString;
2222 expected_sdp.append(kSdpSctpDataChannelString);
2223 EXPECT_EQ(message, expected_sdp);
2224}
2225
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002226TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-17 19:48:38 -08002227 bool use_sctpmap = true;
2228 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002229 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002230 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antonb1c1de12017-12-21 15:14:30 -08002231 DataContentDescription* dcdesc =
2232 jsep_desc.description()
2233 ->GetContentDescriptionByName(kDataContentName)
2234 ->as_data();
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002235
2236 const int kNewPort = 1234;
solenberg9fa49752016-10-08 13:02:44 -07002237 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 10:07:16 -07002238 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002239 codec.SetParam(cricket::kCodecParamPort, kNewPort);
2240 dcdesc->AddOrReplaceCodec(codec);
2241
Steve Antone831b8c2018-02-01 12:22:16 -08002242 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002243
2244 std::string expected_sdp = kSdpString;
2245 expected_sdp.append(kSdpSctpDataChannelString);
2246
2247 char default_portstr[16];
2248 char new_portstr[16];
Niels Mölleraba06332018-10-16 15:14:15 +02002249 snprintf(default_portstr, sizeof(default_portstr), "%d", kDefaultSctpPort);
2250 snprintf(new_portstr, sizeof(new_portstr), "%d", kNewPort);
Yves Gerey665174f2018-06-19 15:03:05 +02002251 rtc::replace_substrs(default_portstr, strlen(default_portstr), new_portstr,
2252 strlen(new_portstr), &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002253
2254 EXPECT_EQ(expected_sdp, message);
2255}
2256
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002257TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002258 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002259 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 15:03:05 +02002260 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 11:04:53 -07002261 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 12:22:16 -08002262 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002263
2264 std::string expected_sdp = kSdpString;
2265 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002266 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:06 +00002267 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02002268 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002269 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002270}
2271
Johannes Kron0854eb62018-10-10 22:33:20 +02002272TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002273 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002274 TestSerialize(jdesc_);
2275}
2276
2277TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2278 cricket::MediaContentDescription* video_desc =
2279 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2280 ASSERT_TRUE(video_desc);
2281 cricket::MediaContentDescription* audio_desc =
2282 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2283 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002284 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002285 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002286 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002287 cricket::MediaContentDescription::kMedia);
2288 TestSerialize(jdesc_);
2289}
2290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 12:31:36 -07002292 bool encrypted = false;
2293 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002294 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07002295 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 12:22:16 -08002296 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297
2298 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 15:03:05 +02002299 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2300 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301
2302 EXPECT_EQ(sdp_with_extmap, message);
2303}
2304
jbauch5869f502017-06-29 12:31:36 -07002305TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2306 bool encrypted = true;
2307 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 10:27:41 -08002308 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002309 ASSERT_TRUE(
2310 desc_with_extmap.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 12:22:16 -08002311 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 12:31:36 -07002312}
2313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314TEST_F(WebRtcSdpTest, SerializeCandidates) {
2315 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:10 +00002316 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-16 18:37:23 -08002317
2318 Candidate candidate_with_ufrag(candidates_.front());
2319 candidate_with_ufrag.set_username("ABC");
2320 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2321 candidate_with_ufrag));
2322 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2323 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 16:07:48 -07002324
2325 Candidate candidate_with_network_info(candidates_.front());
2326 candidate_with_network_info.set_network_id(1);
2327 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2328 candidate_with_network_info));
2329 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2330 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2331 candidate_with_network_info.set_network_cost(999);
2332 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2333 candidate_with_network_info));
2334 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2335 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2336 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337}
2338
Zach Steinb336c272018-08-09 01:16:13 -07002339TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2340 rtc::SocketAddress address("a.test", 1234);
2341 cricket::Candidate candidate(
2342 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2343 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2344 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2345 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2346 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2347}
2348
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002349// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2350// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:55 +00002351TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002352 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002353 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2354 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2355 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002356 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 06:47:29 -07002357 std::unique_ptr<IceCandidateInterface> jcandidate(
2358 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002359
2360 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2361 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2362}
2363
htaa6b99442016-04-12 10:29:17 -07002364TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 01:34:11 -08002365 cricket::VideoCodec h264_codec("H264");
2366 h264_codec.SetParam("profile-level-id", "42e01f");
2367 h264_codec.SetParam("level-asymmetry-allowed", "1");
2368 h264_codec.SetParam("packetization-mode", "1");
2369 video_desc_->AddCodec(h264_codec);
2370
htaa6b99442016-04-12 10:29:17 -07002371 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2372
Steve Antone831b8c2018-02-01 12:22:16 -08002373 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 10:29:17 -07002374 size_t after_pt = message.find(" H264/90000");
2375 ASSERT_NE(after_pt, std::string::npos);
2376 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2377 ASSERT_NE(before_pt, std::string::npos);
2378 before_pt += strlen("a=rtpmap:");
2379 std::string pt = message.substr(before_pt, after_pt - before_pt);
2380 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2381 std::string to_find = "a=fmtp:" + pt + " ";
2382 size_t fmtp_pos = message.find(to_find);
2383 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 11:43:52 +01002384 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 10:29:17 -07002385 ASSERT_NE(std::string::npos, fmtp_endpos);
2386 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2387 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2388 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2389 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 11:02:14 -07002390 // Check that there are no spaces after semicolons.
2391 // https://bugs.webrtc.org/5793
2392 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 10:29:17 -07002393}
2394
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 10:27:41 -08002396 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 // Deserialize
2398 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2399 // Verify
2400 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2401}
2402
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002403TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 10:27:41 -08002404 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002405 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 15:03:05 +02002406 "v=0\r\n"
2407 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2408 "s=-\r\n"
2409 "t=0 0\r\n"
2410 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002411 // Deserialize
2412 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2413 EXPECT_EQ(0u, jdesc.description()->contents().size());
2414}
2415
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 10:27:41 -08002417 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 std::string sdp_without_carriage_return = kSdpFullString;
2419 Replace("\r\n", "\n", &sdp_without_carriage_return);
2420 // Deserialize
2421 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2422 // Verify
2423 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2424}
2425
2426TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2427 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 10:27:41 -08002428 JsepSessionDescription jdesc_no_candidates(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002429 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
2430 kSessionVersion));
Steve Antona3a92c22017-12-07 10:27:41 -08002431 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2433 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2434}
2435
2436TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2437 static const char kSdpNoRtpmapString[] =
2438 "v=0\r\n"
2439 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2440 "s=-\r\n"
2441 "t=0 0\r\n"
2442 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2443 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002444 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 // The rtpmap line for static payload codec is optional.
2446 "a=rtpmap:18 G729/16000\r\n"
2447 "a=rtpmap:103 ISAC/16000\r\n";
2448
Steve Antona3a92c22017-12-07 10:27:41 -08002449 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2451 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002452 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 10:07:16 -07002454 // The codecs in the AudioContentDescription should be in the same order as
2455 // the payload types (<fmt>s) on the m= line.
2456 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2457 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 08:55:48 -08002458 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 EXPECT_EQ(ref_codecs, audio->codecs());
2460}
2461
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002462TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2463 static const char kSdpNoRtpmapString[] =
2464 "v=0\r\n"
2465 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2466 "s=-\r\n"
2467 "t=0 0\r\n"
2468 "m=audio 49232 RTP/AVP 18 103\r\n"
2469 "a=fmtp:18 annexb=yes\r\n"
2470 "a=rtpmap:103 ISAC/16000\r\n";
2471
Steve Antona3a92c22017-12-07 10:27:41 -08002472 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002473 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2474 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08002475 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002476
2477 cricket::AudioCodec g729 = audio->codecs()[0];
2478 EXPECT_EQ("G729", g729.name);
2479 EXPECT_EQ(8000, g729.clockrate);
2480 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 15:03:05 +02002481 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002482 ASSERT_TRUE(found != g729.params.end());
2483 EXPECT_EQ(found->second, "yes");
2484
2485 cricket::AudioCodec isac = audio->codecs()[1];
2486 EXPECT_EQ("ISAC", isac.name);
2487 EXPECT_EQ(103, isac.id);
2488 EXPECT_EQ(16000, isac.clockrate);
2489}
2490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491// Ensure that we can deserialize SDP with a=fingerprint properly.
2492TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2493 // Add a DTLS a=fingerprint attribute to our session description.
2494 AddFingerprint();
Steve Antona3a92c22017-12-07 10:27:41 -08002495 JsepSessionDescription new_jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02002496 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 jdesc_.session_version()));
2498
Steve Antona3a92c22017-12-07 10:27:41 -08002499 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 std::string sdp_with_fingerprint = kSdpString;
2501 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2502 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2503 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2504 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2505}
2506
2507TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 10:27:41 -08002508 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 std::string sdp_with_bundle = kSdpFullString;
2510 InjectAfter(kSessionTime,
2511 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2512 &sdp_with_bundle);
2513 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2514 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2515 group.AddContentName(kAudioContentName);
2516 group.AddContentName(kVideoContentName);
2517 desc_.AddGroup(group);
Yves Gerey665174f2018-06-19 15:03:05 +02002518 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 jdesc_.session_version()));
2520 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2521}
2522
2523TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 10:27:41 -08002524 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002526 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002528 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 15:03:05 +02002530 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 15:14:30 -08002531 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 15:14:30 -08002533 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 acd->set_bandwidth(50 * 1000);
Yves Gerey665174f2018-06-19 15:03:05 +02002535 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 jdesc_.session_version()));
2537 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2538}
2539
2540TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 10:27:41 -08002541 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02002543 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002545 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002547 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 &sdp_with_ice_options);
2549 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2550 std::vector<std::string> transport_options;
2551 transport_options.push_back(kIceOption3);
2552 transport_options.push_back(kIceOption1);
2553 AddIceOptions(kAudioContentName, transport_options);
2554 transport_options.clear();
2555 transport_options.push_back(kIceOption3);
2556 transport_options.push_back(kIceOption2);
2557 AddIceOptions(kVideoContentName, transport_options);
Yves Gerey665174f2018-06-19 15:03:05 +02002558 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 jdesc_.session_version()));
2560 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2561}
2562
2563TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2564 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 10:27:41 -08002565 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 std::string sdp_with_ufrag_pwd = kSdpFullString;
2567 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2568 // Add session level ufrag and pwd
2569 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 15:03:05 +02002570 "a=ice-pwd:session+level+icepwd\r\n"
2571 "a=ice-ufrag:session+level+iceufrag\r\n",
2572 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 15:03:05 +02002574 InjectAfter(
2575 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2577 &sdp_with_ufrag_pwd);
2578 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 15:03:05 +02002579 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2580 "media+level+icepwd"));
2581 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2582 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2584 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2585}
2586
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002588 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589}
2590
2591TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002592 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593}
2594
2595TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 14:57:10 -08002596 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597}
2598
2599TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2600 EXPECT_TRUE(TestDeserializeRejected(true, false));
2601}
2602
2603TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2604 EXPECT_TRUE(TestDeserializeRejected(false, true));
2605}
2606
2607TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2608 EXPECT_TRUE(TestDeserializeRejected(true, true));
2609}
2610
2611// Tests that we can still handle the sdp uses mslabel and label instead of
2612// msid for backward compatibility.
2613TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 13:14:45 -07002614 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 10:27:41 -08002615 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 std::string sdp_without_msid = kSdpFullString;
2617 Replace("msid", "xmsid", &sdp_without_msid);
2618 // Deserialize
2619 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2620 // Verify
2621 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 11:25:05 +01002622 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2623 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624}
2625
Johannes Kron0854eb62018-10-10 22:33:20 +02002626TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002627 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 22:33:20 +02002628 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2629 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2630 // Deserialize
2631 JsepSessionDescription jdesc_deserialized(kDummyType);
2632 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2633 // Verify
2634 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2635}
2636
2637TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 10:17:39 +02002638 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 22:33:20 +02002639 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2640 // Deserialize
2641 JsepSessionDescription jdesc_deserialized(kDummyType);
2642 EXPECT_TRUE(
2643 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2644 // Verify
2645 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2646}
2647
2648TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2649 cricket::MediaContentDescription* video_desc =
2650 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2651 ASSERT_TRUE(video_desc);
2652 cricket::MediaContentDescription* audio_desc =
2653 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2654 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 10:17:39 +02002655 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002656 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 10:17:39 +02002657 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 22:33:20 +02002658 cricket::MediaContentDescription::kMedia);
2659
2660 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2661 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2662 &sdp_with_extmap_allow_mixed);
2663 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2664 &sdp_with_extmap_allow_mixed);
2665
2666 // Deserialize
2667 JsepSessionDescription jdesc_deserialized(kDummyType);
2668 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2669 // Verify
2670 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2671}
2672
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2674 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2675
2676 std::string sdp = kSdpOneCandidate;
2677 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2678 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2679 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2680 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 16:07:48 -07002681 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682
2683 // Candidate line without generation extension.
2684 sdp = kSdpOneCandidate;
2685 Replace(" generation 2", "", &sdp);
2686 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2687 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2688 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2689 Candidate expected = jcandidate_->candidate();
2690 expected.set_generation(0);
2691 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2692
honghaiza0c44ea2016-03-23 16:07:48 -07002693 // Candidate with network id and/or cost.
2694 sdp = kSdpOneCandidate;
2695 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2696 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2697 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2698 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2699 expected = jcandidate_->candidate();
2700 expected.set_network_id(2);
2701 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2702 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2703 // Add network cost
2704 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2705 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2706 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2707 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2708
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002709 sdp = kSdpTcpActiveCandidate;
2710 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2711 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:07 +00002712 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:31 +00002713 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2714 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2715 kCandidateFoundation1);
kwibergd1fe2812016-04-27 06:47:29 -07002716 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2717 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 15:03:05 +02002718 EXPECT_TRUE(
2719 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20 +00002720 sdp = kSdpTcpPassiveCandidate;
2721 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2722 sdp = kSdpTcpSOCandidate;
2723 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724}
2725
2726// This test verifies the deserialization of candidate-attribute
2727// as per RFC 5245. Candiate-attribute will be of the format
2728// candidate:<blah>. This format will be used when candidates
2729// are trickled.
2730TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2731 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2732
2733 std::string candidate_attribute = kRawCandidate;
2734 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2735 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2736 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2737 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2738 EXPECT_EQ(2u, jcandidate.candidate().generation());
2739
2740 // Candidate line without generation extension.
2741 candidate_attribute = kRawCandidate;
2742 Replace(" generation 2", "", &candidate_attribute);
2743 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2744 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2745 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2746 Candidate expected = jcandidate_->candidate();
2747 expected.set_generation(0);
2748 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2749
2750 // Candidate line without candidate:
2751 candidate_attribute = kRawCandidate;
2752 Replace("candidate:", "", &candidate_attribute);
2753 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2754
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002755 // Candidate line with IPV6 address.
2756 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 01:16:13 -07002757
2758 // Candidate line with hostname address.
2759 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002760}
2761
2762// This test verifies that the deserialization of an invalid candidate string
2763// fails.
2764TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 15:03:05 +02002765 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002766
2767 std::string candidate_attribute = kRawCandidate;
2768 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15 +00002770
2771 candidate_attribute = kSdpOneCandidate;
2772 candidate_attribute.replace(0, 1, "x");
2773 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2774
2775 candidate_attribute = kRawCandidate;
2776 candidate_attribute.append("\r\n");
2777 candidate_attribute.append(kRawCandidate);
2778 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2779
2780 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781}
2782
2783TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2784 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 10:27:41 -08002785 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2787
2788 std::string sdp_with_data = kSdpString;
2789 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002790 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791
2792 // Deserialize
2793 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2794 // Verify
2795 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2796}
2797
2798TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-17 19:48:38 -08002799 bool use_sctpmap = true;
2800 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002801 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2803
2804 std::string sdp_with_data = kSdpString;
2805 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 10:27:41 -08002806 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807
lally@webrtc.org36300852015-02-24 20:19:35 +00002808 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2809 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2810 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2811
2812 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002813 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2814 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002815 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2816 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2817
2818 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002819 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2820 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2822 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2823}
2824
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002825TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002826 bool use_sctpmap = false;
2827 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002828 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002829 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2830
2831 std::string sdp_with_data = kSdpString;
2832 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002833 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002834
lally@webrtc.org36300852015-02-24 20:19:35 +00002835 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002836 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2837 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002838
lally@webrtc.org36300852015-02-24 20:19:35 +00002839 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002840 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2841 kUdpDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:35 +00002842 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2843 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002844
lally@webrtc.org36300852015-02-24 20:19:35 +00002845 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002846 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2847 kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:26 +00002848 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2849 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2850}
2851
lally69f57602015-10-08 10:15:04 -07002852TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-17 19:48:38 -08002853 bool use_sctpmap = false;
2854 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002855 JsepSessionDescription jdesc(kDummyType);
lally69f57602015-10-08 10:15:04 -07002856 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2857
2858 std::string sdp_with_data = kSdpString;
2859 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 10:27:41 -08002860 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 10:15:04 -07002861
2862 // Verify with DTLS/SCTP.
2863 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2864 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2865
2866 // Verify with UDP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002867 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
2868 kUdpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002869 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2870 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2871
2872 // Verify with TCP/DTLS/SCTP.
Yves Gerey665174f2018-06-19 15:03:05 +02002873 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2874 kTcpDtlsSctp);
lally69f57602015-10-08 10:15:04 -07002875 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2876 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2877}
2878
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002879// Test to check the behaviour if sctp-port is specified
2880// on the m= line and in a=sctp-port.
2881TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-17 19:48:38 -08002882 bool use_sctpmap = true;
2883 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002884 JsepSessionDescription jdesc(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002885 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2886
2887 std::string sdp_with_data = kSdpString;
2888 // Append m= attributes
2889 sdp_with_data.append(kSdpSctpDataChannelString);
2890 // Append a=sctp-port attribute
2891 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 10:27:41 -08002892 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002893
2894 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2895}
2896
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002897// For crbug/344475.
2898TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2899 std::string sdp_with_data = kSdpString;
2900 sdp_with_data.append(kSdpSctpDataChannelString);
2901 // Remove the "\n" at the end.
2902 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 10:27:41 -08002903 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:26 +00002904
2905 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2906 // No crash is a pass.
2907}
2908
Steve Anton36b29d12017-10-30 09:57:42 -07002909void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-17 19:48:38 -08002910 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:02 +00002911 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-17 19:48:38 -08002912 cricket::SessionDescription* mutant = desc.Copy();
Steve Antonb1c1de12017-12-21 15:14:30 -08002913 DataContentDescription* dcdesc =
2914 mutant->GetContentDescriptionByName(kDataContentName)->as_data();
wu@webrtc.org78187522013-10-07 23:32:02 +00002915 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:22 +00002916 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 13:02:44 -07002917 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:02 +00002918 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002919 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:02 +00002920
2921 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 09:57:42 -07002922 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:02 +00002923 mutant = NULL;
zstein4b2e0822017-02-17 19:48:38 -08002924}
2925
2926TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2927 bool use_sctpmap = true;
2928 AddSctpDataChannel(use_sctpmap);
2929
2930 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 10:27:41 -08002931 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002932 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:02 +00002933
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002934 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:02 +00002935 std::string sdp_with_data = kSdpString;
2936 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-17 19:48:38 -08002937 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2938 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2939 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002940 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:02 +00002941
2942 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2943 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-17 19:48:38 -08002944}
2945
2946TEST_F(WebRtcSdpTest,
2947 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2948 bool use_sctpmap = false;
2949 AddSctpDataChannel(use_sctpmap);
2950
Steve Antona3a92c22017-12-07 10:27:41 -08002951 JsepSessionDescription jdesc(kDummyType);
Steve Anton36b29d12017-10-30 09:57:42 -07002952 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002953
2954 // We need to test the deserialized JsepSessionDescription from
2955 // kSdpSctpDataChannelStringWithSctpPort for
2956 // draft-ietf-mmusic-sctp-sdp-07
2957 // a=sctp-port
zstein4b2e0822017-02-17 19:48:38 -08002958 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002959 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-17 19:48:38 -08002960 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2961 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2962 &sdp_with_data);
Steve Antona3a92c22017-12-07 10:27:41 -08002963 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56 +00002964
2965 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2966 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:02 +00002967}
2968
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002969TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002970 // We want to test that deserializing data content limits bandwidth
2971 // settings (it should never be greater than the default).
2972 // This should prevent someone from using unlimited data bandwidth through
2973 // JS and "breaking the Internet".
2974 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002975 std::string sdp_with_bandwidth = kSdpString;
2976 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002977 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002978 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002979 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002980
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002981 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2982}
2983
2984TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-17 19:48:38 -08002985 bool use_sctpmap = true;
2986 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 10:27:41 -08002987 JsepSessionDescription jdesc(kDummyType);
Steve Antonb1c1de12017-12-21 15:14:30 -08002988 DataContentDescription* dcd = GetFirstDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002989 dcd->set_bandwidth(100 * 1000);
2990 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2991
2992 std::string sdp_with_bandwidth = kSdpString;
2993 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 15:03:05 +02002994 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002995 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 10:27:41 -08002996 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 15:31:25 -07002997
2998 // SCTP has congestion control, so we shouldn't limit the bandwidth
2999 // as we do for RTP.
3000 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00003001 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3002}
3003
Yves Gerey665174f2018-06-19 15:03:05 +02003004class WebRtcSdpExtmapTest : public WebRtcSdpTest,
3005 public testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 12:31:36 -07003006
3007TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 15:03:05 +02003008 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003009 bool encrypted = GetParam();
3010 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011}
3012
Yves Gerey665174f2018-06-19 15:03:05 +02003013TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003014 bool encrypted = GetParam();
3015 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016}
3017
Yves Gerey665174f2018-06-19 15:03:05 +02003018TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 12:31:36 -07003019 bool encrypted = GetParam();
3020 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021}
3022
jbauch5869f502017-06-29 12:31:36 -07003023INSTANTIATE_TEST_CASE_P(Encrypted,
3024 WebRtcSdpExtmapTest,
3025 ::testing::Values(false, true));
3026
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003027TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 10:27:41 -08003028 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003029 std::string sdp = kSdpFullString;
3030 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3031 // Deserialize
3032 SdpParseError error;
3033 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-16 17:54:10 -08003034 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00003035 EXPECT_EQ(lastline, error.line);
3036 EXPECT_EQ("Invalid SDP line.", error.description);
3037}
3038
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003039TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3040 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3041 std::string new_sdp = kSdpOneCandidate;
3042 Replace("udp", "unsupported_transport", &new_sdp);
3043 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3044 new_sdp = kSdpOneCandidate;
3045 Replace("udp", "uDP", &new_sdp);
3046 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3047 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3048 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3049 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3050}
3051
honghaiza54a0802015-12-16 18:37:23 -08003052TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-16 18:37:23 -08003054 EXPECT_TRUE(
3055 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3057 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3058 Candidate ref_candidate = jcandidate_->candidate();
3059 ref_candidate.set_username("user_rtp");
3060 ref_candidate.set_password("password_rtp");
3061 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3062}
3063
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003064TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003065 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003066
3067 // Deserialize
3068 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3069
3070 // Verify
3071 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003072 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003073 EXPECT_TRUE(audio->conference_mode());
3074
3075 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003076 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00003077 EXPECT_TRUE(video->conference_mode());
3078}
3079
deadbeefd45aea82017-09-16 01:24:29 -07003080TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 10:27:41 -08003081 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 01:24:29 -07003082
3083 // We tested deserialization already above, so just test that if we serialize
3084 // and deserialize the flag doesn't disappear.
3085 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 12:22:16 -08003086 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 01:24:29 -07003087 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3088
3089 // Verify.
3090 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 15:55:30 -08003091 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003092 EXPECT_TRUE(audio->conference_mode());
3093
3094 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 15:55:30 -08003095 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 01:24:29 -07003096 EXPECT_TRUE(video->conference_mode());
3097}
3098
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3100 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003101 const char kSdpEmptyType[] = " =candidate";
3102 const char kSdpEqualAsPlus[] = "a+candidate";
3103 const char kSdpSpaceAfterEqual[] = "a= candidate";
3104 const char kSdpUpperType[] = "A=candidate";
3105 const char kSdpEmptyLine[] = "";
3106 const char kSdpMissingValue[] = "a=";
3107
Yves Gerey665174f2018-06-19 15:03:05 +02003108 const char kSdpBrokenFingerprint[] =
3109 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003110 "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 +02003111 const char kSdpExtraField[] =
3112 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113 "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 +02003114 const char kSdpMissingSpace[] =
3115 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003116 "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 +00003117 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 15:03:05 +02003118 const char kSdpMd5[] =
3119 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003120 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121
3122 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003123 ExpectParseFailure("v=", kSdpDestroyer);
3124 ExpectParseFailure("o=", kSdpDestroyer);
3125 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003127 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128
3129 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003130 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3131 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003132
3133 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003134 ExpectParseFailure("a=candidate", kSdpEmptyType);
3135 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3136 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3137 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003138
3139 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3140 // because it's orthogonal to what we are replacing and hence
3141 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:51 +00003142 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3143 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3144 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3145 ExpectParseFailure("a=sendrecv", kSdpMd5);
3146
3147 // Empty Line
3148 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3149 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003150}
3151
3152TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3153 // ssrc
3154 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-16 17:54:10 -08003155 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003156 // crypto
3157 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3158 // rtpmap
3159 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3160 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3161 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3162 // candidate
3163 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3164 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3165 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3166 ExpectParseFailure("rport 2346", "rport badvalue");
3167 ExpectParseFailure("rport 2346 generation 2",
3168 "rport 2346 generation badvalue");
3169 // m line
3170 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3171 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3172
3173 // bandwidth
3174 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003175 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:09 +00003176 // rtcp-fb
3177 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3178 "a=rtcp-fb:badvalue nack\r\n",
3179 "a=rtcp-fb:badvalue nack");
3180 // extmap
3181 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3182 "a=extmap:badvalue http://example.com\r\n",
3183 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184}
3185
3186TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 10:27:41 -08003187 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188
3189 const char kSdpWithReorderedPlTypesString[] =
3190 "v=0\r\n"
3191 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3192 "s=-\r\n"
3193 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22 +00003194 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 15:03:05 +02003195 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3196 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003198 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199
3200 // Deserialize
3201 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003204 GetFirstAudioContentDescription(jdesc_output.description());
3205 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00003207 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3208 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209 EXPECT_EQ(104, acd->codecs()[0].id);
3210}
3211
3212TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 10:27:41 -08003213 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214 CodecParams params;
3215 params.max_ptime = 40;
3216 params.ptime = 30;
3217 params.min_ptime = 10;
3218 params.sprop_stereo = 1;
3219 params.stereo = 1;
3220 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003221 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 12:22:16 -08003223 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224}
3225
3226TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3227 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 10:27:41 -08003228 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003230 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231}
3232
3233TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3234 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 10:27:41 -08003235 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 12:22:16 -08003237 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238}
3239
3240TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 10:27:41 -08003241 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
3243 const char kSdpWithFmtpString[] =
3244 "v=0\r\n"
3245 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3246 "s=-\r\n"
3247 "t=0 0\r\n"
3248 "m=video 3457 RTP/SAVPF 120\r\n"
3249 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 09:21:23 -07003250 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3251
3252 // Deserialize
3253 SdpParseError error;
Donald Curtis144d0182015-05-15 13:14:24 -07003254 EXPECT_TRUE(
3255 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 09:21:23 -07003256
Donald Curtis0e07f922015-05-15 09:21:23 -07003257 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003258 GetFirstVideoContentDescription(jdesc_output.description());
3259 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 09:21:23 -07003260 ASSERT_FALSE(vcd->codecs().empty());
3261 cricket::VideoCodec vp8 = vcd->codecs()[0];
3262 EXPECT_EQ("VP8", vp8.name);
3263 EXPECT_EQ(120, vp8.id);
3264 cricket::CodecParameterMap::iterator found =
3265 vp8.params.find("x-google-min-bitrate");
3266 ASSERT_TRUE(found != vp8.params.end());
3267 EXPECT_EQ(found->second, "10");
3268 found = vp8.params.find("x-google-max-quantization");
3269 ASSERT_TRUE(found != vp8.params.end());
3270 EXPECT_EQ(found->second, "40");
3271}
3272
johan2d8d23e2016-06-03 01:22:42 -07003273TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 10:27:41 -08003274 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 01:22:42 -07003275
3276 const char kSdpWithFmtpString[] =
3277 "v=0\r\n"
3278 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3279 "s=-\r\n"
3280 "t=0 0\r\n"
3281 "m=video 49170 RTP/AVP 98\r\n"
3282 "a=rtpmap:98 H264/90000\r\n"
3283 "a=fmtp:98 profile-level-id=42A01E; "
3284 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3285
3286 // Deserialize.
3287 SdpParseError error;
3288 EXPECT_TRUE(
3289 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3290
johan2d8d23e2016-06-03 01:22:42 -07003291 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003292 GetFirstVideoContentDescription(jdesc_output.description());
3293 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 01:22:42 -07003294 ASSERT_FALSE(vcd->codecs().empty());
3295 cricket::VideoCodec h264 = vcd->codecs()[0];
3296 EXPECT_EQ("H264", h264.name);
3297 EXPECT_EQ(98, h264.id);
3298 cricket::CodecParameterMap::const_iterator found =
3299 h264.params.find("profile-level-id");
3300 ASSERT_TRUE(found != h264.params.end());
3301 EXPECT_EQ(found->second, "42A01E");
3302 found = h264.params.find("sprop-parameter-sets");
3303 ASSERT_TRUE(found != h264.params.end());
3304 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3305}
3306
Donald Curtis0e07f922015-05-15 09:21:23 -07003307TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 10:27:41 -08003308 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 09:21:23 -07003309
3310 const char kSdpWithFmtpString[] =
3311 "v=0\r\n"
3312 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3313 "s=-\r\n"
3314 "t=0 0\r\n"
3315 "m=video 3457 RTP/SAVPF 120\r\n"
3316 "a=rtpmap:120 VP8/90000\r\n"
3317 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318
3319 // Deserialize
3320 SdpParseError error;
Yves Gerey665174f2018-06-19 15:03:05 +02003321 EXPECT_TRUE(
3322 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003325 GetFirstVideoContentDescription(jdesc_output.description());
3326 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 ASSERT_FALSE(vcd->codecs().empty());
3328 cricket::VideoCodec vp8 = vcd->codecs()[0];
3329 EXPECT_EQ("VP8", vp8.name);
3330 EXPECT_EQ(120, vp8.id);
3331 cricket::CodecParameterMap::iterator found =
3332 vp8.params.find("x-google-min-bitrate");
3333 ASSERT_TRUE(found != vp8.params.end());
3334 EXPECT_EQ(found->second, "10");
3335 found = vp8.params.find("x-google-max-quantization");
3336 ASSERT_TRUE(found != vp8.params.end());
3337 EXPECT_EQ(found->second, "40");
3338}
3339
ossuaa4b0772017-01-30 07:41:18 -08003340TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003341 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003342
3343 cricket::AudioCodecs codecs = acd->codecs();
3344 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3345 acd->set_codecs(codecs);
3346
Yves Gerey665174f2018-06-19 15:03:05 +02003347 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003348 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003349 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003350 std::string sdp_with_fmtp = kSdpFullString;
3351 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3352 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3353 &sdp_with_fmtp);
3354 EXPECT_EQ(sdp_with_fmtp, message);
3355}
3356
3357TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003358 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003359
3360 cricket::AudioCodecs codecs = acd->codecs();
3361 codecs[0].params["stereo"] = "1";
3362 acd->set_codecs(codecs);
3363
Yves Gerey665174f2018-06-19 15:03:05 +02003364 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003365 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003366 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003367 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003368 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 07:41:18 -08003369 &sdp_with_fmtp);
3370 EXPECT_EQ(sdp_with_fmtp, message);
3371}
3372
3373TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003374 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 07:41:18 -08003375
3376 cricket::AudioCodecs codecs = acd->codecs();
3377 codecs[0].params["ptime"] = "20";
3378 codecs[0].params["maxptime"] = "120";
3379 acd->set_codecs(codecs);
3380
Yves Gerey665174f2018-06-19 15:03:05 +02003381 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
ossuaa4b0772017-01-30 07:41:18 -08003382 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003383 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 07:41:18 -08003384 std::string sdp_with_fmtp = kSdpFullString;
3385 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3386 "a=maxptime:120\r\n" // No comma here. String merging!
3387 "a=ptime:20\r\n",
3388 &sdp_with_fmtp);
3389 EXPECT_EQ(sdp_with_fmtp, message);
3390}
3391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 15:14:30 -08003393 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394
3395 cricket::VideoCodecs codecs = vcd->codecs();
3396 codecs[0].params["x-google-min-bitrate"] = "10";
3397 vcd->set_codecs(codecs);
3398
Yves Gerey665174f2018-06-19 15:03:05 +02003399 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003401 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 std::string sdp_with_fmtp = kSdpFullString;
3403 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 15:03:05 +02003404 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405 EXPECT_EQ(sdp_with_fmtp, message);
3406}
3407
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003408TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3409 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 10:27:41 -08003410 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 std::string sdp_with_icelite = kSdpFullString;
3412 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3413 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3414 const cricket::TransportInfo* tinfo1 =
3415 desc->GetTransportInfoByName("audio_content_name");
3416 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3417 const cricket::TransportInfo* tinfo2 =
3418 desc->GetTransportInfoByName("video_content_name");
3419 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003420
3421 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 15:03:05 +02003422 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3424 desc = jdesc_with_icelite.description();
3425 const cricket::TransportInfo* atinfo =
3426 desc->GetTransportInfoByName("audio_content_name");
3427 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3428 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003429 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 11:37:28 -07003431
3432 // Now that we know deserialization works, we can use TestSerialize to test
3433 // serialization.
3434 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435}
3436
3437// Verifies that the candidates in the input SDP are parsed and serialized
3438// correctly in the output SDP.
3439TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3440 std::string sdp_with_data = kSdpString;
3441 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 10:27:41 -08003442 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443
3444 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 12:22:16 -08003445 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446}
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003447
3448TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3449 AddFingerprint();
3450 TransportInfo audio_transport_info =
3451 *(desc_.GetTransportInfoByName(kAudioContentName));
3452 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3453 audio_transport_info.description.connection_role);
3454 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003455 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003456
3457 TransportInfo video_transport_info =
3458 *(desc_.GetTransportInfoByName(kVideoContentName));
3459 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3460 video_transport_info.description.connection_role);
3461 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 15:03:05 +02003462 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003463
3464 desc_.RemoveTransportInfoByName(kAudioContentName);
3465 desc_.RemoveTransportInfoByName(kVideoContentName);
3466
3467 desc_.AddTransportInfo(audio_transport_info);
3468 desc_.AddTransportInfo(video_transport_info);
3469
Yves Gerey665174f2018-06-19 15:03:05 +02003470 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003471 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 12:22:16 -08003472 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003473 std::string sdp_with_dtlssetup = kSdpFullString;
3474
3475 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003476 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3477 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003478 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 15:03:05 +02003479 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003480 EXPECT_EQ(sdp_with_dtlssetup, message);
3481}
3482
3483TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 10:27:41 -08003484 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003485 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 15:03:05 +02003486 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003487 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3488 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3489 const cricket::TransportInfo* atinfo =
3490 desc->GetTransportInfoByName("audio_content_name");
3491 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3492 atinfo->description.connection_role);
3493 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 15:03:05 +02003494 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00003495 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3496 vtinfo->description.connection_role);
3497}
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003498
3499// Verifies that the order of the serialized m-lines follows the order of the
3500// ContentInfo in SessionDescription, and vise versa for deserialization.
3501TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 10:27:41 -08003502 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 15:03:05 +02003503 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3504 kSdpSctpDataChannelString};
3505 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3506 cricket::MEDIA_TYPE_VIDEO,
3507 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003508
3509 // Verifies all 6 permutations.
3510 for (size_t i = 0; i < 6; ++i) {
3511 size_t media_content_in_sdp[3];
3512 // The index of the first media content.
3513 media_content_in_sdp[0] = i / 2;
3514 // The index of the second media content.
3515 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3516 // The index of the third media content.
3517 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3518
3519 std::string sdp_string = kSdpSessionString;
3520 for (size_t i = 0; i < 3; ++i)
3521 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3522
3523 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3524 cricket::SessionDescription* desc = jdesc.description();
3525 EXPECT_EQ(3u, desc->contents().size());
3526
3527 for (size_t i = 0; i < 3; ++i) {
3528 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 15:14:30 -08003529 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003530 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3531 }
3532
Steve Antone831b8c2018-02-01 12:22:16 -08003533 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +00003534 EXPECT_EQ(sdp_string, serialized_sdp);
3535 }
3536}
deadbeef9d3584c2016-02-16 17:54:10 -08003537
deadbeef25ed4352016-12-12 18:37:36 -08003538TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3539 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 10:27:41 -08003540 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003541 ASSERT_TRUE(
deadbeef25ed4352016-12-12 18:37:36 -08003542 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3543 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3544}
3545
deadbeef12771a12017-01-03 13:53:47 -08003546// The semantics of "a=bundle-only" are only defined when it's used in
3547// combination with a 0 port on the m= line. We should ignore it if used with a
3548// nonzero port.
3549TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3550 // Make the base bundle-only description but unset the bundle-only flag.
3551 MakeBundleOnlyDescription();
3552 jdesc_.description()->contents()[1].bundle_only = false;
3553
3554 std::string modified_sdp = kBundleOnlySdpFullString;
3555 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 10:27:41 -08003556 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 13:53:47 -08003557 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3558 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-12 18:37:36 -08003559}
3560
3561TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3562 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003563 TestSerialize(jdesc_);
deadbeef25ed4352016-12-12 18:37:36 -08003564}
3565
deadbeef9d3584c2016-02-16 17:54:10 -08003566TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3567 MakePlanBDescription();
3568
Steve Antona3a92c22017-12-07 10:27:41 -08003569 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003570 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3571
3572 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3573}
3574
3575TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3576 MakePlanBDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003577 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-16 17:54:10 -08003578}
3579
3580TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3581 MakeUnifiedPlanDescription();
3582
Steve Antona3a92c22017-12-07 10:27:41 -08003583 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-16 17:54:10 -08003584 EXPECT_TRUE(
3585 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3586
3587 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3588}
3589
3590TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3591 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 12:22:16 -08003592 TestSerialize(jdesc_);
3593}
3594
Seth Hampson5b4f0752018-04-02 16:31:36 -07003595// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003596// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3597// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 16:31:36 -07003598// with no stream ids and multiple stream ids. For parsing this, the Unified
3599// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3600// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003601TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3602 // Create both msid lines for Plan B and Unified Plan support.
3603 MakeUnifiedPlanDescriptionMultipleStreamIds(
3604 cricket::kMsidSignalingMediaSection |
3605 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003606
3607 JsepSessionDescription deserialized_description(kDummyType);
3608 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3609 &deserialized_description));
3610
3611 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 11:25:05 +01003612 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3613 cricket::kMsidSignalingSsrcAttribute,
3614 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003615}
3616
Seth Hampson7fa6ee62018-10-17 10:25:28 -07003617// Tests the serialization of a Unified Plan SDP that is compatible for both
3618// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3619// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3620// multiple stream ids.
3621TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3622 // Create both msid lines for Plan B and Unified Plan support.
3623 MakeUnifiedPlanDescriptionMultipleStreamIds(
3624 cricket::kMsidSignalingMediaSection |
3625 cricket::kMsidSignalingSsrcAttribute);
3626 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3627 // We explicitly test that the serialized SDP string is equal to the hard
3628 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3629 // take priority over "a=ssrc msid" lines. This means if we just used
3630 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3631 // and still pass, because the deserialized version would be the same.
3632 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3633}
3634
3635// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3636// that signal stream IDs) is deserialized appropriately. It tests the case for
3637// no stream ids and multiple stream ids.
3638TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3639 // Only create a=msid lines for strictly Unified Plan stream ID support.
3640 MakeUnifiedPlanDescriptionMultipleStreamIds(
3641 cricket::kMsidSignalingMediaSection);
3642
3643 JsepSessionDescription deserialized_description(kDummyType);
3644 std::string unified_plan_sdp_string =
3645 kUnifiedPlanSdpFullStringWithSpecialMsid;
3646 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3647 EXPECT_TRUE(
3648 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3649
3650 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3651}
3652
3653// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3654// that signal stream IDs) is serialized appropriately. It tests the case for no
3655// stream ids and multiple stream ids.
3656TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3657 // Only create a=msid lines for strictly Unified Plan stream ID support.
3658 MakeUnifiedPlanDescriptionMultipleStreamIds(
3659 cricket::kMsidSignalingMediaSection);
3660
Seth Hampson5b4f0752018-04-02 16:31:36 -07003661 TestSerialize(jdesc_);
3662}
3663
Seth Hampson5897a6e2018-04-03 11:16:33 -07003664// This tests that a Unified Plan SDP with no a=ssrc lines is
3665// serialized/deserialized appropriately. In this case the
3666// MediaContentDescription will contain a StreamParams object that doesn't have
3667// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3668// SSRC lines.
3669TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3670 MakeUnifiedPlanDescription();
3671 RemoveSsrcSignalingFromStreamParams();
3672 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3673 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3674
3675 JsepSessionDescription deserialized_description(kDummyType);
3676 EXPECT_TRUE(
3677 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3678 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3679}
3680
3681TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3682 MakeUnifiedPlanDescription();
3683 RemoveSsrcSignalingFromStreamParams();
3684
3685 TestSerialize(jdesc_);
3686}
3687
Steve Antone831b8c2018-02-01 12:22:16 -08003688TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3689 JsepSessionDescription jsep_desc(kDummyType);
3690 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3691 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3692}
3693
3694TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3695 JsepSessionDescription jsep_desc(kDummyType);
3696 std::string sdp = kSdpSessionString;
3697 sdp += kSdpSctpDataChannelString;
3698 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3699 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3700}
3701
3702TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3703 JsepSessionDescription jsep_desc(kDummyType);
3704 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3705 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3706 jsep_desc.description()->msid_signaling());
3707}
3708
3709TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3710 JsepSessionDescription jsep_desc(kDummyType);
3711 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3712 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3713 jsep_desc.description()->msid_signaling());
3714}
3715
3716const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3717const char kSsrcAttributeMsidLine[] =
3718 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3719
3720TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3721 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3722 std::string sdp = webrtc::SdpSerialize(jdesc_);
3723
3724 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3725 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3726}
3727
3728TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3729 jdesc_.description()->set_msid_signaling(
3730 cricket::kMsidSignalingSsrcAttribute);
3731 std::string sdp = webrtc::SdpSerialize(jdesc_);
3732
3733 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
3734 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3735}
3736
3737TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
3738 jdesc_.description()->set_msid_signaling(
3739 cricket::kMsidSignalingMediaSection |
3740 cricket::kMsidSignalingSsrcAttribute);
3741 std::string sdp = webrtc::SdpSerialize(jdesc_);
3742
3743 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3744 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-16 17:54:10 -08003745}
deadbeef7e146cb2016-09-28 10:04:34 -07003746
3747// Regression test for heap overflow bug:
3748// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3749TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 10:04:34 -07003750 // The issue occurs when the sctp-port attribute is found in a video
3751 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 12:43:58 -08003752 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 10:04:34 -07003753 "v=0\r\n"
3754 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3755 "s=-\r\n"
3756 "t=0 0\r\n"
3757 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3758 "a=sctp-port 5000\r\n"
3759 "a=fmtp:108 foo=10\r\n";
3760
3761 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3762 "sctp-port");
3763}
deadbeefb2362572016-12-13 16:37:06 -08003764
3765// Regression test for integer overflow bug:
3766// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3767TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-13 16:37:06 -08003768 // Bandwidth attribute is the max signed 32-bit int, which will get
3769 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 12:43:58 -08003770 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-13 16:37:06 -08003771 "v=0\r\n"
3772 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3773 "s=-\r\n"
3774 "t=0 0\r\n"
3775 "m=video 3457 RTP/SAVPF 120\r\n"
3776 "b=AS:2147483647\r\n"
3777 "foo=fail\r\n";
3778
3779 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3780}
deadbeef7bcdb692017-01-20 12:43:58 -08003781
deadbeefbc88c6b2017-08-02 11:26:34 -07003782// Similar to the above, except that negative values are illegal, not just
3783// error-prone as large values are.
3784// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3785TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3786 static const char kSdpWithNegativeBandwidth[] =
3787 "v=0\r\n"
3788 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3789 "s=-\r\n"
3790 "t=0 0\r\n"
3791 "m=video 3457 RTP/SAVPF 120\r\n"
3792 "b=AS:-1000\r\n";
3793
3794 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3795}
3796
deadbeef3e8016e2017-08-03 17:49:30 -07003797// An exception to the above rule: a value of -1 for b=AS should just be
3798// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3799// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3800// limit", but this is now what ommitting the attribute entirely will do, so
3801// ignoring it will have the intended effect.
3802TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3803 static const char kSdpWithBandwidthOfNegativeOne[] =
3804 "v=0\r\n"
3805 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3806 "s=-\r\n"
3807 "t=0 0\r\n"
3808 "m=video 3457 RTP/SAVPF 120\r\n"
3809 "b=AS:-1\r\n";
3810
Steve Antona3a92c22017-12-07 10:27:41 -08003811 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-03 17:49:30 -07003812 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-03 17:49:30 -07003813 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 15:14:30 -08003814 GetFirstVideoContentDescription(jdesc_output.description());
3815 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-03 17:49:30 -07003816 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3817}
3818
deadbeef7bcdb692017-01-20 12:43:58 -08003819// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3820// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3821// Regression test for:
3822// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3823TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3824 // Important piece is "ufrag foo pwd bar".
3825 static const char kSdpWithIceCredentialsInCandidateString[] =
3826 "v=0\r\n"
3827 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3828 "s=-\r\n"
3829 "t=0 0\r\n"
3830 "m=audio 9 RTP/SAVPF 111\r\n"
3831 "c=IN IP4 0.0.0.0\r\n"
3832 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3833 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3834 "a=rtpmap:111 opus/48000/2\r\n"
3835 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3836 "generation 2 ufrag foo pwd bar\r\n";
3837
Steve Antona3a92c22017-12-07 10:27:41 -08003838 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 12:43:58 -08003839 EXPECT_TRUE(
3840 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3841 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3842 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003843 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 12:43:58 -08003844 cricket::Candidate c = candidates->at(0)->candidate();
3845 EXPECT_EQ("ufrag_voice", c.username());
3846 EXPECT_EQ("pwd_voice", c.password());
3847}
deadbeef90f1e1e2017-02-10 12:35:05 -08003848
Johannes Kron211856b2018-09-06 12:12:28 +02003849// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
3850// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3851// Regression test for:
3852// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
3853TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
3854 static const char kSdpWithFooIceCredentials[] =
3855 "v=0\r\n"
3856 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3857 "s=-\r\n"
3858 "t=0 0\r\n"
3859 "m=audio 9 RTP/SAVPF 111\r\n"
3860 "c=IN IP4 0.0.0.0\r\n"
3861 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3862 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
3863 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3864 "a=rtpmap:111 opus/48000/2\r\n"
3865 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3866 "generation 2\r\n";
3867
3868 JsepSessionDescription jdesc_output(kDummyType);
3869 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
3870 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3871 ASSERT_NE(nullptr, candidates);
3872 ASSERT_EQ(1U, candidates->count());
3873 cricket::Candidate c = candidates->at(0)->candidate();
3874 EXPECT_EQ("ufrag_voice", c.username());
3875 EXPECT_EQ("pwd_voice", c.password());
3876}
3877
deadbeef90f1e1e2017-02-10 12:35:05 -08003878// Test that SDP with an invalid port number in "a=candidate" lines is
3879// rejected, without crashing.
3880// Regression test for:
3881// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3882TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3883 static const char kSdpWithInvalidCandidatePort[] =
3884 "v=0\r\n"
3885 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3886 "s=-\r\n"
3887 "t=0 0\r\n"
3888 "m=audio 9 RTP/SAVPF 111\r\n"
3889 "c=IN IP4 0.0.0.0\r\n"
3890 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3891 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3892 "a=rtpmap:111 opus/48000/2\r\n"
3893 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3894 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3895
Steve Antona3a92c22017-12-07 10:27:41 -08003896 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 12:35:05 -08003897 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3898}
deadbeefa4549d62017-02-10 17:26:22 -08003899
3900// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3901// Regression test for:
3902// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3903TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3904 static const char kSdpWithMissingTrackId[] =
3905 "v=0\r\n"
3906 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3907 "s=-\r\n"
3908 "t=0 0\r\n"
3909 "m=audio 9 RTP/SAVPF 111\r\n"
3910 "c=IN IP4 0.0.0.0\r\n"
3911 "a=rtpmap:111 opus/48000/2\r\n"
3912 "a=msid:stream_id \r\n";
3913
Steve Antona3a92c22017-12-07 10:27:41 -08003914 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003915 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3916}
3917
3918TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3919 static const char kSdpWithMissingStreamId[] =
3920 "v=0\r\n"
3921 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3922 "s=-\r\n"
3923 "t=0 0\r\n"
3924 "m=audio 9 RTP/SAVPF 111\r\n"
3925 "c=IN IP4 0.0.0.0\r\n"
3926 "a=rtpmap:111 opus/48000/2\r\n"
3927 "a=msid: track_id\r\n";
3928
Steve Antona3a92c22017-12-07 10:27:41 -08003929 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-10 17:26:22 -08003930 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3931}
zhihuang38989e52017-03-21 11:04:53 -07003932
3933// Tests that if both session-level address and media-level address exist, use
3934// the media-level address.
3935TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 10:27:41 -08003936 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003937
3938 // Sesssion-level address.
3939 std::string sdp = kSdpFullString;
3940 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3941 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3942
3943 const auto& content1 = jsep_desc.description()->contents()[0];
3944 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 15:14:30 -08003945 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003946 const auto& content2 = jsep_desc.description()->contents()[1];
3947 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 15:14:30 -08003948 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003949}
3950
3951// Tests that the session-level connection address will be used if the media
3952// level-addresses are not specified.
3953TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 10:27:41 -08003954 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003955
3956 // Sesssion-level address.
3957 std::string sdp = kSdpString;
3958 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3959 // Remove the media level addresses.
3960 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3961 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3962 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3963
3964 const auto& content1 = jsep_desc.description()->contents()[0];
3965 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003966 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003967 const auto& content2 = jsep_desc.description()->contents()[1];
3968 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003969 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003970}
3971
3972TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 10:27:41 -08003973 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003974
3975 std::string sdp = kSdpString;
3976 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3977 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3978 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3979 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3980 &sdp);
3981 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3982 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3983 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3984 &sdp);
3985 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3986 const auto& content1 = jsep_desc.description()->contents()[0];
3987 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003988 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003989 const auto& content2 = jsep_desc.description()->contents()[1];
3990 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 15:14:30 -08003991 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 11:04:53 -07003992}
3993
3994// Test that the invalid or unsupprted connection data cannot be parsed.
3995TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 10:27:41 -08003996 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07003997 std::string sdp = kSdpString;
3998 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3999
4000 // Unsupported multicast IPv4 address.
4001 sdp = kSdpFullString;
4002 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4003 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4004
4005 // Unsupported multicast IPv6 address.
4006 sdp = kSdpFullString;
4007 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4008 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4009
4010 // Mismatched address type.
4011 sdp = kSdpFullString;
4012 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4013 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4014
4015 sdp = kSdpFullString;
4016 Replace("c=IN IP4 74.125.224.39\r\n",
4017 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4018 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4019}
4020
4021TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 10:27:41 -08004022 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004023 MakeDescriptionWithoutCandidates(&expected_jsep);
4024 // Serialization.
Steve Antone831b8c2018-02-01 12:22:16 -08004025 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 11:04:53 -07004026 // Deserialization.
Steve Antona3a92c22017-12-07 10:27:41 -08004027 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 11:04:53 -07004028 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 15:14:30 -08004029 auto audio_desc = jdesc.description()
4030 ->GetContentByName(kAudioContentName)
4031 ->media_description();
4032 auto video_desc = jdesc.description()
4033 ->GetContentByName(kVideoContentName)
4034 ->media_description();
zhihuang38989e52017-03-21 11:04:53 -07004035 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4036 audio_desc->connection_address().ToString());
4037 EXPECT_EQ(video_desc_->connection_address().ToString(),
4038 video_desc->connection_address().ToString());
4039}
Taylor Brandstetter93a7b242018-04-16 10:45:24 -07004040
4041// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4042// used (i.e., a single space as the session name)." So we should accept that.
4043TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4044 JsepSessionDescription jsep_desc(kDummyType);
4045 std::string sdp = kSdpString;
4046 Replace("s=-\r\n", "s= \r\n", &sdp);
4047 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4048}
Amit Hilbucha2012042018-12-03 11:35:05 -08004049
4050// Simulcast malformed input test for invalid format.
4051TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4052 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4053 "a=simulcast:\r\n", "a=simulcast:");
4054}
4055
4056// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4057TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4058 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4059 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4060 "a=simulcast:");
4061}
4062
4063// Validates that deserialization uses the a=simulcast: attribute
4064TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004065 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4066 sdp += "a=rid:1 send\r\n";
4067 sdp += "a=rid:2 send\r\n";
4068 sdp += "a=rid:3 send\r\n";
4069 sdp += "a=rid:4 recv\r\n";
4070 sdp += "a=rid:5 recv\r\n";
4071 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 11:35:05 -08004072 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4073 JsepSessionDescription output(kDummyType);
4074 SdpParseError error;
4075 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4076 const cricket::ContentInfos& contents = output.description()->contents();
4077 const cricket::MediaContentDescription* media =
4078 contents.back().media_description();
4079 EXPECT_TRUE(media->HasSimulcast());
4080 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4081 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004082 EXPECT_FALSE(media->streams().empty());
4083 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4084 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004085}
4086
4087// Validates that deserialization removes rids that do not appear in SDP
4088TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4089 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4090 sdp += "a=rid:1 send\r\n";
4091 sdp += "a=rid:3 send\r\n";
4092 sdp += "a=rid:4 recv\r\n";
4093 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4094 JsepSessionDescription output(kDummyType);
4095 SdpParseError error;
4096 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4097 const cricket::ContentInfos& contents = output.description()->contents();
4098 const cricket::MediaContentDescription* media =
4099 contents.back().media_description();
4100 EXPECT_TRUE(media->HasSimulcast());
4101 const SimulcastDescription& simulcast = media->simulcast_description();
4102 EXPECT_EQ(2ul, simulcast.send_layers().size());
4103 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4104
4105 std::vector<SimulcastLayer> all_send_layers =
4106 simulcast.send_layers().GetAllLayers();
4107 EXPECT_EQ(2ul, all_send_layers.size());
4108 EXPECT_EQ(0, std::count_if(all_send_layers.begin(), all_send_layers.end(),
4109 [](const SimulcastLayer& layer) {
4110 return layer.rid == "2";
4111 }));
4112
4113 std::vector<SimulcastLayer> all_receive_layers =
4114 simulcast.receive_layers().GetAllLayers();
4115 ASSERT_EQ(1ul, all_receive_layers.size());
4116 EXPECT_EQ("4", all_receive_layers[0].rid);
4117
4118 EXPECT_FALSE(media->streams().empty());
4119 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4120 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004121}
4122
4123// Validates that Simulcast removes rids that appear in both send and receive.
4124TEST_F(WebRtcSdpTest,
4125 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4126 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4127 sdp += "a=rid:1 send\r\n";
4128 sdp += "a=rid:2 send\r\n";
4129 sdp += "a=rid:3 send\r\n";
4130 sdp += "a=rid:4 recv\r\n";
4131 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4132 JsepSessionDescription output(kDummyType);
4133 SdpParseError error;
4134 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4135 const cricket::ContentInfos& contents = output.description()->contents();
4136 const cricket::MediaContentDescription* media =
4137 contents.back().media_description();
4138 EXPECT_TRUE(media->HasSimulcast());
4139 const SimulcastDescription& simulcast = media->simulcast_description();
4140 EXPECT_EQ(2ul, simulcast.send_layers().size());
4141 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4142 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4143 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4144
4145 EXPECT_FALSE(media->streams().empty());
4146 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4147 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004148}
4149
4150// Ignores empty rid line.
4151TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4152 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4153 sdp += "a=rid:1 send\r\n";
4154 sdp += "a=rid:2 send\r\n";
4155 sdp += "a=rid\r\n"; // Should ignore this line.
4156 sdp += "a=rid:\r\n"; // Should ignore this line.
4157 sdp += "a=simulcast:send 1;2\r\n";
4158 JsepSessionDescription output(kDummyType);
4159 SdpParseError error;
4160 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4161 const cricket::ContentInfos& contents = output.description()->contents();
4162 const cricket::MediaContentDescription* media =
4163 contents.back().media_description();
4164 EXPECT_TRUE(media->HasSimulcast());
4165 const SimulcastDescription& simulcast = media->simulcast_description();
4166 EXPECT_TRUE(simulcast.receive_layers().empty());
4167 EXPECT_EQ(2ul, simulcast.send_layers().size());
4168 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4169
4170 EXPECT_FALSE(media->streams().empty());
4171 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4172 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004173}
4174
4175// Ignores malformed rid lines.
4176TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4177 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4178 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4179 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4180 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4181 sdp += "a=rid:4\r\n"; // Should ignore this line.
4182 sdp += "a=rid:5 send\r\n";
4183 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4184 JsepSessionDescription output(kDummyType);
4185 SdpParseError error;
4186 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4187 const cricket::ContentInfos& contents = output.description()->contents();
4188 const cricket::MediaContentDescription* media =
4189 contents.back().media_description();
4190 EXPECT_TRUE(media->HasSimulcast());
4191 const SimulcastDescription& simulcast = media->simulcast_description();
4192 EXPECT_TRUE(simulcast.receive_layers().empty());
4193 EXPECT_EQ(1ul, simulcast.send_layers().size());
4194 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4195
4196 EXPECT_FALSE(media->streams().empty());
4197 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4198 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004199}
4200
4201// Removes RIDs that specify a different format than the m= section.
4202TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4203 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4204 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4205 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4206 sdp += "a=simulcast:send 1;2\r\n";
4207 JsepSessionDescription output(kDummyType);
4208 SdpParseError error;
4209 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4210 const cricket::ContentInfos& contents = output.description()->contents();
4211 const cricket::MediaContentDescription* media =
4212 contents.back().media_description();
4213 EXPECT_TRUE(media->HasSimulcast());
4214 const SimulcastDescription& simulcast = media->simulcast_description();
4215 EXPECT_TRUE(simulcast.receive_layers().empty());
4216 EXPECT_EQ(1ul, simulcast.send_layers().size());
4217 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4218 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4219 EXPECT_EQ(1ul, media->streams().size());
4220 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4221 EXPECT_EQ(1ul, rids.size());
4222 EXPECT_EQ("1", rids[0].rid);
4223 EXPECT_EQ(1ul, rids[0].payload_types.size());
4224 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004225}
4226
4227// Ignores duplicate rid lines
4228TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4229 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4230 sdp += "a=rid:1 send\r\n";
4231 sdp += "a=rid:2 send\r\n";
4232 sdp += "a=rid:2 send\r\n";
4233 sdp += "a=rid:3 send\r\n";
4234 sdp += "a=rid:4 recv\r\n";
4235 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4236 JsepSessionDescription output(kDummyType);
4237 SdpParseError error;
4238 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4239 const cricket::ContentInfos& contents = output.description()->contents();
4240 const cricket::MediaContentDescription* media =
4241 contents.back().media_description();
4242 EXPECT_TRUE(media->HasSimulcast());
4243 const SimulcastDescription& simulcast = media->simulcast_description();
4244 EXPECT_EQ(2ul, simulcast.send_layers().size());
4245 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4246 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4247 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4248
4249 EXPECT_FALSE(media->streams().empty());
4250 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4251 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 11:35:05 -08004252}
4253
4254// Simulcast serialization integration test.
4255// This test will serialize and deserialize the description and compare.
4256// More detailed tests for parsing simulcast can be found in
4257// unit tests for SdpSerializer.
4258TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004259 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 11:35:05 -08004260 auto description = jdesc_.description();
4261 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004262 ASSERT_EQ(media->streams().size(), 1ul);
4263 StreamParams& send_stream = media->mutable_streams()[0];
4264 std::vector<RidDescription> send_rids;
4265 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4266 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4267 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4268 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4269 send_stream.set_rids(send_rids);
Amit Hilbuchc57d5732018-12-11 15:30:11 -08004270
Amit Hilbucha2012042018-12-03 11:35:05 -08004271 SimulcastDescription& simulcast = media->simulcast_description();
4272 simulcast.send_layers().AddLayerWithAlternatives(
4273 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4274 simulcast.send_layers().AddLayerWithAlternatives(
4275 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
4276
Amit Hilbucha2012042018-12-03 11:35:05 -08004277 TestSerialize(jdesc_);
4278}
Steve Anton06817cd2018-12-18 15:55:30 -08004279
4280// Test that the content name is empty if the media section does not have an
4281// a=mid line.
4282TEST_F(WebRtcSdpTest, ParseNoMid) {
4283 std::string sdp = kSdpString;
4284 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4285 Replace("a=mid:video_content_name\r\n", "", &sdp);
4286
4287 JsepSessionDescription output(kDummyType);
4288 SdpParseError error;
4289 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4290
4291 EXPECT_THAT(output.description()->contents(),
4292 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4293 Field("name", &cricket::ContentInfo::name, "")));
4294}