blob: 476955d26ba14b92636cd7f0c06f31c13e9027e0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:369 */
10
Yves Gerey3e707812018-11-28 15:47:4911#include <stdio.h>
12#include <string.h>
Jonas Olssona4d87372019-07-05 17:08:3313
Harald Alvestrand4d7160e2019-04-12 05:01:2914#include <algorithm>
Yves Gerey3e707812018-11-28 15:47:4915#include <cstdint>
16#include <map>
kwibergd1fe2812016-04-27 13:47:2917#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3618#include <string>
Yves Gerey3e707812018-11-28 15:47:4919#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:3620#include <vector>
21
Steve Anton64b626b2019-01-29 01:25:2622#include "absl/algorithm/container.h"
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:0523#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 23:13:0924#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 15:47:4925#include "api/array_view.h"
Steve Anton10542f22019-01-11 17:11:0026#include "api/crypto_params.h"
27#include "api/jsep_session_description.h"
28#include "api/media_types.h"
29#include "api/rtp_parameters.h"
30#include "api/rtp_transceiver_interface.h"
Yves Gerey3e707812018-11-28 15:47:4931#include "media/base/codec.h"
Steve Anton10542f22019-01-11 17:11:0032#include "media/base/media_constants.h"
33#include "media/base/stream_params.h"
34#include "p2p/base/p2p_constants.h"
Yves Gerey665174f2018-06-19 13:03:0535#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 17:11:0036#include "p2p/base/transport_description.h"
37#include "p2p/base/transport_info.h"
38#include "pc/media_session.h"
39#include "pc/session_description.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3140#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0041#include "rtc_base/message_digest.h"
42#include "rtc_base/socket_address.h"
43#include "rtc_base/ssl_fingerprint.h"
44#include "rtc_base/string_encode.h"
Steve Anton06817cd2018-12-18 23:55:3045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4946#include "test/gtest.h"
Patrik Höglund563934e2017-09-15 07:04:2847
ossu7bb87ee2017-01-23 12:56:2548#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 17:11:0049#include "pc/test/android_test_initializer.h"
ossu7bb87ee2017-01-23 12:56:2550#endif
Steve Anton10542f22019-01-11 17:11:0051#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:3652
53using cricket::AudioCodec;
54using cricket::AudioContentDescription;
55using cricket::Candidate;
Steve Anton06817cd2018-12-18 23:55:3056using cricket::ContentGroup;
henrike@webrtc.org28e20752013-07-10 00:45:3657using cricket::ContentInfo;
58using cricket::CryptoParams;
henrike@webrtc.org28e20752013-07-10 00:45:3659using cricket::DataCodec;
henrike@webrtc.org28e20752013-07-10 00:45:3660using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
61using cricket::ICE_CANDIDATE_COMPONENT_RTP;
62using cricket::kFecSsrcGroupSemantics;
63using cricket::LOCAL_PORT_TYPE;
Steve Anton5adfafd2017-12-21 00:34:0064using cricket::MediaProtocolType;
Steve Anton06817cd2018-12-18 23:55:3065using cricket::RELAY_PORT_TYPE;
Amit Hilbuchc57d5732018-12-11 23:30:1166using cricket::RidDescription;
67using cricket::RidDirection;
Harald Alvestrand5fc28b12019-05-13 11:36:1668using cricket::RtpDataContentDescription;
69using cricket::SctpDataContentDescription;
Steve Anton06817cd2018-12-18 23:55:3070using cricket::SessionDescription;
Amit Hilbucha2012042018-12-03 19:35:0571using cricket::SimulcastDescription;
72using cricket::SimulcastLayer;
henrike@webrtc.org28e20752013-07-10 00:45:3673using cricket::StreamParams;
74using cricket::STUN_PORT_TYPE;
75using cricket::TransportDescription;
76using cricket::TransportInfo;
77using cricket::VideoCodec;
78using cricket::VideoContentDescription;
Steve Anton06817cd2018-12-18 23:55:3079using ::testing::ElementsAre;
80using ::testing::Field;
henrike@webrtc.org28e20752013-07-10 00:45:3681using webrtc::IceCandidateCollection;
82using webrtc::IceCandidateInterface;
83using webrtc::JsepIceCandidate;
84using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 18:24:5585using webrtc::RtpExtension;
Steve Anton4e70a722017-11-28 22:57:1086using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:3687using webrtc::SdpParseError;
Steve Antona3a92c22017-12-07 18:27:4188using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:3689using webrtc::SessionDescriptionInterface;
90
91typedef std::vector<AudioCodec> AudioCodecs;
92typedef std::vector<Candidate> Candidates;
93
Peter Boström0c4e06b2015-10-07 10:23:2194static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-18 03:48:3895static const uint16_t kUnusualSctpPort = 9556;
henrike@webrtc.org28e20752013-07-10 00:45:3696static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2197static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1498static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3699static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:14100static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36101static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:21102static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36103static const char kCandidateFoundation1[] = "a0+B/1";
104static const char kCandidateFoundation2[] = "a0+B/2";
105static const char kCandidateFoundation3[] = "a0+B/3";
106static const char kCandidateFoundation4[] = "a0+B/4";
107static const char kAttributeCryptoVoice[] =
108 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
109 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
110 "dummy_session_params\r\n";
111static const char kAttributeCryptoVideo[] =
112 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
113 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
Yves Gerey665174f2018-06-19 13:03:05114static const char kFingerprint[] =
115 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:36116 "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 20:33:20117static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36118static const int kExtmapId = 1;
119static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
120static const char kExtmap[] =
121 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
122static const char kExtmapWithDirectionAndAttribute[] =
123 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 19:31:36124static const char kExtmapWithDirectionAndAttributeEncrypted[] =
125 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
126 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36127
Peter Boström0c4e06b2015-10-07 10:23:21128static const uint8_t kIdentityDigest[] = {
129 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
130 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36131
lally@webrtc.org34807282015-02-24 20:19:39132static const char kDtlsSctp[] = "DTLS/SCTP";
133static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
134static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35135
henrike@webrtc.org28e20752013-07-10 00:45:36136struct CodecParams {
137 int max_ptime;
138 int ptime;
139 int min_ptime;
140 int sprop_stereo;
141 int stereo;
142 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59143 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36144};
145
deadbeef9d3584c2016-02-17 01:54:10146// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
147// instead of "a=crypto", and have an explicit test for adding "a=crypto".
148// Currently it's the other way around.
149
henrike@webrtc.org28e20752013-07-10 00:45:36150// Reference sdp string
151static const char kSdpFullString[] =
152 "v=0\r\n"
153 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
154 "s=-\r\n"
155 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10156 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36157 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
158 "c=IN IP4 74.125.127.126\r\n"
159 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
167 "generation 2\r\n"
168 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
169 "raddr 192.168.1.5 rport 2346 "
170 "generation 2\r\n"
171 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
172 "raddr 192.168.1.5 rport 2348 "
173 "generation 2\r\n"
174 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
175 "a=mid:audio_content_name\r\n"
176 "a=sendrecv\r\n"
177 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51178 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36179 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
180 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
181 "dummy_session_params\r\n"
182 "a=rtpmap:111 opus/48000/2\r\n"
183 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41184 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36185 "a=ssrc:1 cname:stream_1_cname\r\n"
186 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
187 "a=ssrc:1 mslabel:local_stream_1\r\n"
188 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36189 "m=video 3457 RTP/SAVPF 120\r\n"
190 "c=IN IP4 74.125.224.39\r\n"
191 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
192 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
193 "generation 2\r\n"
194 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
195 "generation 2\r\n"
196 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
197 "generation 2\r\n"
198 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
199 "generation 2\r\n"
200 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
201 "generation 2\r\n"
202 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
203 "generation 2\r\n"
204 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
205 "a=mid:video_content_name\r\n"
206 "a=sendrecv\r\n"
207 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
208 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
209 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10210 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36211 "a=ssrc:2 cname:stream_1_cname\r\n"
212 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
213 "a=ssrc:2 mslabel:local_stream_1\r\n"
214 "a=ssrc:2 label:video_track_id_1\r\n"
215 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10216 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36217 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10218 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36219
220// SDP reference string without the candidates.
221static const char kSdpString[] =
222 "v=0\r\n"
223 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
224 "s=-\r\n"
225 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10226 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22227 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06228 "c=IN IP4 0.0.0.0\r\n"
229 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36230 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
231 "a=mid:audio_content_name\r\n"
232 "a=sendrecv\r\n"
233 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51234 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36235 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
236 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
237 "dummy_session_params\r\n"
238 "a=rtpmap:111 opus/48000/2\r\n"
239 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41240 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36241 "a=ssrc:1 cname:stream_1_cname\r\n"
242 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
243 "a=ssrc:1 mslabel:local_stream_1\r\n"
244 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22245 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06246 "c=IN IP4 0.0.0.0\r\n"
247 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36248 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
249 "a=mid:video_content_name\r\n"
250 "a=sendrecv\r\n"
251 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
252 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
253 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10254 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36255 "a=ssrc:2 cname:stream_1_cname\r\n"
256 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
257 "a=ssrc:2 mslabel:local_stream_1\r\n"
258 "a=ssrc:2 label:video_track_id_1\r\n"
259 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10260 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36261 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10262 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36263
264static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22265 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06266 "c=IN IP4 0.0.0.0\r\n"
267 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36268 "a=ice-ufrag:ufrag_data\r\n"
269 "a=ice-pwd:pwd_data\r\n"
270 "a=mid:data_content_name\r\n"
271 "a=sendrecv\r\n"
272 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
273 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
274 "a=rtpmap:101 google-data/90000\r\n"
275 "a=ssrc:10 cname:data_channel_cname\r\n"
276 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
277 "a=ssrc:10 mslabel:data_channel\r\n"
278 "a=ssrc:10 label:data_channeld0\r\n";
279
Harald Alvestrand5fc28b12019-05-13 11:36:16280// draft-ietf-mmusic-sctp-sdp-03
henrike@webrtc.org28e20752013-07-10 00:45:36281static const char kSdpSctpDataChannelString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38282 "m=application 9 UDP/DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06283 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36284 "a=ice-ufrag:ufrag_data\r\n"
285 "a=ice-pwd:pwd_data\r\n"
286 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33287 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36288
lally@webrtc.orgec97c652015-02-24 20:18:48289// draft-ietf-mmusic-sctp-sdp-12
Harald Alvestrand48cce4d2019-04-11 08:41:24290// Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26,
291// since the separator after "sctp-port" needs to be a colon.
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56292static const char kSdpSctpDataChannelStringWithSctpPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38293 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally@webrtc.orgc7848b72015-02-24 20:19:26294 "a=sctp-port 5000\r\n"
295 "c=IN IP4 0.0.0.0\r\n"
296 "a=ice-ufrag:ufrag_data\r\n"
297 "a=ice-pwd:pwd_data\r\n"
298 "a=mid:data_content_name\r\n";
299
Harald Alvestrand48cce4d2019-04-11 08:41:24300// draft-ietf-mmusic-sctp-sdp-26
lally69f57602015-10-08 17:15:04301static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
Guido Urdanetacecf87f2019-05-31 10:17:38302 "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
lally69f57602015-10-08 17:15:04303 "a=sctp-port:5000\r\n"
304 "c=IN IP4 0.0.0.0\r\n"
305 "a=ice-ufrag:ufrag_data\r\n"
306 "a=ice-pwd:pwd_data\r\n"
307 "a=mid:data_content_name\r\n";
308
henrike@webrtc.org28e20752013-07-10 00:45:36309static const char kSdpSctpDataChannelWithCandidatesString[] =
Guido Urdanetacecf87f2019-05-31 10:17:38310 "m=application 2345 UDP/DTLS/SCTP 5000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36311 "c=IN IP4 74.125.127.126\r\n"
312 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
313 "generation 2\r\n"
314 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
315 "generation 2\r\n"
316 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
317 "raddr 192.168.1.5 rport 2346 "
318 "generation 2\r\n"
319 "a=ice-ufrag:ufrag_data\r\n"
320 "a=ice-pwd:pwd_data\r\n"
321 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33322 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36323
jiayl@webrtc.org9c16c392014-05-01 18:30:30324static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04325 "v=0\r\n"
326 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
327 "s=-\r\n"
328 "t=0 0\r\n"
329 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22330 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06331 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04332 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22333 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06334 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04335 "a=x-google-flag:conference\r\n";
336
jiayl@webrtc.orge7d47a12014-08-05 19:19:05337static const char kSdpSessionString[] =
338 "v=0\r\n"
339 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
340 "s=-\r\n"
341 "t=0 0\r\n"
342 "a=msid-semantic: WMS local_stream\r\n";
343
344static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22345 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06346 "c=IN IP4 0.0.0.0\r\n"
347 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05348 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
349 "a=mid:audio_content_name\r\n"
350 "a=sendrecv\r\n"
351 "a=rtpmap:111 opus/48000/2\r\n"
352 "a=ssrc:1 cname:stream_1_cname\r\n"
353 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
354 "a=ssrc:1 mslabel:local_stream\r\n"
355 "a=ssrc:1 label:audio_track_id_1\r\n";
356
357static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22358 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06359 "c=IN IP4 0.0.0.0\r\n"
360 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05361 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
362 "a=mid:video_content_name\r\n"
363 "a=sendrecv\r\n"
364 "a=rtpmap:120 VP8/90000\r\n"
365 "a=ssrc:2 cname:stream_1_cname\r\n"
366 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
367 "a=ssrc:2 mslabel:local_stream\r\n"
368 "a=ssrc:2 label:video_track_id_1\r\n";
369
deadbeef25ed4352016-12-13 02:37:36370// Reference sdp string using bundle-only.
371static const char kBundleOnlySdpFullString[] =
372 "v=0\r\n"
373 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
374 "s=-\r\n"
375 "t=0 0\r\n"
376 "a=group:BUNDLE audio_content_name video_content_name\r\n"
377 "a=msid-semantic: WMS local_stream_1\r\n"
378 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
379 "c=IN IP4 74.125.127.126\r\n"
380 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
381 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
388 "generation 2\r\n"
389 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
390 "raddr 192.168.1.5 rport 2346 "
391 "generation 2\r\n"
392 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
393 "raddr 192.168.1.5 rport 2348 "
394 "generation 2\r\n"
395 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
396 "a=mid:audio_content_name\r\n"
397 "a=sendrecv\r\n"
398 "a=rtcp-mux\r\n"
399 "a=rtcp-rsize\r\n"
400 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
401 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
402 "dummy_session_params\r\n"
403 "a=rtpmap:111 opus/48000/2\r\n"
404 "a=rtpmap:103 ISAC/16000\r\n"
405 "a=rtpmap:104 ISAC/32000\r\n"
406 "a=ssrc:1 cname:stream_1_cname\r\n"
407 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
408 "a=ssrc:1 mslabel:local_stream_1\r\n"
409 "a=ssrc:1 label:audio_track_id_1\r\n"
410 "m=video 0 RTP/SAVPF 120\r\n"
411 "c=IN IP4 0.0.0.0\r\n"
412 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
413 "a=bundle-only\r\n"
414 "a=mid:video_content_name\r\n"
415 "a=sendrecv\r\n"
416 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
417 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
418 "a=rtpmap:120 VP8/90000\r\n"
419 "a=ssrc-group:FEC 2 3\r\n"
420 "a=ssrc:2 cname:stream_1_cname\r\n"
421 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
422 "a=ssrc:2 mslabel:local_stream_1\r\n"
423 "a=ssrc:2 label:video_track_id_1\r\n"
424 "a=ssrc:3 cname:stream_1_cname\r\n"
425 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
426 "a=ssrc:3 mslabel:local_stream_1\r\n"
427 "a=ssrc:3 label:video_track_id_1\r\n";
428
deadbeef9d3584c2016-02-17 01:54:10429// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
430// tracks.
431static const char kPlanBSdpFullString[] =
432 "v=0\r\n"
433 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
434 "s=-\r\n"
435 "t=0 0\r\n"
436 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
437 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
438 "c=IN IP4 74.125.127.126\r\n"
439 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
440 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
441 "generation 2\r\n"
442 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
443 "generation 2\r\n"
444 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
445 "generation 2\r\n"
446 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
447 "generation 2\r\n"
448 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
449 "raddr 192.168.1.5 rport 2346 "
450 "generation 2\r\n"
451 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
452 "raddr 192.168.1.5 rport 2348 "
453 "generation 2\r\n"
454 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
455 "a=mid:audio_content_name\r\n"
456 "a=sendrecv\r\n"
457 "a=rtcp-mux\r\n"
458 "a=rtcp-rsize\r\n"
459 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
460 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
461 "dummy_session_params\r\n"
462 "a=rtpmap:111 opus/48000/2\r\n"
463 "a=rtpmap:103 ISAC/16000\r\n"
464 "a=rtpmap:104 ISAC/32000\r\n"
465 "a=ssrc:1 cname:stream_1_cname\r\n"
466 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
467 "a=ssrc:1 mslabel:local_stream_1\r\n"
468 "a=ssrc:1 label:audio_track_id_1\r\n"
469 "a=ssrc:4 cname:stream_2_cname\r\n"
470 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
471 "a=ssrc:4 mslabel:local_stream_2\r\n"
472 "a=ssrc:4 label:audio_track_id_2\r\n"
473 "m=video 3457 RTP/SAVPF 120\r\n"
474 "c=IN IP4 74.125.224.39\r\n"
475 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
476 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
477 "generation 2\r\n"
478 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
479 "generation 2\r\n"
480 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
481 "generation 2\r\n"
482 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
483 "generation 2\r\n"
484 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
485 "generation 2\r\n"
486 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
487 "generation 2\r\n"
488 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
489 "a=mid:video_content_name\r\n"
490 "a=sendrecv\r\n"
491 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
492 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
493 "a=rtpmap:120 VP8/90000\r\n"
494 "a=ssrc-group:FEC 2 3\r\n"
495 "a=ssrc:2 cname:stream_1_cname\r\n"
496 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
497 "a=ssrc:2 mslabel:local_stream_1\r\n"
498 "a=ssrc:2 label:video_track_id_1\r\n"
499 "a=ssrc:3 cname:stream_1_cname\r\n"
500 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
501 "a=ssrc:3 mslabel:local_stream_1\r\n"
502 "a=ssrc:3 label:video_track_id_1\r\n"
503 "a=ssrc:5 cname:stream_2_cname\r\n"
504 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
505 "a=ssrc:5 mslabel:local_stream_2\r\n"
506 "a=ssrc:5 label:video_track_id_2\r\n"
507 "a=ssrc:6 cname:stream_2_cname\r\n"
508 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
509 "a=ssrc:6 mslabel:local_stream_2\r\n"
510 "a=ssrc:6 label:video_track_id_3\r\n";
511
512// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
513// tracks.
514static const char kUnifiedPlanSdpFullString[] =
515 "v=0\r\n"
516 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
517 "s=-\r\n"
518 "t=0 0\r\n"
519 "a=msid-semantic: WMS local_stream_1\r\n"
520 // Audio track 1, stream 1 (with candidates).
521 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
522 "c=IN IP4 74.125.127.126\r\n"
523 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
524 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
525 "generation 2\r\n"
526 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
527 "generation 2\r\n"
528 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
529 "generation 2\r\n"
530 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
531 "generation 2\r\n"
532 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
533 "raddr 192.168.1.5 rport 2346 "
534 "generation 2\r\n"
535 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
536 "raddr 192.168.1.5 rport 2348 "
537 "generation 2\r\n"
538 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
539 "a=mid:audio_content_name\r\n"
540 "a=msid:local_stream_1 audio_track_id_1\r\n"
541 "a=sendrecv\r\n"
542 "a=rtcp-mux\r\n"
543 "a=rtcp-rsize\r\n"
544 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
545 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
546 "dummy_session_params\r\n"
547 "a=rtpmap:111 opus/48000/2\r\n"
548 "a=rtpmap:103 ISAC/16000\r\n"
549 "a=rtpmap:104 ISAC/32000\r\n"
550 "a=ssrc:1 cname:stream_1_cname\r\n"
551 // Video track 1, stream 1 (with candidates).
552 "m=video 3457 RTP/SAVPF 120\r\n"
553 "c=IN IP4 74.125.224.39\r\n"
554 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
555 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
556 "generation 2\r\n"
557 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
558 "generation 2\r\n"
559 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
560 "generation 2\r\n"
561 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
562 "generation 2\r\n"
563 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
564 "generation 2\r\n"
565 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
566 "generation 2\r\n"
567 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
568 "a=mid:video_content_name\r\n"
569 "a=msid:local_stream_1 video_track_id_1\r\n"
570 "a=sendrecv\r\n"
571 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
572 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
573 "a=rtpmap:120 VP8/90000\r\n"
574 "a=ssrc-group:FEC 2 3\r\n"
575 "a=ssrc:2 cname:stream_1_cname\r\n"
576 "a=ssrc:3 cname:stream_1_cname\r\n"
577 // Audio track 2, stream 2.
578 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
579 "c=IN IP4 0.0.0.0\r\n"
580 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
581 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
582 "a=mid:audio_content_name_2\r\n"
583 "a=msid:local_stream_2 audio_track_id_2\r\n"
584 "a=sendrecv\r\n"
585 "a=rtcp-mux\r\n"
586 "a=rtcp-rsize\r\n"
587 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
588 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
589 "dummy_session_params\r\n"
590 "a=rtpmap:111 opus/48000/2\r\n"
591 "a=rtpmap:103 ISAC/16000\r\n"
592 "a=rtpmap:104 ISAC/32000\r\n"
593 "a=ssrc:4 cname:stream_2_cname\r\n"
594 // Video track 2, stream 2.
595 "m=video 9 RTP/SAVPF 120\r\n"
596 "c=IN IP4 0.0.0.0\r\n"
597 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
598 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
599 "a=mid:video_content_name_2\r\n"
600 "a=msid:local_stream_2 video_track_id_2\r\n"
601 "a=sendrecv\r\n"
602 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
603 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
604 "a=rtpmap:120 VP8/90000\r\n"
605 "a=ssrc:5 cname:stream_2_cname\r\n"
606 // Video track 3, stream 2.
607 "m=video 9 RTP/SAVPF 120\r\n"
608 "c=IN IP4 0.0.0.0\r\n"
609 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
610 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
611 "a=mid:video_content_name_3\r\n"
612 "a=msid:local_stream_2 video_track_id_3\r\n"
613 "a=sendrecv\r\n"
614 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
615 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
616 "a=rtpmap:120 VP8/90000\r\n"
617 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36618
Seth Hampson5b4f0752018-04-02 23:31:36619// Unified Plan SDP reference string:
620// - audio track 1 has 1 a=msid lines
621// - audio track 2 has 2 a=msid lines
622// - audio track 3 has 1 a=msid line with the special "-" marker signifying that
623// there are 0 media stream ids.
624// This Unified Plan SDP represents a SDP that signals the msid using both
625// a=msid and a=ssrc msid semantics.
626static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] =
627 "v=0\r\n"
628 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
629 "s=-\r\n"
630 "t=0 0\r\n"
631 "a=msid-semantic: WMS local_stream_1\r\n"
632 // Audio track 1, with 1 stream id.
633 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
634 "c=IN IP4 74.125.127.126\r\n"
635 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
636 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
637 "generation 2\r\n"
638 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
639 "generation 2\r\n"
640 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
641 "generation 2\r\n"
642 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
643 "generation 2\r\n"
644 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
645 "raddr 192.168.1.5 rport 2346 "
646 "generation 2\r\n"
647 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
648 "raddr 192.168.1.5 rport 2348 "
649 "generation 2\r\n"
650 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
651 "a=mid:audio_content_name\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36652 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28653 "a=msid:local_stream_1 audio_track_id_1\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36654 "a=rtcp-mux\r\n"
655 "a=rtcp-rsize\r\n"
656 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
657 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
658 "dummy_session_params\r\n"
659 "a=rtpmap:111 opus/48000/2\r\n"
660 "a=rtpmap:103 ISAC/16000\r\n"
661 "a=rtpmap:104 ISAC/32000\r\n"
662 "a=ssrc:1 cname:stream_1_cname\r\n"
663 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
664 "a=ssrc:1 mslabel:local_stream_1\r\n"
665 "a=ssrc:1 label:audio_track_id_1\r\n"
666 // Audio track 2, with two stream ids.
667 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
668 "c=IN IP4 0.0.0.0\r\n"
669 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
670 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
671 "a=mid:audio_content_name_2\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28672 "a=sendrecv\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36673 "a=msid:local_stream_1 audio_track_id_2\r\n"
674 "a=msid:local_stream_2 audio_track_id_2\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36675 "a=rtcp-mux\r\n"
676 "a=rtcp-rsize\r\n"
677 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
678 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
679 "dummy_session_params\r\n"
680 "a=rtpmap:111 opus/48000/2\r\n"
681 "a=rtpmap:103 ISAC/16000\r\n"
682 "a=rtpmap:104 ISAC/32000\r\n"
683 "a=ssrc:4 cname:stream_1_cname\r\n"
684 // The support for Plan B msid signaling only includes the
685 // first media stream id "local_stream_1."
686 "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n"
687 "a=ssrc:4 mslabel:local_stream_1\r\n"
688 "a=ssrc:4 label:audio_track_id_2\r\n"
689 // Audio track 3, with no stream ids.
690 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
691 "c=IN IP4 0.0.0.0\r\n"
692 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
693 "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n"
694 "a=mid:audio_content_name_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36695 "a=sendrecv\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28696 "a=msid:- audio_track_id_3\r\n"
Seth Hampson5b4f0752018-04-02 23:31:36697 "a=rtcp-mux\r\n"
698 "a=rtcp-rsize\r\n"
699 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
700 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
701 "dummy_session_params\r\n"
702 "a=rtpmap:111 opus/48000/2\r\n"
703 "a=rtpmap:103 ISAC/16000\r\n"
704 "a=rtpmap:104 ISAC/32000\r\n"
Seth Hampson7fa6ee62018-10-17 17:25:28705 "a=ssrc:7 cname:stream_2_cname\r\n"
706 "a=ssrc:7 msid:- audio_track_id_3\r\n"
707 "a=ssrc:7 mslabel:-\r\n"
708 "a=ssrc:7 label:audio_track_id_3\r\n";
Seth Hampson5b4f0752018-04-02 23:31:36709
Amit Hilbuchc57d5732018-12-11 23:30:11710// SDP string for unified plan without SSRCs
711static const char kUnifiedPlanSdpFullStringNoSsrc[] =
712 "v=0\r\n"
713 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
714 "s=-\r\n"
715 "t=0 0\r\n"
716 "a=msid-semantic: WMS local_stream_1\r\n"
717 // Audio track 1, stream 1 (with candidates).
718 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
719 "c=IN IP4 74.125.127.126\r\n"
720 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
721 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
722 "generation 2\r\n"
723 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
724 "generation 2\r\n"
725 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
726 "generation 2\r\n"
727 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
728 "generation 2\r\n"
729 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
730 "raddr 192.168.1.5 rport 2346 "
731 "generation 2\r\n"
732 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
733 "raddr 192.168.1.5 rport 2348 "
734 "generation 2\r\n"
735 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
736 "a=mid:audio_content_name\r\n"
737 "a=msid:local_stream_1 audio_track_id_1\r\n"
738 "a=sendrecv\r\n"
739 "a=rtcp-mux\r\n"
740 "a=rtcp-rsize\r\n"
741 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
742 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
743 "dummy_session_params\r\n"
744 "a=rtpmap:111 opus/48000/2\r\n"
745 "a=rtpmap:103 ISAC/16000\r\n"
746 "a=rtpmap:104 ISAC/32000\r\n"
747 // Video track 1, stream 1 (with candidates).
748 "m=video 3457 RTP/SAVPF 120\r\n"
749 "c=IN IP4 74.125.224.39\r\n"
750 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
751 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
752 "generation 2\r\n"
753 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
754 "generation 2\r\n"
755 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
756 "generation 2\r\n"
757 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
758 "generation 2\r\n"
759 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
760 "generation 2\r\n"
761 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
762 "generation 2\r\n"
763 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
764 "a=mid:video_content_name\r\n"
765 "a=msid:local_stream_1 video_track_id_1\r\n"
766 "a=sendrecv\r\n"
767 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
768 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
769 "a=rtpmap:120 VP8/90000\r\n"
770 // Audio track 2, stream 2.
771 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
772 "c=IN IP4 0.0.0.0\r\n"
773 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
774 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
775 "a=mid:audio_content_name_2\r\n"
776 "a=msid:local_stream_2 audio_track_id_2\r\n"
777 "a=sendrecv\r\n"
778 "a=rtcp-mux\r\n"
779 "a=rtcp-rsize\r\n"
780 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
781 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
782 "dummy_session_params\r\n"
783 "a=rtpmap:111 opus/48000/2\r\n"
784 "a=rtpmap:103 ISAC/16000\r\n"
785 "a=rtpmap:104 ISAC/32000\r\n"
786 // Video track 2, stream 2.
787 "m=video 9 RTP/SAVPF 120\r\n"
788 "c=IN IP4 0.0.0.0\r\n"
789 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
790 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
791 "a=mid:video_content_name_2\r\n"
792 "a=msid:local_stream_2 video_track_id_2\r\n"
793 "a=sendrecv\r\n"
794 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
795 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
796 "a=rtpmap:120 VP8/90000\r\n"
797 // Video track 3, stream 2.
798 "m=video 9 RTP/SAVPF 120\r\n"
799 "c=IN IP4 0.0.0.0\r\n"
800 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
801 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
802 "a=mid:video_content_name_3\r\n"
803 "a=msid:local_stream_2 video_track_id_3\r\n"
804 "a=sendrecv\r\n"
805 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
806 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
807 "a=rtpmap:120 VP8/90000\r\n";
808
henrike@webrtc.org28e20752013-07-10 00:45:36809// One candidate reference string as per W3c spec.
810// candidate:<blah> not a=candidate:<blah>CRLF
811static const char kRawCandidate[] =
812 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
813// One candidate reference string.
814static const char kSdpOneCandidate[] =
815 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
816 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15817
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20818static const char kSdpTcpActiveCandidate[] =
819 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
820 "tcptype active generation 2";
821static const char kSdpTcpPassiveCandidate[] =
822 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
823 "tcptype passive generation 2";
824static const char kSdpTcpSOCandidate[] =
825 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
826 "tcptype so generation 2";
827static const char kSdpTcpInvalidCandidate[] =
828 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
829 "tcptype invalid generation 2";
830
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15831// One candidate reference string with IPV6 address.
832static const char kRawIPV6Candidate[] =
833 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 19:04:36834 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36835
836// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23837static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36838 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23839 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36840
Zach Steinb336c272018-08-09 08:16:13841static const char kRawHostnameCandidate[] =
842 "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2";
843
henrike@webrtc.org28e20752013-07-10 00:45:36844// Session id and version
845static const char kSessionId[] = "18446744069414584320";
846static const char kSessionVersion[] = "18446462598732840960";
847
deadbeef9d3584c2016-02-17 01:54:10848// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36849static const char kIceOption1[] = "iceoption1";
850static const char kIceOption2[] = "iceoption2";
851static const char kIceOption3[] = "iceoption3";
852
deadbeef9d3584c2016-02-17 01:54:10853// ICE ufrags/passwords.
854static const char kUfragVoice[] = "ufrag_voice";
855static const char kPwdVoice[] = "pwd_voice";
856static const char kUfragVideo[] = "ufrag_video";
857static const char kPwdVideo[] = "pwd_video";
858static const char kUfragData[] = "ufrag_data";
859static const char kPwdData[] = "pwd_data";
860
861// Extra ufrags/passwords for extra unified plan m= sections.
862static const char kUfragVoice2[] = "ufrag_voice_2";
863static const char kPwdVoice2[] = "pwd_voice_2";
Seth Hampson5b4f0752018-04-02 23:31:36864static const char kUfragVoice3[] = "ufrag_voice_3";
865static const char kPwdVoice3[] = "pwd_voice_3";
deadbeef9d3584c2016-02-17 01:54:10866static const char kUfragVideo2[] = "ufrag_video_2";
867static const char kPwdVideo2[] = "pwd_video_2";
868static const char kUfragVideo3[] = "ufrag_video_3";
869static const char kPwdVideo3[] = "pwd_video_3";
870
henrike@webrtc.org28e20752013-07-10 00:45:36871// Content name
872static const char kAudioContentName[] = "audio_content_name";
873static const char kVideoContentName[] = "video_content_name";
874static const char kDataContentName[] = "data_content_name";
875
deadbeef9d3584c2016-02-17 01:54:10876// Extra content names for extra unified plan m= sections.
877static const char kAudioContentName2[] = "audio_content_name_2";
Seth Hampson5b4f0752018-04-02 23:31:36878static const char kAudioContentName3[] = "audio_content_name_3";
deadbeef9d3584c2016-02-17 01:54:10879static const char kVideoContentName2[] = "video_content_name_2";
880static const char kVideoContentName3[] = "video_content_name_3";
881
henrike@webrtc.org28e20752013-07-10 00:45:36882// MediaStream 1
Seth Hampson845e8782018-03-02 19:34:10883static const char kStreamId1[] = "local_stream_1";
henrike@webrtc.org28e20752013-07-10 00:45:36884static const char kStream1Cname[] = "stream_1_cname";
885static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21886static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36887static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10888static const uint32_t kVideoTrack1Ssrc1 = 2;
889static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36890
891// MediaStream 2
Seth Hampson845e8782018-03-02 19:34:10892static const char kStreamId2[] = "local_stream_2";
henrike@webrtc.org28e20752013-07-10 00:45:36893static const char kStream2Cname[] = "stream_2_cname";
894static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21895static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10896static const char kVideoTrackId2[] = "video_track_id_2";
897static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36898static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10899static const uint32_t kVideoTrack3Ssrc = 6;
Seth Hampson5b4f0752018-04-02 23:31:36900static const char kAudioTrackId3[] = "audio_track_id_3";
901static const uint32_t kAudioTrack3Ssrc = 7;
henrike@webrtc.org28e20752013-07-10 00:45:36902
903// DataChannel
904static const char kDataChannelLabel[] = "data_channel";
905static const char kDataChannelMsid[] = "data_channeld0";
906static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 10:23:21907static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36908
909// Candidate
910static const char kDummyMid[] = "dummy_mid";
911static const int kDummyIndex = 123;
912
913// Misc
Steve Antona3a92c22017-12-07 18:27:41914static SdpType kDummyType = SdpType::kOffer;
henrike@webrtc.org28e20752013-07-10 00:45:36915
916// Helper functions
917
918static bool SdpDeserialize(const std::string& message,
919 JsepSessionDescription* jdesc) {
920 return webrtc::SdpDeserialize(message, jdesc, NULL);
921}
922
923static bool SdpDeserializeCandidate(const std::string& message,
924 JsepIceCandidate* candidate) {
925 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
926}
927
928// Add some extra |newlines| to the |message| after |line|.
929static void InjectAfter(const std::string& line,
930 const std::string& newlines,
931 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09932 absl::StrReplaceAll({{line, line + newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36933}
934
935static void Replace(const std::string& line,
936 const std::string& newlines,
937 std::string* message) {
Steve Anton1c9c9fc2019-02-14 23:13:09938 absl::StrReplaceAll({{line, newlines}}, message);
henrike@webrtc.org28e20752013-07-10 00:45:36939}
940
wu@webrtc.org5e760e72014-04-02 23:19:09941// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
942// message.
943static void ExpectParseFailure(const std::string& bad_sdp,
944 const std::string& bad_part) {
Steve Antona3a92c22017-12-07 18:27:41945 JsepSessionDescription desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:36946 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09947 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36948 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09949 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
950}
951
952// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
953static void ExpectParseFailure(const char* good_part, const char* bad_part) {
954 std::string bad_sdp = kSdpFullString;
955 Replace(good_part, bad_part, &bad_sdp);
956 ExpectParseFailure(bad_sdp, bad_part);
957}
958
959// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
960static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
961 const std::string& newlines,
962 const std::string& bad_part) {
963 std::string bad_sdp = kSdpFullString;
964 InjectAfter(injectpoint, newlines, &bad_sdp);
965 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36966}
967
Steve Anton4e70a722017-11-28 22:57:10968static void ReplaceDirection(RtpTransceiverDirection direction,
henrike@webrtc.org28e20752013-07-10 00:45:36969 std::string* message) {
970 std::string new_direction;
971 switch (direction) {
Steve Anton4e70a722017-11-28 22:57:10972 case RtpTransceiverDirection::kInactive:
henrike@webrtc.org28e20752013-07-10 00:45:36973 new_direction = "a=inactive";
974 break;
Steve Anton4e70a722017-11-28 22:57:10975 case RtpTransceiverDirection::kSendOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36976 new_direction = "a=sendonly";
977 break;
Steve Anton4e70a722017-11-28 22:57:10978 case RtpTransceiverDirection::kRecvOnly:
henrike@webrtc.org28e20752013-07-10 00:45:36979 new_direction = "a=recvonly";
980 break;
Steve Anton4e70a722017-11-28 22:57:10981 case RtpTransceiverDirection::kSendRecv:
henrike@webrtc.org28e20752013-07-10 00:45:36982 default:
983 new_direction = "a=sendrecv";
984 break;
985 }
986 Replace("a=sendrecv", new_direction, message);
987}
988
Yves Gerey665174f2018-06-19 13:03:05989static void ReplaceRejected(bool audio_rejected,
990 bool video_rejected,
henrike@webrtc.org28e20752013-07-10 00:45:36991 std::string* message) {
992 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14993 Replace("m=audio 9", "m=audio 0", message);
994 Replace(kAttributeIceUfragVoice, "", message);
995 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36996 }
997 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14998 Replace("m=video 9", "m=video 0", message);
999 Replace(kAttributeIceUfragVideo, "", message);
1000 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:361001 }
1002}
1003
1004// WebRtcSdpTest
1005
Mirko Bonadei6a489f22019-04-09 13:11:121006class WebRtcSdpTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:361007 public:
Steve Antona3a92c22017-12-07 18:27:411008 WebRtcSdpTest() : jdesc_(kDummyType) {
phoglund37ebcf02016-01-08 13:04:571009#ifdef WEBRTC_ANDROID
1010 webrtc::InitializeAndroidObjects();
1011#endif
henrike@webrtc.org28e20752013-07-10 00:45:361012 // AudioContentDescription
1013 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:101014 StreamParams audio_stream;
1015 audio_stream.id = kAudioTrackId1;
1016 audio_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101017 audio_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101018 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
1019 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 18:04:531020 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
1021 audio_desc_->set_connection_address(audio_addr);
Harald Alvestrand1716d392019-06-03 18:35:451022 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1023 absl::WrapUnique(audio_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361024
1025 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:101026 video_desc_ = CreateVideoContentDescription();
1027 StreamParams video_stream;
1028 video_stream.id = kVideoTrackId1;
1029 video_stream.cname = kStream1Cname;
Seth Hampson845e8782018-03-02 19:34:101030 video_stream.set_stream_ids({kStreamId1});
deadbeef9d3584c2016-02-17 01:54:101031 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
1032 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
1033 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
1034 video_stream.ssrc_groups.push_back(ssrc_group);
1035 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 18:04:531036 rtc::SocketAddress video_addr("74.125.224.39", 3457);
1037 video_desc_->set_connection_address(video_addr);
Harald Alvestrand1716d392019-06-03 18:35:451038 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1039 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361040
1041 // TransportInfo
Steve Anton06817cd2018-12-18 23:55:301042 desc_.AddTransportInfo(TransportInfo(
1043 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)));
1044 desc_.AddTransportInfo(TransportInfo(
1045 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)));
henrike@webrtc.org28e20752013-07-10 00:45:361046
1047 // v4 host
1048 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521049 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071050 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311051 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1052 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361053 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071054 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311055 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1056 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361057 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071058 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311059 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1060 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361061 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071062 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:311063 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
1064 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:361065
1066 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521067 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071068 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1069 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311070 cricket::LOCAL_PORT_TYPE,
1071 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361072 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071073 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1074 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311075 cricket::LOCAL_PORT_TYPE,
1076 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361077 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071078 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1079 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311080 cricket::LOCAL_PORT_TYPE,
1081 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361082 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:071083 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1084 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:311085 cricket::LOCAL_PORT_TYPE,
1086 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:361087
1088 // stun
1089 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521090 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
1091 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071092 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1093 address_stun, kCandidatePriority, "", "",
1094 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311095 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361096 candidate9.set_related_address(rel_address_stun);
1097
1098 address_stun.SetPort(port_stun++);
1099 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:071100 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1101 address_stun, kCandidatePriority, "", "",
1102 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311103 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:361104 candidate10.set_related_address(rel_address_stun);
1105
1106 // relay
1107 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521108 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071109 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
1110 address_relay, kCandidatePriority, "", "",
1111 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:311112 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361113 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:071114 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1115 address_relay, kCandidatePriority, "", "",
1116 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:311117 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:361118
1119 // voice
1120 candidates_.push_back(candidate1);
1121 candidates_.push_back(candidate2);
1122 candidates_.push_back(candidate5);
1123 candidates_.push_back(candidate6);
1124 candidates_.push_back(candidate9);
1125 candidates_.push_back(candidate10);
1126
1127 // video
1128 candidates_.push_back(candidate3);
1129 candidates_.push_back(candidate4);
1130 candidates_.push_back(candidate7);
1131 candidates_.push_back(candidate8);
1132 candidates_.push_back(candidate11);
1133 candidates_.push_back(candidate12);
1134
Yves Gerey665174f2018-06-19 13:03:051135 jcandidate_.reset(
1136 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:361137
1138 // Set up JsepSessionDescription.
Harald Alvestrand4d7160e2019-04-12 05:01:291139 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
henrike@webrtc.org28e20752013-07-10 00:45:361140 std::string mline_id;
1141 int mline_index = 0;
Yves Gerey665174f2018-06-19 13:03:051142 for (size_t i = 0; i < candidates_.size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361143 // In this test, the audio m line index will be 0, and the video m line
1144 // will be 1.
1145 bool is_video = (i > 5);
1146 mline_id = is_video ? "video_content_name" : "audio_content_name";
1147 mline_index = is_video ? 1 : 0;
Yves Gerey665174f2018-06-19 13:03:051148 JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i));
henrike@webrtc.org28e20752013-07-10 00:45:361149 jdesc_.AddCandidate(&jice);
1150 }
1151 }
1152
Seth Hampson5b4f0752018-04-02 23:31:361153 void RemoveVideoCandidates() {
deadbeef25ed4352016-12-13 02:37:361154 const IceCandidateCollection* video_candidates_collection =
1155 jdesc_.candidates(1);
1156 ASSERT_NE(nullptr, video_candidates_collection);
1157 std::vector<cricket::Candidate> video_candidates;
1158 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1159 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1160 c.set_transport_name("video_content_name");
1161 video_candidates.push_back(c);
1162 }
1163 jdesc_.RemoveCandidates(video_candidates);
Seth Hampson5b4f0752018-04-02 23:31:361164 }
1165
1166 // Turns the existing reference description into a description using
1167 // a=bundle-only. This means no transport attributes and a 0 port value on
1168 // the m= sections not associated with the BUNDLE-tag.
1169 void MakeBundleOnlyDescription() {
1170 RemoveVideoCandidates();
deadbeef25ed4352016-12-13 02:37:361171
1172 // And the rest of the transport attributes.
1173 desc_.transport_infos()[1].description.ice_ufrag.clear();
1174 desc_.transport_infos()[1].description.ice_pwd.clear();
1175 desc_.transport_infos()[1].description.connection_role =
1176 cricket::CONNECTIONROLE_NONE;
1177
1178 // Set bundle-only flag.
1179 desc_.contents()[1].bundle_only = true;
1180
1181 // Add BUNDLE group.
1182 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1183 group.AddContentName(kAudioContentName);
1184 group.AddContentName(kVideoContentName);
1185 desc_.AddGroup(group);
1186
Harald Alvestrand4d7160e2019-04-12 05:01:291187 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef25ed4352016-12-13 02:37:361188 jdesc_.session_version()));
1189 }
1190
deadbeef9d3584c2016-02-17 01:54:101191 // Turns the existing reference description into a plan B description,
1192 // with 2 audio tracks and 3 video tracks.
1193 void MakePlanBDescription() {
Steve Antonb1c1de12017-12-21 23:14:301194 audio_desc_ = audio_desc_->Copy();
1195 video_desc_ = video_desc_->Copy();
deadbeef9d3584c2016-02-17 01:54:101196
1197 StreamParams audio_track_2;
1198 audio_track_2.id = kAudioTrackId2;
1199 audio_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101200 audio_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101201 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1202 audio_desc_->AddStream(audio_track_2);
1203
1204 StreamParams video_track_2;
1205 video_track_2.id = kVideoTrackId2;
1206 video_track_2.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101207 video_track_2.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101208 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1209 video_desc_->AddStream(video_track_2);
1210
1211 StreamParams video_track_3;
1212 video_track_3.id = kVideoTrackId3;
1213 video_track_3.cname = kStream2Cname;
Seth Hampson845e8782018-03-02 19:34:101214 video_track_3.set_stream_ids({kStreamId2});
deadbeef9d3584c2016-02-17 01:54:101215 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1216 video_desc_->AddStream(video_track_3);
1217
1218 desc_.RemoveContentByName(kAudioContentName);
1219 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451220 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1221 absl::WrapUnique(audio_desc_));
1222 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1223 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101224
Harald Alvestrand4d7160e2019-04-12 05:01:291225 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101226 jdesc_.session_version()));
1227 }
1228
1229 // Turns the existing reference description into a unified plan description,
1230 // with 2 audio tracks and 3 video tracks.
Amit Hilbuchc57d5732018-12-11 23:30:111231 void MakeUnifiedPlanDescription(bool use_ssrcs = true) {
deadbeef9d3584c2016-02-17 01:54:101232 // Audio track 2.
1233 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1234 StreamParams audio_track_2;
1235 audio_track_2.id = kAudioTrackId2;
Seth Hampson845e8782018-03-02 19:34:101236 audio_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111237 if (use_ssrcs) {
1238 audio_track_2.cname = kStream2Cname;
1239 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1240 }
deadbeef9d3584c2016-02-17 01:54:101241 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451242 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1243 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301244 desc_.AddTransportInfo(TransportInfo(
1245 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
deadbeef9d3584c2016-02-17 01:54:101246 // Video track 2, in stream 2.
1247 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1248 StreamParams video_track_2;
1249 video_track_2.id = kVideoTrackId2;
Seth Hampson845e8782018-03-02 19:34:101250 video_track_2.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111251 if (use_ssrcs) {
1252 video_track_2.cname = kStream2Cname;
1253 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1254 }
deadbeef9d3584c2016-02-17 01:54:101255 video_desc_2->AddStream(video_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451256 desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp,
1257 absl::WrapUnique(video_desc_2));
Steve Anton06817cd2018-12-18 23:55:301258 desc_.AddTransportInfo(TransportInfo(
1259 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)));
deadbeef9d3584c2016-02-17 01:54:101260
1261 // Video track 3, in stream 2.
1262 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1263 StreamParams video_track_3;
1264 video_track_3.id = kVideoTrackId3;
Seth Hampson845e8782018-03-02 19:34:101265 video_track_3.set_stream_ids({kStreamId2});
Amit Hilbuchc57d5732018-12-11 23:30:111266 if (use_ssrcs) {
1267 video_track_3.cname = kStream2Cname;
1268 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1269 }
deadbeef9d3584c2016-02-17 01:54:101270 video_desc_3->AddStream(video_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451271 desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp,
1272 absl::WrapUnique(video_desc_3));
Steve Anton06817cd2018-12-18 23:55:301273 desc_.AddTransportInfo(TransportInfo(
1274 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)));
Steve Antone831b8c2018-02-01 20:22:161275 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
deadbeef9d3584c2016-02-17 01:54:101276
Harald Alvestrand4d7160e2019-04-12 05:01:291277 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef9d3584c2016-02-17 01:54:101278 jdesc_.session_version()));
1279 }
1280
1281 // Creates an audio content description with no streams, and some default
1282 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361283 AudioContentDescription* CreateAudioContentDescription() {
1284 AudioContentDescription* audio = new AudioContentDescription();
1285 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511286 audio->set_rtcp_reduced_size(true);
Yves Gerey665174f2018-06-19 13:03:051287 audio->AddCrypto(CryptoParams(
1288 1, "AES_CM_128_HMAC_SHA1_32",
henrike@webrtc.org28e20752013-07-10 00:45:361289 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1290 "dummy_session_params"));
1291 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 17:07:161292 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-17 01:54:101293 audio->AddCodec(opus);
ossue1405ad2017-01-23 16:55:481294 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1295 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361296 return audio;
1297 }
1298
Seth Hampson5b4f0752018-04-02 23:31:361299 // Turns the existing reference description into a unified plan description,
1300 // with 3 audio MediaContentDescriptions with special StreamParams that
1301 // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id -
1302 // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids
Seth Hampson7fa6ee62018-10-17 17:25:281303 void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) {
Seth Hampson5b4f0752018-04-02 23:31:361304 desc_.RemoveContentByName(kVideoContentName);
1305 desc_.RemoveTransportInfoByName(kVideoContentName);
1306 RemoveVideoCandidates();
1307
1308 // Audio track 2 has 2 media stream ids.
1309 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1310 StreamParams audio_track_2;
1311 audio_track_2.id = kAudioTrackId2;
1312 audio_track_2.cname = kStream1Cname;
1313 audio_track_2.set_stream_ids({kStreamId1, kStreamId2});
1314 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1315 audio_desc_2->AddStream(audio_track_2);
Harald Alvestrand1716d392019-06-03 18:35:451316 desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp,
1317 absl::WrapUnique(audio_desc_2));
Steve Anton06817cd2018-12-18 23:55:301318 desc_.AddTransportInfo(TransportInfo(
1319 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)));
Seth Hampson5b4f0752018-04-02 23:31:361320
1321 // Audio track 3 has no stream ids.
1322 AudioContentDescription* audio_desc_3 = CreateAudioContentDescription();
1323 StreamParams audio_track_3;
1324 audio_track_3.id = kAudioTrackId3;
1325 audio_track_3.cname = kStream2Cname;
1326 audio_track_3.set_stream_ids({});
1327 audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc);
1328 audio_desc_3->AddStream(audio_track_3);
Harald Alvestrand1716d392019-06-03 18:35:451329 desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp,
1330 absl::WrapUnique(audio_desc_3));
Steve Anton06817cd2018-12-18 23:55:301331 desc_.AddTransportInfo(TransportInfo(
1332 kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3)));
Seth Hampson7fa6ee62018-10-17 17:25:281333 desc_.set_msid_signaling(msid_signaling);
Harald Alvestrand4d7160e2019-04-12 05:01:291334 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5b4f0752018-04-02 23:31:361335 jdesc_.session_version()));
1336 }
1337
Seth Hampson5897a6e2018-04-03 18:16:331338 // Turns the existing reference description into a unified plan description
1339 // with one audio MediaContentDescription that contains one StreamParams with
1340 // 0 ssrcs.
1341 void MakeUnifiedPlanDescriptionNoSsrcSignaling() {
1342 desc_.RemoveContentByName(kVideoContentName);
1343 desc_.RemoveContentByName(kAudioContentName);
1344 desc_.RemoveTransportInfoByName(kVideoContentName);
1345 RemoveVideoCandidates();
1346
1347 AudioContentDescription* audio_desc = CreateAudioContentDescription();
1348 StreamParams audio_track;
1349 audio_track.id = kAudioTrackId1;
1350 audio_track.set_stream_ids({kStreamId1});
1351 audio_desc->AddStream(audio_track);
Harald Alvestrand1716d392019-06-03 18:35:451352 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1353 absl::WrapUnique(audio_desc));
Seth Hampson5897a6e2018-04-03 18:16:331354
1355 // Enable signaling a=msid lines.
1356 desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection);
Harald Alvestrand4d7160e2019-04-12 05:01:291357 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
Seth Hampson5897a6e2018-04-03 18:16:331358 jdesc_.session_version()));
1359 }
1360
deadbeef9d3584c2016-02-17 01:54:101361 // Creates a video content description with no streams, and some default
1362 // configuration.
1363 VideoContentDescription* CreateVideoContentDescription() {
1364 VideoContentDescription* video = new VideoContentDescription();
1365 video->AddCrypto(CryptoParams(
1366 1, "AES_CM_128_HMAC_SHA1_80",
1367 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1368 video->set_protocol(cricket::kMediaProtocolSavpf);
1369 video->AddCodec(
perkj26752742016-10-24 08:21:161370 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-17 01:54:101371 return video;
1372 }
1373
henrike@webrtc.org28e20752013-07-10 00:45:361374 template <class MCD>
Yves Gerey665174f2018-06-19 13:03:051375 void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) {
henrike@webrtc.org28e20752013-07-10 00:45:361376 // type
Harald Alvestrand1716d392019-06-03 18:35:451377 EXPECT_EQ(cd1->type(), cd2->type());
henrike@webrtc.org28e20752013-07-10 00:45:361378
1379 // content direction
1380 EXPECT_EQ(cd1->direction(), cd2->direction());
1381
1382 // rtcp_mux
1383 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1384
deadbeef13871492015-12-09 20:37:511385 // rtcp_reduced_size
1386 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1387
henrike@webrtc.org28e20752013-07-10 00:45:361388 // cryptos
1389 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1390 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1391 ADD_FAILURE();
1392 return;
1393 }
Yves Gerey665174f2018-06-19 13:03:051394 for (size_t i = 0; i < cd1->cryptos().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361395 const CryptoParams c1 = cd1->cryptos().at(i);
1396 const CryptoParams c2 = cd2->cryptos().at(i);
1397 EXPECT_TRUE(c1.Matches(c2));
1398 EXPECT_EQ(c1.key_params, c2.key_params);
1399 EXPECT_EQ(c1.session_params, c2.session_params);
1400 }
lally@webrtc.orgd7b61652015-02-24 20:18:551401
henrike@webrtc.org28e20752013-07-10 00:45:361402 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551403 // Use an equivalence class here, for old and new versions of the
1404 // protocol description.
Yves Gerey665174f2018-06-19 13:03:051405 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp ||
1406 cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1407 cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
lally@webrtc.org36300852015-02-24 20:19:351408 const bool cd2_is_also_dtls_sctp =
Yves Gerey665174f2018-06-19 13:03:051409 cd2->protocol() == cricket::kMediaProtocolDtlsSctp ||
1410 cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp ||
1411 cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
lally@webrtc.org36300852015-02-24 20:19:351412 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551413 } else {
1414 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1415 }
henrike@webrtc.org28e20752013-07-10 00:45:361416
1417 // codecs
1418 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1419
1420 // bandwidth
1421 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1422
1423 // streams
1424 EXPECT_EQ(cd1->streams(), cd2->streams());
1425
Johannes Kron0854eb62018-10-10 20:33:201426 // extmap-allow-mixed
Johannes Kron9581bc42018-10-23 08:17:391427 EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum());
Johannes Kron0854eb62018-10-10 20:33:201428
henrike@webrtc.org28e20752013-07-10 00:45:361429 // extmap
1430 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1431 cd2->rtp_header_extensions().size());
Yves Gerey665174f2018-06-19 13:03:051432 for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 18:24:551433 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1434 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:361435 EXPECT_EQ(ext1.uri, ext2.uri);
1436 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 19:31:361437 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:361438 }
henrike@webrtc.org28e20752013-07-10 00:45:361439 }
1440
Amit Hilbuchc57d5732018-12-11 23:30:111441 void CompareRidDescriptionIds(const std::vector<RidDescription>& rids,
1442 const std::vector<std::string>& ids) {
1443 // Order of elements does not matter, only equivalence of sets.
1444 EXPECT_EQ(rids.size(), ids.size());
1445 for (const std::string& id : ids) {
Steve Anton64b626b2019-01-29 01:25:261446 EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) {
1447 return rid.rid == id;
1448 }));
Amit Hilbuchc57d5732018-12-11 23:30:111449 }
1450 }
1451
Amit Hilbucha2012042018-12-03 19:35:051452 void CompareSimulcastDescription(const SimulcastDescription& simulcast1,
1453 const SimulcastDescription& simulcast2) {
1454 EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size());
1455 EXPECT_EQ(simulcast1.receive_layers().size(),
1456 simulcast2.receive_layers().size());
1457 }
1458
Harald Alvestrand5fc28b12019-05-13 11:36:161459 void CompareRtpDataContentDescription(const RtpDataContentDescription* dcd1,
1460 const RtpDataContentDescription* dcd2) {
1461 CompareMediaContentDescription<RtpDataContentDescription>(dcd1, dcd2);
1462 }
1463
1464 void CompareSctpDataContentDescription(
1465 const SctpDataContentDescription* dcd1,
1466 const SctpDataContentDescription* dcd2) {
Harald Alvestrand26bf7c42019-04-23 05:20:171467 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
Harald Alvestrand5fc28b12019-05-13 11:36:161468 EXPECT_EQ(dcd1->port(), dcd2->port());
1469 EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size());
Harald Alvestrand26bf7c42019-04-23 05:20:171470 }
1471
henrike@webrtc.org28e20752013-07-10 00:45:361472 void CompareSessionDescription(const SessionDescription& desc1,
1473 const SessionDescription& desc2) {
1474 // Compare content descriptions.
1475 if (desc1.contents().size() != desc2.contents().size()) {
1476 ADD_FAILURE();
1477 return;
1478 }
Yves Gerey665174f2018-06-19 13:03:051479 for (size_t i = 0; i < desc1.contents().size(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:361480 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1481 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-13 02:37:361482 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:361483 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-13 02:37:361484 EXPECT_EQ(c1.type, c2.type);
1485 EXPECT_EQ(c1.rejected, c2.rejected);
1486 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:361487
1488 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1489 if (IsAudioContent(&c1)) {
1490 const AudioContentDescription* acd1 =
Steve Antonb1c1de12017-12-21 23:14:301491 c1.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361492 const AudioContentDescription* acd2 =
Steve Antonb1c1de12017-12-21 23:14:301493 c2.media_description()->as_audio();
henrike@webrtc.org28e20752013-07-10 00:45:361494 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1495 }
1496
1497 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1498 if (IsVideoContent(&c1)) {
1499 const VideoContentDescription* vcd1 =
Steve Antonb1c1de12017-12-21 23:14:301500 c1.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361501 const VideoContentDescription* vcd2 =
Steve Antonb1c1de12017-12-21 23:14:301502 c2.media_description()->as_video();
henrike@webrtc.org28e20752013-07-10 00:45:361503 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1504 }
1505
1506 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
Harald Alvestrand5fc28b12019-05-13 11:36:161507 if (c1.media_description()->as_sctp()) {
1508 ASSERT_TRUE(c2.media_description()->as_sctp());
1509 const SctpDataContentDescription* scd1 =
1510 c1.media_description()->as_sctp();
1511 const SctpDataContentDescription* scd2 =
1512 c2.media_description()->as_sctp();
1513 CompareSctpDataContentDescription(scd1, scd2);
1514 } else {
1515 if (IsDataContent(&c1)) {
1516 const RtpDataContentDescription* dcd1 =
1517 c1.media_description()->as_rtp_data();
1518 const RtpDataContentDescription* dcd2 =
1519 c2.media_description()->as_rtp_data();
1520 CompareRtpDataContentDescription(dcd1, dcd2);
1521 }
henrike@webrtc.org28e20752013-07-10 00:45:361522 }
Amit Hilbucha2012042018-12-03 19:35:051523
1524 CompareSimulcastDescription(
1525 c1.media_description()->simulcast_description(),
1526 c2.media_description()->simulcast_description());
Bjorn A Mellem8e1343a2019-09-30 22:12:471527 EXPECT_EQ(c1.media_description()->alt_protocol(),
1528 c2.media_description()->alt_protocol());
henrike@webrtc.org28e20752013-07-10 00:45:361529 }
1530
1531 // group
1532 const cricket::ContentGroups groups1 = desc1.groups();
1533 const cricket::ContentGroups groups2 = desc2.groups();
1534 EXPECT_EQ(groups1.size(), groups1.size());
1535 if (groups1.size() != groups2.size()) {
1536 ADD_FAILURE();
1537 return;
1538 }
1539 for (size_t i = 0; i < groups1.size(); ++i) {
1540 const cricket::ContentGroup group1 = groups1.at(i);
1541 const cricket::ContentGroup group2 = groups2.at(i);
1542 EXPECT_EQ(group1.semantics(), group2.semantics());
1543 const cricket::ContentNames names1 = group1.content_names();
1544 const cricket::ContentNames names2 = group2.content_names();
1545 EXPECT_EQ(names1.size(), names2.size());
1546 if (names1.size() != names2.size()) {
1547 ADD_FAILURE();
1548 return;
1549 }
1550 cricket::ContentNames::const_iterator iter1 = names1.begin();
1551 cricket::ContentNames::const_iterator iter2 = names2.begin();
1552 while (iter1 != names1.end()) {
1553 EXPECT_EQ(*iter1++, *iter2++);
1554 }
1555 }
1556
1557 // transport info
1558 const cricket::TransportInfos transports1 = desc1.transport_infos();
1559 const cricket::TransportInfos transports2 = desc2.transport_infos();
1560 EXPECT_EQ(transports1.size(), transports2.size());
1561 if (transports1.size() != transports2.size()) {
1562 ADD_FAILURE();
1563 return;
1564 }
1565 for (size_t i = 0; i < transports1.size(); ++i) {
1566 const cricket::TransportInfo transport1 = transports1.at(i);
1567 const cricket::TransportInfo transport2 = transports2.at(i);
1568 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361569 EXPECT_EQ(transport1.description.ice_ufrag,
1570 transport2.description.ice_ufrag);
Yves Gerey665174f2018-06-19 13:03:051571 EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd);
Taylor Brandstetter2f65ec52018-05-24 18:37:281572 EXPECT_EQ(transport1.description.ice_mode,
1573 transport2.description.ice_mode);
henrike@webrtc.org28e20752013-07-10 00:45:361574 if (transport1.description.identity_fingerprint) {
1575 EXPECT_EQ(*transport1.description.identity_fingerprint,
1576 *transport2.description.identity_fingerprint);
1577 } else {
1578 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1579 transport2.description.identity_fingerprint.get());
1580 }
1581 EXPECT_EQ(transport1.description.transport_options,
1582 transport2.description.transport_options);
Bjorn A Mellemc85ebbe2019-06-07 17:28:061583 EXPECT_EQ(transport1.description.opaque_parameters,
1584 transport2.description.opaque_parameters);
henrike@webrtc.org28e20752013-07-10 00:45:361585 }
deadbeefc80741f2015-10-22 20:14:451586
1587 // global attributes
1588 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
Johannes Kron9581bc42018-10-23 08:17:391589 EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed());
henrike@webrtc.org28e20752013-07-10 00:45:361590 }
1591
Yves Gerey665174f2018-06-19 13:03:051592 bool CompareSessionDescription(const JsepSessionDescription& desc1,
1593 const JsepSessionDescription& desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:361594 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1595 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1596 CompareSessionDescription(*desc1.description(), *desc2.description());
1597 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1598 return false;
1599 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1600 const IceCandidateCollection* cc1 = desc1.candidates(i);
1601 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-13 02:37:361602 if (cc1->count() != cc2->count()) {
1603 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:361604 return false;
deadbeef25ed4352016-12-13 02:37:361605 }
henrike@webrtc.org28e20752013-07-10 00:45:361606 for (size_t j = 0; j < cc1->count(); ++j) {
1607 const IceCandidateInterface* c1 = cc1->at(j);
1608 const IceCandidateInterface* c2 = cc2->at(j);
1609 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1610 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1611 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1612 }
1613 }
1614 return true;
1615 }
1616
1617 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1618 // them with invalid keywords so that the parser will just ignore them.
1619 bool RemoveCandidateUfragPwd(std::string* sdp) {
Steve Anton1c9c9fc2019-02-14 23:13:091620 absl::StrReplaceAll(
1621 {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:361622 return true;
1623 }
1624
1625 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
Yves Gerey665174f2018-06-19 13:03:051626 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc,
1627 int mline_index,
1628 const std::string& ufrag,
1629 const std::string& pwd) {
henrike@webrtc.org28e20752013-07-10 00:45:361630 std::string content_name;
1631 if (mline_index == 0) {
1632 content_name = kAudioContentName;
1633 } else if (mline_index == 1) {
1634 content_name = kVideoContentName;
1635 } else {
nissec80e7412017-01-11 13:56:461636 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:361637 }
Yves Gerey665174f2018-06-19 13:03:051638 TransportInfo transport_info(content_name,
1639 TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361640 SessionDescription* desc =
1641 const_cast<SessionDescription*>(jdesc->description());
1642 desc->RemoveTransportInfoByName(content_name);
Steve Anton06817cd2018-12-18 23:55:301643 desc->AddTransportInfo(transport_info);
henrike@webrtc.org28e20752013-07-10 00:45:361644 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1645 const IceCandidateCollection* cc = jdesc_.candidates(i);
1646 for (size_t j = 0; j < cc->count(); ++j) {
1647 if (cc->at(j)->sdp_mline_index() == mline_index) {
Yves Gerey665174f2018-06-19 13:03:051648 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag);
1649 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd);
henrike@webrtc.org28e20752013-07-10 00:45:361650 }
1651 }
1652 }
1653 return true;
1654 }
1655
1656 void AddIceOptions(const std::string& content_name,
1657 const std::vector<std::string>& transport_options) {
1658 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1659 cricket::TransportInfo transport_info =
1660 *(desc_.GetTransportInfoByName(content_name));
1661 desc_.RemoveTransportInfoByName(content_name);
1662 transport_info.description.transport_options = transport_options;
1663 desc_.AddTransportInfo(transport_info);
1664 }
1665
deadbeef3f7219b2015-12-28 23:17:141666 void SetIceUfragPwd(const std::string& content_name,
1667 const std::string& ice_ufrag,
1668 const std::string& ice_pwd) {
1669 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1670 cricket::TransportInfo transport_info =
1671 *(desc_.GetTransportInfoByName(content_name));
1672 desc_.RemoveTransportInfoByName(content_name);
1673 transport_info.description.ice_ufrag = ice_ufrag;
1674 transport_info.description.ice_pwd = ice_pwd;
1675 desc_.AddTransportInfo(transport_info);
1676 }
1677
Bjorn A Mellemc85ebbe2019-06-07 17:28:061678 void AddOpaqueTransportParameters(const std::string& content_name,
1679 cricket::OpaqueTransportParameters params) {
1680 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1681 cricket::TransportInfo info = *(desc_.GetTransportInfoByName(content_name));
1682 desc_.RemoveTransportInfoByName(content_name);
1683 info.description.opaque_parameters = params;
1684 desc_.AddTransportInfo(info);
1685 }
1686
Bjorn A Mellem8e1343a2019-09-30 22:12:471687 void AddAltProtocol(const std::string& content_name,
1688 const std::string& alt_protocol) {
1689 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1690 cricket::MediaContentDescription* description =
1691 desc_.GetContentDescriptionByName(content_name);
1692 description->set_alt_protocol(alt_protocol);
1693 }
1694
henrike@webrtc.org28e20752013-07-10 00:45:361695 void AddFingerprint() {
1696 desc_.RemoveTransportInfoByName(kAudioContentName);
1697 desc_.RemoveTransportInfoByName(kVideoContentName);
Steve Anton4905edb2018-10-16 02:27:441698 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest);
Steve Anton06817cd2018-12-18 23:55:301699 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371700 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101701 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1702 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301703 cricket::CONNECTIONROLE_NONE, &fingerprint)));
1704 desc_.AddTransportInfo(TransportInfo(
deadbeef46eed762016-01-28 21:24:371705 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101706 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1707 cricket::ICEMODE_FULL,
Steve Anton06817cd2018-12-18 23:55:301708 cricket::CONNECTIONROLE_NONE, &fingerprint)));
henrike@webrtc.org28e20752013-07-10 00:45:361709 }
1710
jbauch5869f502017-06-29 19:31:361711 void AddExtmap(bool encrypted) {
Steve Antonb1c1de12017-12-21 23:14:301712 audio_desc_ = audio_desc_->Copy();
1713 video_desc_ = video_desc_->Copy();
jbauch5869f502017-06-29 19:31:361714 audio_desc_->AddRtpHeaderExtension(
1715 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1716 video_desc_->AddRtpHeaderExtension(
1717 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:361718 desc_.RemoveContentByName(kAudioContentName);
1719 desc_.RemoveContentByName(kVideoContentName);
Harald Alvestrand1716d392019-06-03 18:35:451720 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp,
1721 absl::WrapUnique(audio_desc_));
1722 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp,
1723 absl::WrapUnique(video_desc_));
henrike@webrtc.org28e20752013-07-10 00:45:361724 }
1725
1726 void RemoveCryptos() {
1727 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1728 video_desc_->set_cryptos(std::vector<CryptoParams>());
1729 }
1730
Seth Hampson5897a6e2018-04-03 18:16:331731 // Removes everything in StreamParams from the session description that is
1732 // used for a=ssrc lines.
1733 void RemoveSsrcSignalingFromStreamParams() {
Harald Alvestrand1716d392019-06-03 18:35:451734 for (cricket::ContentInfo& content_info :
1735 jdesc_.description()->contents()) {
Seth Hampson5897a6e2018-04-03 18:16:331736 // With Unified Plan there should be one StreamParams per m= section.
1737 StreamParams& stream =
1738 content_info.media_description()->mutable_streams()[0];
1739 stream.ssrcs.clear();
1740 stream.ssrc_groups.clear();
1741 stream.cname.clear();
1742 }
1743 }
1744
Seth Hampson7fa6ee62018-10-17 17:25:281745 // Removes all a=ssrc lines from the SDP string, except for the
1746 // "a=ssrc:... cname:..." lines.
1747 void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) {
1748 const char kAttributeSsrc[] = "a=ssrc";
1749 const char kAttributeCname[] = "cname";
1750 size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc);
1751 while (ssrc_line_pos != std::string::npos) {
1752 size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos);
1753 size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos);
1754 size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos);
1755 if (cname_pos == std::string::npos || cname_pos > end_line_pos) {
1756 // Only erase a=ssrc lines that don't contain "cname".
1757 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1758 ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos);
1759 } else {
1760 // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line.
1761 ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos);
1762 }
1763 }
1764 }
1765
Seth Hampson5897a6e2018-04-03 18:16:331766 // Removes all a=ssrc lines from the SDP string.
1767 void RemoveSsrcLinesFromSdpString(std::string* sdp_string) {
1768 const char kAttributeSsrc[] = "a=ssrc";
1769 while (sdp_string->find(kAttributeSsrc) != std::string::npos) {
1770 size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc);
1771 size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute);
1772 size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute);
1773 sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos);
1774 }
1775 }
1776
Steve Anton4e70a722017-11-28 22:57:101777 bool TestSerializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361778 audio_desc_->set_direction(direction);
1779 video_desc_->set_direction(direction);
1780 std::string new_sdp = kSdpFullString;
1781 ReplaceDirection(direction, &new_sdp);
1782
Harald Alvestrand4d7160e2019-04-12 05:01:291783 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361784 jdesc_.session_version())) {
1785 return false;
1786 }
Steve Antone831b8c2018-02-01 20:22:161787 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:361788 EXPECT_EQ(new_sdp, message);
1789 return true;
1790 }
1791
1792 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
Steve Antonb1c1de12017-12-21 23:14:301793 audio_desc_ = audio_desc_->Copy();
1794 video_desc_ = video_desc_->Copy();
zhihuang38989e52017-03-21 18:04:531795
henrike@webrtc.org28e20752013-07-10 00:45:361796 desc_.RemoveContentByName(kAudioContentName);
1797 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001798 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451799 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001800 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451801 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101802 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1803 audio_rejected ? "" : kPwdVoice);
1804 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1805 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141806
1807 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361808 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1809
Steve Antona3a92c22017-12-07 18:27:411810 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:531811 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:161812 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:361813 EXPECT_EQ(new_sdp, message);
1814 return true;
1815 }
1816
zstein4b2e0822017-02-18 03:48:381817 void AddSctpDataChannel(bool use_sctpmap) {
Harald Alvestrand5fc28b12019-05-13 11:36:161818 std::unique_ptr<SctpDataContentDescription> data(
1819 new SctpDataContentDescription());
1820 sctp_desc_ = data.get();
1821 sctp_desc_->set_use_sctpmap(use_sctpmap);
Guido Urdanetacecf87f2019-05-31 10:17:381822 sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp);
Harald Alvestrand5fc28b12019-05-13 11:36:161823 sctp_desc_->set_port(kDefaultSctpPort);
Steve Anton5adfafd2017-12-21 00:34:001824 desc_.AddContent(kDataContentName, MediaProtocolType::kSctp,
Harald Alvestrand1716d392019-06-03 18:35:451825 std::move(data));
Steve Anton06817cd2018-12-18 23:55:301826 desc_.AddTransportInfo(TransportInfo(
1827 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:361828 }
1829
1830 void AddRtpDataChannel() {
Harald Alvestrand5fc28b12019-05-13 11:36:161831 std::unique_ptr<RtpDataContentDescription> data(
1832 new RtpDataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361833 data_desc_ = data.get();
1834
deadbeef67cf2c12016-04-13 17:07:161835 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:361836 StreamParams data_stream;
1837 data_stream.id = kDataChannelMsid;
1838 data_stream.cname = kDataChannelCname;
Seth Hampson845e8782018-03-02 19:34:101839 data_stream.set_stream_ids({kDataChannelLabel});
henrike@webrtc.org28e20752013-07-10 00:45:361840 data_stream.ssrcs.push_back(kDataChannelSsrc);
1841 data_desc_->AddStream(data_stream);
Yves Gerey665174f2018-06-19 13:03:051842 data_desc_->AddCrypto(
1843 CryptoParams(1, "AES_CM_128_HMAC_SHA1_80",
1844 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
henrike@webrtc.org28e20752013-07-10 00:45:361845 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
Harald Alvestrand1716d392019-06-03 18:35:451846 desc_.AddContent(kDataContentName, MediaProtocolType::kRtp,
1847 std::move(data));
Steve Anton06817cd2018-12-18 23:55:301848 desc_.AddTransportInfo(TransportInfo(
1849 kDataContentName, TransportDescription(kUfragData, kPwdData)));
henrike@webrtc.org28e20752013-07-10 00:45:361850 }
1851
Steve Anton4e70a722017-11-28 22:57:101852 bool TestDeserializeDirection(RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:361853 std::string new_sdp = kSdpFullString;
1854 ReplaceDirection(direction, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411855 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:361856
1857 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1858
1859 audio_desc_->set_direction(direction);
1860 video_desc_->set_direction(direction);
Harald Alvestrand4d7160e2019-04-12 05:01:291861 if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361862 jdesc_.session_version())) {
1863 return false;
1864 }
1865 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1866 return true;
1867 }
1868
1869 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 23:17:141870 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361871 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
Steve Antona3a92c22017-12-07 18:27:411872 JsepSessionDescription new_jdesc(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361873 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141874
Steve Antonb1c1de12017-12-21 23:14:301875 audio_desc_ = audio_desc_->Copy();
1876 video_desc_ = video_desc_->Copy();
henrike@webrtc.org28e20752013-07-10 00:45:361877 desc_.RemoveContentByName(kAudioContentName);
1878 desc_.RemoveContentByName(kVideoContentName);
Steve Anton5adfafd2017-12-21 00:34:001879 desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451880 absl::WrapUnique(audio_desc_));
Steve Anton5adfafd2017-12-21 00:34:001881 desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected,
Harald Alvestrand1716d392019-06-03 18:35:451882 absl::WrapUnique(video_desc_));
deadbeef9d3584c2016-02-17 01:54:101883 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1884 audio_rejected ? "" : kPwdVoice);
1885 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1886 video_rejected ? "" : kPwdVideo);
Steve Antona3a92c22017-12-07 18:27:411887 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:291888 if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(),
deadbeef3f7219b2015-12-28 23:17:141889 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361890 return false;
1891 }
deadbeef3f7219b2015-12-28 23:17:141892 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361893 return true;
1894 }
1895
Yves Gerey665174f2018-06-19 13:03:051896 void TestDeserializeExtmap(bool session_level,
1897 bool media_level,
1898 bool encrypted) {
jbauch5869f502017-06-29 19:31:361899 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:411900 JsepSessionDescription new_jdesc(SdpType::kOffer);
Harald Alvestrand4d7160e2019-04-12 05:01:291901 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:361902 jdesc_.session_version()));
Steve Antona3a92c22017-12-07 18:27:411903 JsepSessionDescription jdesc_with_extmap(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361904 std::string sdp_with_extmap = kSdpString;
1905 if (session_level) {
jbauch5869f502017-06-29 19:31:361906 InjectAfter(kSessionTime,
1907 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1908 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361909 &sdp_with_extmap);
1910 }
1911 if (media_level) {
jbauch5869f502017-06-29 19:31:361912 InjectAfter(kAttributeIcePwdVoice,
1913 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1914 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361915 &sdp_with_extmap);
jbauch5869f502017-06-29 19:31:361916 InjectAfter(kAttributeIcePwdVideo,
1917 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1918 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361919 &sdp_with_extmap);
1920 }
1921 // The extmap can't be present at the same time in both session level and
1922 // media level.
1923 if (session_level && media_level) {
1924 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:051925 EXPECT_FALSE(
1926 webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error));
henrike@webrtc.org28e20752013-07-10 00:45:361927 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1928 } else {
1929 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1930 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1931 }
1932 }
1933
1934 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
Yves Gerey665174f2018-06-19 13:03:051935 const std::string& name,
1936 int expected_value) {
henrike@webrtc.org28e20752013-07-10 00:45:361937 cricket::CodecParameterMap::const_iterator found = params.find(name);
1938 ASSERT_TRUE(found != params.end());
Jonas Olsson6b1985d2018-07-05 09:59:481939 EXPECT_EQ(found->second, rtc::ToString(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361940 }
1941
1942 void TestDeserializeCodecParams(const CodecParams& params,
1943 JsepSessionDescription* jdesc_output) {
1944 std::string sdp =
1945 "v=0\r\n"
1946 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1947 "s=-\r\n"
1948 "t=0 0\r\n"
1949 // Include semantics for WebRTC Media Streams since it is supported by
1950 // this parser, and will be added to the SDP when serializing a session
1951 // description.
1952 "a=msid-semantic: WMS\r\n"
1953 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411954 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361955 // Pltype 111 listed before 103 and 104 in the map.
1956 "a=rtpmap:111 opus/48000/2\r\n"
1957 // Pltype 103 listed before 104.
1958 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411959 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151960 "a=fmtp:111 0-15,66,70\r\n"
1961 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361962 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241963 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151964 << "; sprop-stereo=" << params.sprop_stereo
1965 << "; useinbandfec=" << params.useinband
Jonas Olssonb2b20312020-01-14 11:11:311966 << "; maxaveragebitrate=" << params.maxaveragebitrate
1967 << "\r\n"
1968 "a=ptime:"
1969 << params.ptime
1970 << "\r\n"
1971 "a=maxptime:"
1972 << params.max_ptime << "\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361973 sdp += os.str();
1974
stefan@webrtc.org85d27942014-06-09 12:51:391975 os.clear();
1976 os.str("");
1977 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221978 os << "m=video 9 RTP/SAVPF 99 95\r\n"
Jonas Olssonb2b20312020-01-14 11:11:311979 "a=rtpmap:99 VP8/90000\r\n"
1980 "a=rtpmap:95 RTX/90000\r\n"
1981 "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391982 sdp += os.str();
1983
henrike@webrtc.org28e20752013-07-10 00:45:361984 // Deserialize
1985 SdpParseError error;
1986 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1987
henrike@webrtc.org28e20752013-07-10 00:45:361988 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:301989 GetFirstAudioContentDescription(jdesc_output->description());
1990 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:361991 ASSERT_FALSE(acd->codecs().empty());
1992 cricket::AudioCodec opus = acd->codecs()[0];
1993 EXPECT_EQ("opus", opus.name);
1994 EXPECT_EQ(111, opus.id);
1995 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1996 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1997 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1998 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591999 VerifyCodecParameter(opus.params, "maxaveragebitrate",
2000 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:362001 for (size_t i = 0; i < acd->codecs().size(); ++i) {
2002 cricket::AudioCodec codec = acd->codecs()[i];
2003 VerifyCodecParameter(codec.params, "ptime", params.ptime);
2004 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:362005 }
stefan@webrtc.org85d27942014-06-09 12:51:392006
stefan@webrtc.org85d27942014-06-09 12:51:392007 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302008 GetFirstVideoContentDescription(jdesc_output->description());
2009 ASSERT_TRUE(vcd);
stefan@webrtc.org85d27942014-06-09 12:51:392010 ASSERT_FALSE(vcd->codecs().empty());
2011 cricket::VideoCodec vp8 = vcd->codecs()[0];
2012 EXPECT_EQ("VP8", vp8.name);
2013 EXPECT_EQ(99, vp8.id);
2014 cricket::VideoCodec rtx = vcd->codecs()[1];
2015 EXPECT_EQ("RTX", rtx.name);
2016 EXPECT_EQ(95, rtx.id);
2017 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:362018 }
2019
2020 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
2021 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:462022 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:362023 "v=0\r\n"
2024 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2025 "s=-\r\n"
2026 "t=0 0\r\n"
2027 // Include semantics for WebRTC Media Streams since it is supported by
2028 // this parser, and will be added to the SDP when serializing a session
2029 // description.
2030 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:222031 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:462032 "a=rtpmap:111 opus/48000/2\r\n";
2033 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:362034 "m=video 3457 RTP/SAVPF 101\r\n"
2035 "a=rtpmap:101 VP8/90000\r\n"
Elad Alonfadb1812019-05-24 11:40:022036 "a=rtcp-fb:101 goog-lntf\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362037 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582038 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:462039 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362040 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:462041 os << sdp_session_and_audio;
Yves Gerey665174f2018-06-19 13:03:052042 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:462043 os << sdp_video;
Yves Gerey665174f2018-06-19 13:03:052044 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:462045 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:362046 // Deserialize
2047 SdpParseError error;
2048 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:362049 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:302050 GetFirstAudioContentDescription(jdesc_output->description());
2051 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:362052 ASSERT_FALSE(acd->codecs().empty());
2053 cricket::AudioCodec opus = acd->codecs()[0];
2054 EXPECT_EQ(111, opus.id);
Yves Gerey665174f2018-06-19 13:03:052055 EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam(
2056 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
henrike@webrtc.org28e20752013-07-10 00:45:362057
henrike@webrtc.org28e20752013-07-10 00:45:362058 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:302059 GetFirstVideoContentDescription(jdesc_output->description());
2060 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:362061 ASSERT_FALSE(vcd->codecs().empty());
2062 cricket::VideoCodec vp8 = vcd->codecs()[0];
2063 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
2064 vp8.name.c_str());
2065 EXPECT_EQ(101, vp8.id);
Yves Gerey665174f2018-06-19 13:03:052066 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Elad Alonfadb1812019-05-24 11:40:022067 cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty)));
2068 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
Yves Gerey665174f2018-06-19 13:03:052069 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty)));
2070 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2071 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli)));
2072 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2073 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty)));
2074 EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam(
2075 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir)));
henrike@webrtc.org28e20752013-07-10 00:45:362076 }
2077
2078 // Two SDP messages can mean the same thing but be different strings, e.g.
2079 // some of the lines can be serialized in different order.
2080 // However, a deserialized description can be compared field by field and has
2081 // no order. If deserializer has already been tested, serializing then
2082 // deserializing and comparing JsepSessionDescription will test
2083 // the serializer sufficiently.
Steve Antone831b8c2018-02-01 20:22:162084 void TestSerialize(const JsepSessionDescription& jdesc) {
2085 std::string message = webrtc::SdpSerialize(jdesc);
Steve Antona3a92c22017-12-07 18:27:412086 JsepSessionDescription jdesc_output_des(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362087 SdpParseError error;
2088 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
2089 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
2090 }
2091
zhihuang38989e52017-03-21 18:04:532092 // Calling 'Initialize' with a copy of the inner SessionDescription will
2093 // create a copy of the JsepSessionDescription without candidates. The
2094 // 'connection address' field, previously set from the candidates, must also
2095 // be reset.
2096 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
2097 rtc::SocketAddress audio_addr("0.0.0.0", 9);
2098 rtc::SocketAddress video_addr("0.0.0.0", 9);
2099 audio_desc_->set_connection_address(audio_addr);
2100 video_desc_->set_connection_address(video_addr);
Harald Alvestrand4d7160e2019-04-12 05:01:292101 ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion));
zhihuang38989e52017-03-21 18:04:532102 }
2103
henrike@webrtc.org28e20752013-07-10 00:45:362104 protected:
2105 SessionDescription desc_;
2106 AudioContentDescription* audio_desc_;
2107 VideoContentDescription* video_desc_;
Harald Alvestrand5fc28b12019-05-13 11:36:162108 RtpDataContentDescription* data_desc_;
2109 SctpDataContentDescription* sctp_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:362110 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:292111 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:362112 JsepSessionDescription jdesc_;
2113};
2114
2115void TestMismatch(const std::string& string1, const std::string& string2) {
2116 int position = 0;
2117 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
2118 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:492119 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:362120 break;
2121 }
2122 }
2123 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
2124 << " character\n"
Jonas Olssonb2b20312020-01-14 11:11:312125 " 1: "
2126 << string1.substr(position, 20)
2127 << "\n"
2128 " 2: "
2129 << string2.substr(position, 20) << "\n";
henrike@webrtc.org28e20752013-07-10 00:45:362130}
2131
henrike@webrtc.org28e20752013-07-10 00:45:362132TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
2133 // SessionDescription with desc and candidates.
Steve Antone831b8c2018-02-01 20:22:162134 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362135 TestMismatch(std::string(kSdpFullString), message);
2136}
2137
2138TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
Steve Antona3a92c22017-12-07 18:27:412139 JsepSessionDescription jdesc_empty(kDummyType);
Steve Antone831b8c2018-02-01 20:22:162140 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty));
henrike@webrtc.org28e20752013-07-10 00:45:362141}
2142
2143// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
2144// the case in a DTLS offer.
2145TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
2146 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412147 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532148 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162149 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362150
2151 std::string sdp_with_fingerprint = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052152 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2153 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362154
2155 EXPECT_EQ(sdp_with_fingerprint, message);
2156}
2157
2158// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
2159// be the case in a DTLS answer.
2160TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
2161 AddFingerprint();
2162 RemoveCryptos();
Steve Antona3a92c22017-12-07 18:27:412163 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
zhihuang38989e52017-03-21 18:04:532164 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
Steve Antone831b8c2018-02-01 20:22:162165 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362166
2167 std::string sdp_with_fingerprint = kSdpString;
2168 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
2169 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
Yves Gerey665174f2018-06-19 13:03:052170 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2171 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
henrike@webrtc.org28e20752013-07-10 00:45:362172
2173 EXPECT_EQ(sdp_with_fingerprint, message);
2174}
2175
2176TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
2177 // JsepSessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412178 JsepSessionDescription jdesc_no_candidates(kDummyType);
zhihuang38989e52017-03-21 18:04:532179 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
Steve Antone831b8c2018-02-01 20:22:162180 std::string message = webrtc::SdpSerialize(jdesc_no_candidates);
henrike@webrtc.org28e20752013-07-10 00:45:362181 EXPECT_EQ(std::string(kSdpString), message);
2182}
2183
2184TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
2185 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2186 group.AddContentName(kAudioContentName);
2187 group.AddContentName(kVideoContentName);
2188 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 05:01:292189 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362190 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162191 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362192 std::string sdp_with_bundle = kSdpFullString;
2193 InjectAfter(kSessionTime,
2194 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2195 &sdp_with_bundle);
2196 EXPECT_EQ(sdp_with_bundle, message);
2197}
2198
2199TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
Steve Antonb1c1de12017-12-21 23:14:302200 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362201 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302202 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362203 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:292204 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362205 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162206 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362207 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052208 InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362209 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052210 InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362211 &sdp_with_bandwidth);
2212 EXPECT_EQ(sdp_with_bandwidth, message);
2213}
2214
2215TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
2216 std::vector<std::string> transport_options;
2217 transport_options.push_back(kIceOption1);
2218 transport_options.push_back(kIceOption3);
2219 AddIceOptions(kAudioContentName, transport_options);
2220 transport_options.clear();
2221 transport_options.push_back(kIceOption2);
2222 transport_options.push_back(kIceOption3);
2223 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292224 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362225 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:162226 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:362227 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052228 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362229 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052230 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362231 &sdp_with_ice_options);
2232 EXPECT_EQ(sdp_with_ice_options, message);
2233}
2234
Bjorn A Mellemc85ebbe2019-06-07 17:28:062235TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithOpaqueTransportParams) {
2236 cricket::OpaqueTransportParameters params;
2237 params.protocol = "foo";
2238 params.parameters = "test64";
2239 AddOpaqueTransportParameters(kAudioContentName, params);
2240 AddOpaqueTransportParameters(kVideoContentName, params);
2241
2242 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2243 jdesc_.session_version()));
2244 std::string message = webrtc::SdpSerialize(jdesc_);
2245
2246 std::string sdp_with_transport_parameters = kSdpFullString;
2247 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2248 &sdp_with_transport_parameters);
2249 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2250 &sdp_with_transport_parameters);
2251 EXPECT_EQ(message, sdp_with_transport_parameters);
2252}
2253
Bjorn A Mellem8e1343a2019-09-30 22:12:472254TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAltProtocol) {
2255 AddAltProtocol(kAudioContentName, "foo");
2256 AddAltProtocol(kVideoContentName, "bar");
2257
2258 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2259 jdesc_.session_version()));
2260 std::string message = webrtc::SdpSerialize(jdesc_);
2261
2262 std::string sdp_with_alt_protocol = kSdpFullString;
2263 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2264 &sdp_with_alt_protocol);
2265 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2266 &sdp_with_alt_protocol);
2267 EXPECT_EQ(message, sdp_with_alt_protocol);
2268}
2269
henrike@webrtc.org28e20752013-07-10 00:45:362270TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102271 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362272}
2273
2274TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102275 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362276}
2277
2278TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102279 EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362280}
2281
2282TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
2283 EXPECT_TRUE(TestSerializeRejected(true, false));
2284}
2285
2286TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
2287 EXPECT_TRUE(TestSerializeRejected(false, true));
2288}
2289
2290TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
2291 EXPECT_TRUE(TestSerializeRejected(true, true));
2292}
2293
2294TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
2295 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:412296 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362297
zhihuang38989e52017-03-21 18:04:532298 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162299 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:362300
2301 std::string expected_sdp = kSdpString;
2302 expected_sdp.append(kSdpRtpDataChannelString);
2303 EXPECT_EQ(expected_sdp, message);
2304}
2305
2306TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-18 03:48:382307 bool use_sctpmap = true;
2308 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412309 JsepSessionDescription jsep_desc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362310
zhihuang38989e52017-03-21 18:04:532311 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162312 std::string message = webrtc::SdpSerialize(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:362313
2314 std::string expected_sdp = kSdpString;
2315 expected_sdp.append(kSdpSctpDataChannelString);
2316 EXPECT_EQ(message, expected_sdp);
2317}
2318
Harald Alvestrand5fc28b12019-05-13 11:36:162319void MutateJsepSctpPort(JsepSessionDescription* jdesc,
2320 const SessionDescription& desc,
2321 int port) {
2322 // Take our pre-built session description and change the SCTP port.
2323 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
2324 SctpDataContentDescription* dcdesc =
2325 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2326 dcdesc->set_port(port);
2327 ASSERT_TRUE(
2328 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion));
2329}
2330
jiayl@webrtc.org9c16c392014-05-01 18:30:302331TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-18 03:48:382332 bool use_sctpmap = true;
2333 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412334 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:532335 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302336
2337 const int kNewPort = 1234;
Harald Alvestrand5fc28b12019-05-13 11:36:162338 MutateJsepSctpPort(&jsep_desc, desc_, kNewPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302339
Steve Antone831b8c2018-02-01 20:22:162340 std::string message = webrtc::SdpSerialize(jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:302341
2342 std::string expected_sdp = kSdpString;
2343 expected_sdp.append(kSdpSctpDataChannelString);
2344
Steve Anton1c9c9fc2019-02-14 23:13:092345 absl::StrReplaceAll(
2346 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}},
2347 &expected_sdp);
jiayl@webrtc.org9c16c392014-05-01 18:30:302348
2349 EXPECT_EQ(expected_sdp, message);
2350}
2351
wu@webrtc.orgcadf9042013-08-30 21:24:162352TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412353 JsepSessionDescription jsep_desc(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:162354 AddRtpDataChannel();
Yves Gerey665174f2018-06-19 13:03:052355 data_desc_->set_bandwidth(100 * 1000);
zhihuang38989e52017-03-21 18:04:532356 MakeDescriptionWithoutCandidates(&jsep_desc);
Steve Antone831b8c2018-02-01 20:22:162357 std::string message = webrtc::SdpSerialize(jsep_desc);
wu@webrtc.orgcadf9042013-08-30 21:24:162358
2359 std::string expected_sdp = kSdpString;
2360 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 22:31:252361 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:062362 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
Yves Gerey665174f2018-06-19 13:03:052363 "b=AS:100\r\n", &expected_sdp);
sergeyu@chromium.orga59696b2013-09-13 23:48:582364 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:162365}
2366
Johannes Kron0854eb62018-10-10 20:33:202367TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392368 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202369 TestSerialize(jdesc_);
2370}
2371
2372TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) {
2373 cricket::MediaContentDescription* video_desc =
2374 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2375 ASSERT_TRUE(video_desc);
2376 cricket::MediaContentDescription* audio_desc =
2377 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2378 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392379 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202380 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392381 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202382 cricket::MediaContentDescription::kMedia);
2383 TestSerialize(jdesc_);
2384}
2385
henrike@webrtc.org28e20752013-07-10 00:45:362386TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 19:31:362387 bool encrypted = false;
2388 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412389 JsepSessionDescription desc_with_extmap(kDummyType);
zhihuang38989e52017-03-21 18:04:532390 MakeDescriptionWithoutCandidates(&desc_with_extmap);
Steve Antone831b8c2018-02-01 20:22:162391 std::string message = webrtc::SdpSerialize(desc_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362392
2393 std::string sdp_with_extmap = kSdpString;
Yves Gerey665174f2018-06-19 13:03:052394 InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap);
2395 InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap);
henrike@webrtc.org28e20752013-07-10 00:45:362396
2397 EXPECT_EQ(sdp_with_extmap, message);
2398}
2399
jbauch5869f502017-06-29 19:31:362400TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2401 bool encrypted = true;
2402 AddExtmap(encrypted);
Steve Antona3a92c22017-12-07 18:27:412403 JsepSessionDescription desc_with_extmap(kDummyType);
Yves Gerey665174f2018-06-19 13:03:052404 ASSERT_TRUE(
Harald Alvestrand4d7160e2019-04-12 05:01:292405 desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Steve Antone831b8c2018-02-01 20:22:162406 TestSerialize(desc_with_extmap);
jbauch5869f502017-06-29 19:31:362407}
2408
henrike@webrtc.org28e20752013-07-10 00:45:362409TEST_F(WebRtcSdpTest, SerializeCandidates) {
2410 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102411 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232412
2413 Candidate candidate_with_ufrag(candidates_.front());
2414 candidate_with_ufrag.set_username("ABC");
2415 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2416 candidate_with_ufrag));
2417 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2418 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482419
2420 Candidate candidate_with_network_info(candidates_.front());
2421 candidate_with_network_info.set_network_id(1);
2422 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2423 candidate_with_network_info));
2424 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2425 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2426 candidate_with_network_info.set_network_cost(999);
2427 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2428 candidate_with_network_info));
2429 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2430 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2431 message);
henrike@webrtc.org28e20752013-07-10 00:45:362432}
2433
Zach Steinb336c272018-08-09 08:16:132434TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
2435 rtc::SocketAddress address("a.test", 1234);
2436 cricket::Candidate candidate(
2437 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
2438 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
2439 JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
2440 std::string message = webrtc::SdpSerializeCandidate(jcandidate);
2441 EXPECT_EQ(std::string(kRawHostnameCandidate), message);
2442}
2443
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202444// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2445// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:552446TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072447 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312448 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2449 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2450 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202451 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292452 std::unique_ptr<IceCandidateInterface> jcandidate(
2453 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202454
2455 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2456 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2457}
2458
htaa6b99442016-04-12 17:29:172459TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 09:34:112460 cricket::VideoCodec h264_codec("H264");
2461 h264_codec.SetParam("profile-level-id", "42e01f");
2462 h264_codec.SetParam("level-asymmetry-allowed", "1");
2463 h264_codec.SetParam("packetization-mode", "1");
2464 video_desc_->AddCodec(h264_codec);
2465
Harald Alvestrand4d7160e2019-04-12 05:01:292466 jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion);
htaa6b99442016-04-12 17:29:172467
Steve Antone831b8c2018-02-01 20:22:162468 std::string message = webrtc::SdpSerialize(jdesc_);
htaa6b99442016-04-12 17:29:172469 size_t after_pt = message.find(" H264/90000");
2470 ASSERT_NE(after_pt, std::string::npos);
2471 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2472 ASSERT_NE(before_pt, std::string::npos);
2473 before_pt += strlen("a=rtpmap:");
2474 std::string pt = message.substr(before_pt, after_pt - before_pt);
2475 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2476 std::string to_find = "a=fmtp:" + pt + " ";
2477 size_t fmtp_pos = message.find(to_find);
2478 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
Mirko Bonadei37ec55e2019-01-28 10:43:522479 size_t fmtp_endpos = message.find('\n', fmtp_pos);
htaa6b99442016-04-12 17:29:172480 ASSERT_NE(std::string::npos, fmtp_endpos);
2481 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2482 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2483 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2484 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142485 // Check that there are no spaces after semicolons.
2486 // https://bugs.webrtc.org/5793
2487 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172488}
2489
henrike@webrtc.org28e20752013-07-10 00:45:362490TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
Steve Antona3a92c22017-12-07 18:27:412491 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362492 // Deserialize
2493 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2494 // Verify
2495 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2496}
2497
wu@webrtc.orgcecfd182013-10-30 05:18:122498TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
Steve Antona3a92c22017-12-07 18:27:412499 JsepSessionDescription jdesc(kDummyType);
wu@webrtc.orgcecfd182013-10-30 05:18:122500 const char kSdpWithoutMline[] =
Yves Gerey665174f2018-06-19 13:03:052501 "v=0\r\n"
2502 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2503 "s=-\r\n"
2504 "t=0 0\r\n"
2505 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
wu@webrtc.orgcecfd182013-10-30 05:18:122506 // Deserialize
2507 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2508 EXPECT_EQ(0u, jdesc.description()->contents().size());
2509}
2510
henrike@webrtc.org28e20752013-07-10 00:45:362511TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
Steve Antona3a92c22017-12-07 18:27:412512 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362513 std::string sdp_without_carriage_return = kSdpFullString;
2514 Replace("\r\n", "\n", &sdp_without_carriage_return);
2515 // Deserialize
2516 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2517 // Verify
2518 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2519}
2520
2521TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2522 // SessionDescription with desc but without candidates.
Steve Antona3a92c22017-12-07 18:27:412523 JsepSessionDescription jdesc_no_candidates(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292524 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId,
Yves Gerey665174f2018-06-19 13:03:052525 kSessionVersion));
Steve Antona3a92c22017-12-07 18:27:412526 JsepSessionDescription new_jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362527 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2528 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2529}
2530
2531TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2532 static const char kSdpNoRtpmapString[] =
2533 "v=0\r\n"
2534 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2535 "s=-\r\n"
2536 "t=0 0\r\n"
2537 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2538 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412539 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362540 // The rtpmap line for static payload codec is optional.
2541 "a=rtpmap:18 G729/16000\r\n"
2542 "a=rtpmap:103 ISAC/16000\r\n";
2543
Steve Antona3a92c22017-12-07 18:27:412544 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362545 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2546 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302547 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org28e20752013-07-10 00:45:362548 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162549 // The codecs in the AudioContentDescription should be in the same order as
2550 // the payload types (<fmt>s) on the m= line.
2551 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2552 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 16:55:482553 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362554 EXPECT_EQ(ref_codecs, audio->codecs());
2555}
2556
henrike@webrtc.org704bf9e2014-02-27 17:52:042557TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2558 static const char kSdpNoRtpmapString[] =
2559 "v=0\r\n"
2560 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2561 "s=-\r\n"
2562 "t=0 0\r\n"
2563 "m=audio 49232 RTP/AVP 18 103\r\n"
2564 "a=fmtp:18 annexb=yes\r\n"
2565 "a=rtpmap:103 ISAC/16000\r\n";
2566
Steve Antona3a92c22017-12-07 18:27:412567 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:042568 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2569 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:302570 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:042571
2572 cricket::AudioCodec g729 = audio->codecs()[0];
2573 EXPECT_EQ("G729", g729.name);
2574 EXPECT_EQ(8000, g729.clockrate);
2575 EXPECT_EQ(18, g729.id);
Yves Gerey665174f2018-06-19 13:03:052576 cricket::CodecParameterMap::iterator found = g729.params.find("annexb");
henrike@webrtc.org704bf9e2014-02-27 17:52:042577 ASSERT_TRUE(found != g729.params.end());
2578 EXPECT_EQ(found->second, "yes");
2579
2580 cricket::AudioCodec isac = audio->codecs()[1];
2581 EXPECT_EQ("ISAC", isac.name);
2582 EXPECT_EQ(103, isac.id);
2583 EXPECT_EQ(16000, isac.clockrate);
2584}
2585
henrike@webrtc.org28e20752013-07-10 00:45:362586// Ensure that we can deserialize SDP with a=fingerprint properly.
2587TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2588 // Add a DTLS a=fingerprint attribute to our session description.
2589 AddFingerprint();
Steve Antona3a92c22017-12-07 18:27:412590 JsepSessionDescription new_jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292591 ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362592 jdesc_.session_version()));
2593
Steve Antona3a92c22017-12-07 18:27:412594 JsepSessionDescription jdesc_with_fingerprint(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362595 std::string sdp_with_fingerprint = kSdpString;
2596 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2597 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2598 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2599 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2600}
2601
2602TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
Steve Antona3a92c22017-12-07 18:27:412603 JsepSessionDescription jdesc_with_bundle(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362604 std::string sdp_with_bundle = kSdpFullString;
2605 InjectAfter(kSessionTime,
2606 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2607 &sdp_with_bundle);
2608 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2609 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2610 group.AddContentName(kAudioContentName);
2611 group.AddContentName(kVideoContentName);
2612 desc_.AddGroup(group);
Harald Alvestrand4d7160e2019-04-12 05:01:292613 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362614 jdesc_.session_version()));
2615 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2616}
2617
2618TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
Steve Antona3a92c22017-12-07 18:27:412619 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362620 std::string sdp_with_bandwidth = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052621 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362622 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052623 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362624 &sdp_with_bandwidth);
Yves Gerey665174f2018-06-19 13:03:052625 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
Steve Antonb1c1de12017-12-21 23:14:302626 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362627 vcd->set_bandwidth(100 * 1000);
Steve Antonb1c1de12017-12-21 23:14:302628 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:362629 acd->set_bandwidth(50 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:292630 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362631 jdesc_.session_version()));
2632 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2633}
2634
2635TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
Steve Antona3a92c22017-12-07 18:27:412636 JsepSessionDescription jdesc_with_ice_options(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362637 std::string sdp_with_ice_options = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:052638 InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362639 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052640 InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362641 &sdp_with_ice_options);
Yves Gerey665174f2018-06-19 13:03:052642 InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362643 &sdp_with_ice_options);
2644 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2645 std::vector<std::string> transport_options;
2646 transport_options.push_back(kIceOption3);
2647 transport_options.push_back(kIceOption1);
2648 AddIceOptions(kAudioContentName, transport_options);
2649 transport_options.clear();
2650 transport_options.push_back(kIceOption3);
2651 transport_options.push_back(kIceOption2);
2652 AddIceOptions(kVideoContentName, transport_options);
Harald Alvestrand4d7160e2019-04-12 05:01:292653 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:362654 jdesc_.session_version()));
2655 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2656}
2657
Bjorn A Mellemc85ebbe2019-06-07 17:28:062658TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithOpaqueTransportParams) {
2659 std::string sdp_with_transport_parameters = kSdpFullString;
2660 InjectAfter(kAttributeIcePwdVoice, "a=x-opaque:foo:dGVzdDY0\r\n",
2661 &sdp_with_transport_parameters);
2662 InjectAfter(kAttributeIcePwdVideo, "a=x-opaque:foo:dGVzdDY0\r\n",
2663 &sdp_with_transport_parameters);
2664
2665 JsepSessionDescription jdesc_with_transport_parameters(kDummyType);
2666 EXPECT_TRUE(SdpDeserialize(sdp_with_transport_parameters,
2667 &jdesc_with_transport_parameters));
2668
2669 cricket::OpaqueTransportParameters params;
2670 params.protocol = "foo";
2671 params.parameters = "test64";
2672
2673 AddOpaqueTransportParameters(kAudioContentName, params);
2674 AddOpaqueTransportParameters(kVideoContentName, params);
2675
2676 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2677 jdesc_.session_version()));
2678 EXPECT_TRUE(
2679 CompareSessionDescription(jdesc_, jdesc_with_transport_parameters));
2680}
2681
Bjorn A Mellem8e1343a2019-09-30 22:12:472682TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithAltProtocol) {
2683 std::string sdp_with_alt_protocol = kSdpFullString;
2684 InjectAfter(kAttributeIcePwdVoice, "a=x-alt-protocol:foo\r\n",
2685 &sdp_with_alt_protocol);
2686 InjectAfter(kAttributeIcePwdVideo, "a=x-alt-protocol:bar\r\n",
2687 &sdp_with_alt_protocol);
2688
2689 JsepSessionDescription jdesc_with_alt_protocol(kDummyType);
2690 EXPECT_TRUE(SdpDeserialize(sdp_with_alt_protocol, &jdesc_with_alt_protocol));
2691
2692 AddAltProtocol(kAudioContentName, "foo");
2693 AddAltProtocol(kVideoContentName, "bar");
2694
2695 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
2696 jdesc_.session_version()));
2697 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_alt_protocol));
2698}
2699
henrike@webrtc.org28e20752013-07-10 00:45:362700TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2701 // Remove the original ice-ufrag and ice-pwd
Steve Antona3a92c22017-12-07 18:27:412702 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362703 std::string sdp_with_ufrag_pwd = kSdpFullString;
2704 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2705 // Add session level ufrag and pwd
2706 InjectAfter(kSessionTime,
Yves Gerey665174f2018-06-19 13:03:052707 "a=ice-pwd:session+level+icepwd\r\n"
2708 "a=ice-ufrag:session+level+iceufrag\r\n",
2709 &sdp_with_ufrag_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:362710 // Add media level ufrag and pwd for audio
Yves Gerey665174f2018-06-19 13:03:052711 InjectAfter(
2712 "a=mid:audio_content_name\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:362713 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2714 &sdp_with_ufrag_pwd);
2715 // Update the candidate ufrag and pwd to the expected ones.
Yves Gerey665174f2018-06-19 13:03:052716 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag",
2717 "media+level+icepwd"));
2718 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag",
2719 "session+level+icepwd"));
henrike@webrtc.org28e20752013-07-10 00:45:362720 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2721 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2722}
2723
henrike@webrtc.org28e20752013-07-10 00:45:362724TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102725 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362726}
2727
2728TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
Steve Anton4e70a722017-11-28 22:57:102729 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly));
henrike@webrtc.org28e20752013-07-10 00:45:362730}
2731
2732TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
Steve Anton4e70a722017-11-28 22:57:102733 EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive));
henrike@webrtc.org28e20752013-07-10 00:45:362734}
2735
2736TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2737 EXPECT_TRUE(TestDeserializeRejected(true, false));
2738}
2739
2740TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2741 EXPECT_TRUE(TestDeserializeRejected(false, true));
2742}
2743
2744TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2745 EXPECT_TRUE(TestDeserializeRejected(true, true));
2746}
2747
2748// Tests that we can still handle the sdp uses mslabel and label instead of
2749// msid for backward compatibility.
2750TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 20:14:452751 jdesc_.description()->set_msid_supported(false);
Steve Antona3a92c22017-12-07 18:27:412752 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362753 std::string sdp_without_msid = kSdpFullString;
2754 Replace("msid", "xmsid", &sdp_without_msid);
2755 // Deserialize
2756 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2757 // Verify
2758 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
Henrik Boström5b147782018-12-04 10:25:052759 EXPECT_FALSE(jdesc.description()->msid_signaling() &
2760 ~cricket::kMsidSignalingSsrcAttribute);
henrike@webrtc.org28e20752013-07-10 00:45:362761}
2762
Johannes Kron0854eb62018-10-10 20:33:202763TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392764 jdesc_.description()->set_extmap_allow_mixed(true);
Johannes Kron0854eb62018-10-10 20:33:202765 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2766 InjectAfter("t=0 0\r\n", kExtmapAllowMixed, &sdp_with_extmap_allow_mixed);
2767 // Deserialize
2768 JsepSessionDescription jdesc_deserialized(kDummyType);
2769 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2770 // Verify
2771 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2772}
2773
2774TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) {
Johannes Kron9581bc42018-10-23 08:17:392775 jdesc_.description()->set_extmap_allow_mixed(false);
Johannes Kron0854eb62018-10-10 20:33:202776 std::string sdp_without_extmap_allow_mixed = kSdpFullString;
2777 // Deserialize
2778 JsepSessionDescription jdesc_deserialized(kDummyType);
2779 EXPECT_TRUE(
2780 SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized));
2781 // Verify
2782 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2783}
2784
2785TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) {
2786 cricket::MediaContentDescription* video_desc =
2787 jdesc_.description()->GetContentDescriptionByName(kVideoContentName);
2788 ASSERT_TRUE(video_desc);
2789 cricket::MediaContentDescription* audio_desc =
2790 jdesc_.description()->GetContentDescriptionByName(kAudioContentName);
2791 ASSERT_TRUE(audio_desc);
Johannes Kron9581bc42018-10-23 08:17:392792 video_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202793 cricket::MediaContentDescription::kMedia);
Johannes Kron9581bc42018-10-23 08:17:392794 audio_desc->set_extmap_allow_mixed_enum(
Johannes Kron0854eb62018-10-10 20:33:202795 cricket::MediaContentDescription::kMedia);
2796
2797 std::string sdp_with_extmap_allow_mixed = kSdpFullString;
2798 InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed,
2799 &sdp_with_extmap_allow_mixed);
2800 InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed,
2801 &sdp_with_extmap_allow_mixed);
2802
2803 // Deserialize
2804 JsepSessionDescription jdesc_deserialized(kDummyType);
2805 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized));
2806 // Verify
2807 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized));
2808}
2809
henrike@webrtc.org28e20752013-07-10 00:45:362810TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2811 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2812
2813 std::string sdp = kSdpOneCandidate;
2814 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2815 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2816 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2817 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482818 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362819
2820 // Candidate line without generation extension.
2821 sdp = kSdpOneCandidate;
2822 Replace(" generation 2", "", &sdp);
2823 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2824 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2825 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2826 Candidate expected = jcandidate_->candidate();
2827 expected.set_generation(0);
2828 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2829
honghaiza0c44ea2016-03-23 23:07:482830 // Candidate with network id and/or cost.
2831 sdp = kSdpOneCandidate;
2832 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2833 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2834 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2835 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2836 expected = jcandidate_->candidate();
2837 expected.set_network_id(2);
2838 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2839 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2840 // Add network cost
2841 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2842 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2843 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2844 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2845
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202846 sdp = kSdpTcpActiveCandidate;
2847 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2848 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072849 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312850 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2851 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2852 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292853 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2854 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
Yves Gerey665174f2018-06-19 13:03:052855 EXPECT_TRUE(
2856 jcandidate.candidate().IsEquivalent(jcandidate_template->candidate()));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202857 sdp = kSdpTcpPassiveCandidate;
2858 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2859 sdp = kSdpTcpSOCandidate;
2860 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362861}
2862
2863// This test verifies the deserialization of candidate-attribute
2864// as per RFC 5245. Candiate-attribute will be of the format
2865// candidate:<blah>. This format will be used when candidates
2866// are trickled.
2867TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2868 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2869
2870 std::string candidate_attribute = kRawCandidate;
2871 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2872 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2873 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2874 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2875 EXPECT_EQ(2u, jcandidate.candidate().generation());
2876
2877 // Candidate line without generation extension.
2878 candidate_attribute = kRawCandidate;
2879 Replace(" generation 2", "", &candidate_attribute);
2880 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2881 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2882 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2883 Candidate expected = jcandidate_->candidate();
2884 expected.set_generation(0);
2885 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2886
2887 // Candidate line without candidate:
2888 candidate_attribute = kRawCandidate;
2889 Replace("candidate:", "", &candidate_attribute);
2890 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2891
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152892 // Candidate line with IPV6 address.
2893 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
Zach Steinb336c272018-08-09 08:16:132894
2895 // Candidate line with hostname address.
2896 EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152897}
2898
2899// This test verifies that the deserialization of an invalid candidate string
2900// fails.
2901TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
Yves Gerey665174f2018-06-19 13:03:052902 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152903
2904 std::string candidate_attribute = kRawCandidate;
2905 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362906 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152907
2908 candidate_attribute = kSdpOneCandidate;
2909 candidate_attribute.replace(0, 1, "x");
2910 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2911
2912 candidate_attribute = kRawCandidate;
2913 candidate_attribute.append("\r\n");
2914 candidate_attribute.append(kRawCandidate);
2915 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2916
2917 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362918}
2919
2920TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2921 AddRtpDataChannel();
Steve Antona3a92c22017-12-07 18:27:412922 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292923 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:362924
2925 std::string sdp_with_data = kSdpString;
2926 sdp_with_data.append(kSdpRtpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412927 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362928
2929 // Deserialize
2930 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2931 // Verify
2932 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2933}
2934
2935TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-18 03:48:382936 bool use_sctpmap = true;
2937 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412938 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292939 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
henrike@webrtc.org28e20752013-07-10 00:45:362940
2941 std::string sdp_with_data = kSdpString;
2942 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Antona3a92c22017-12-07 18:27:412943 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:362944
Guido Urdanetacecf87f2019-05-31 10:17:382945 // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString).
lally@webrtc.org36300852015-02-24 20:19:352946 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2947 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2948
Guido Urdanetacecf87f2019-05-31 10:17:382949 // Verify with DTLS/SCTP.
2950 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp),
2951 kDtlsSctp);
lally@webrtc.org36300852015-02-24 20:19:352952 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2953 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2954
2955 // Verify with TCP/DTLS/SCTP.
Guido Urdanetacecf87f2019-05-31 10:17:382956 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp),
Yves Gerey665174f2018-06-19 13:03:052957 kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362958 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2959 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2960}
2961
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562962TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-18 03:48:382963 bool use_sctpmap = false;
2964 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412965 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292966 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562967
2968 std::string sdp_with_data = kSdpString;
2969 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Antona3a92c22017-12-07 18:27:412970 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562971
lally@webrtc.orgc7848b72015-02-24 20:19:262972 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2973 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2974}
2975
lally69f57602015-10-08 17:15:042976TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-18 03:48:382977 bool use_sctpmap = false;
2978 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:412979 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:292980 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
lally69f57602015-10-08 17:15:042981
2982 std::string sdp_with_data = kSdpString;
2983 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
Steve Antona3a92c22017-12-07 18:27:412984 JsepSessionDescription jdesc_output(kDummyType);
lally69f57602015-10-08 17:15:042985
lally69f57602015-10-08 17:15:042986 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2987 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2988}
2989
Harald Alvestrand48cce4d2019-04-11 08:41:242990// Helper function to set the max-message-size parameter in the
2991// SCTP data codec.
2992void MutateJsepSctpMaxMessageSize(const SessionDescription& desc,
Harald Alvestrand5fc28b12019-05-13 11:36:162993 int new_value,
Harald Alvestrand48cce4d2019-04-11 08:41:242994 JsepSessionDescription* jdesc) {
Harald Alvestrand8da35a62019-05-10 07:31:042995 std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone();
Harald Alvestrand5fc28b12019-05-13 11:36:162996 SctpDataContentDescription* dcdesc =
2997 mutant->GetContentDescriptionByName(kDataContentName)->as_sctp();
2998 dcdesc->set_max_message_size(new_value);
Harald Alvestrand8da35a62019-05-10 07:31:042999 jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion);
Harald Alvestrand48cce4d2019-04-11 08:41:243000}
3001
3002TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {
3003 bool use_sctpmap = false;
3004 AddSctpDataChannel(use_sctpmap);
3005 JsepSessionDescription jdesc(kDummyType);
3006 std::string sdp_with_data = kSdpString;
3007
3008 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
3009 sdp_with_data.append("a=max-message-size:12345\r\n");
Harald Alvestrand5fc28b12019-05-13 11:36:163010 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
Harald Alvestrand48cce4d2019-04-11 08:41:243011 JsepSessionDescription jdesc_output(kDummyType);
3012
Harald Alvestrand48cce4d2019-04-11 08:41:243013 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3014 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3015}
3016
Harald Alvestrandfbb45bd2019-05-15 06:07:473017TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) {
3018 bool use_sctpmap = false;
3019 AddSctpDataChannel(use_sctpmap);
3020 JsepSessionDescription jdesc(kDummyType);
3021 MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc);
3022 std::string message = webrtc::SdpSerialize(jdesc);
3023 EXPECT_NE(std::string::npos,
3024 message.find("\r\na=max-message-size:12345\r\n"));
3025 JsepSessionDescription jdesc_output(kDummyType);
3026 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3027 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3028}
3029
3030TEST_F(WebRtcSdpTest,
3031 SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) {
3032 // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
3033 // The default max message size is 64K.
3034 bool use_sctpmap = false;
3035 AddSctpDataChannel(use_sctpmap);
3036 JsepSessionDescription jdesc(kDummyType);
3037 MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc);
3038 std::string message = webrtc::SdpSerialize(jdesc);
3039 EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:"));
3040 JsepSessionDescription jdesc_output(kDummyType);
3041 EXPECT_TRUE(SdpDeserialize(message, &jdesc_output));
3042 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
3043}
3044
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563045// Test to check the behaviour if sctp-port is specified
3046// on the m= line and in a=sctp-port.
3047TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-18 03:48:383048 bool use_sctpmap = true;
3049 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:413050 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand4d7160e2019-04-12 05:01:293051 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563052
3053 std::string sdp_with_data = kSdpString;
3054 // Append m= attributes
3055 sdp_with_data.append(kSdpSctpDataChannelString);
3056 // Append a=sctp-port attribute
3057 sdp_with_data.append("a=sctp-port 5000\r\n");
Steve Antona3a92c22017-12-07 18:27:413058 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563059
3060 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3061}
3062
Harald Alvestrand5fc28b12019-05-13 11:36:163063// Test behavior if a=rtpmap occurs in an SCTP section.
3064TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) {
3065 std::string sdp_with_data = kSdpString;
3066 // Append m= attributes
3067 sdp_with_data.append(kSdpSctpDataChannelString);
3068 // Append a=rtpmap attribute
3069 sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n");
3070 JsepSessionDescription jdesc_output(kDummyType);
3071 // Correct behavior is to ignore the extra attribute.
3072 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3073}
3074
3075TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) {
3076 static const char* bad_strings[] = {"DTLS/SCTPRTP/", "obviously-bogus",
3077 "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"};
3078 for (auto proto : bad_strings) {
3079 std::string sdp_with_data = kSdpString;
3080 sdp_with_data.append("m=application 9 ");
3081 sdp_with_data.append(proto);
3082 sdp_with_data.append(" 47\r\n");
3083 JsepSessionDescription jdesc_output(kDummyType);
3084 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output))
3085 << "Parsing should have failed on " << proto;
3086 }
3087 // The following strings are strange, but acceptable as RTP.
3088 static const char* weird_strings[] = {"DTLS/SCTP/RTP/FOO",
3089 "obviously-bogus/RTP/"};
3090 for (auto proto : weird_strings) {
3091 std::string sdp_with_data = kSdpString;
3092 sdp_with_data.append("m=application 9 ");
3093 sdp_with_data.append(proto);
3094 sdp_with_data.append(" 47\r\n");
3095 JsepSessionDescription jdesc_output(kDummyType);
3096 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output))
3097 << "Parsing should have succeeded on " << proto;
3098 }
3099}
3100
henrike@webrtc.org571df2d2014-02-19 23:04:263101// For crbug/344475.
3102TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
3103 std::string sdp_with_data = kSdpString;
3104 sdp_with_data.append(kSdpSctpDataChannelString);
3105 // Remove the "\n" at the end.
3106 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
Steve Antona3a92c22017-12-07 18:27:413107 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org571df2d2014-02-19 23:04:263108
3109 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
3110 // No crash is a pass.
3111}
3112
zstein4b2e0822017-02-18 03:48:383113TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
3114 bool use_sctpmap = true;
3115 AddSctpDataChannel(use_sctpmap);
3116
3117 // First setup the expected JsepSessionDescription.
Steve Antona3a92c22017-12-07 18:27:413118 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163119 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
wu@webrtc.org78187522013-10-07 23:32:023120
jiayl@webrtc.org9c16c392014-05-01 18:30:303121 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:023122 std::string sdp_with_data = kSdpString;
3123 sdp_with_data.append(kSdpSctpDataChannelString);
Steve Anton1c9c9fc2019-02-14 23:13:093124 absl::StrReplaceAll(
3125 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3126 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413127 JsepSessionDescription jdesc_output(kDummyType);
wu@webrtc.org78187522013-10-07 23:32:023128
3129 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3130 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-18 03:48:383131}
3132
3133TEST_F(WebRtcSdpTest,
3134 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
3135 bool use_sctpmap = false;
3136 AddSctpDataChannel(use_sctpmap);
3137
Steve Antona3a92c22017-12-07 18:27:413138 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163139 MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563140
3141 // We need to test the deserialized JsepSessionDescription from
3142 // kSdpSctpDataChannelStringWithSctpPort for
3143 // draft-ietf-mmusic-sctp-sdp-07
3144 // a=sctp-port
zstein4b2e0822017-02-18 03:48:383145 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563146 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
Steve Anton1c9c9fc2019-02-14 23:13:093147 absl::StrReplaceAll(
3148 {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}},
3149 &sdp_with_data);
Steve Antona3a92c22017-12-07 18:27:413150 JsepSessionDescription jdesc_output(kDummyType);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:563151
3152 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
3153 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:023154}
3155
wu@webrtc.orgcadf9042013-08-30 21:24:163156TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 22:31:253157 // We want to test that deserializing data content limits bandwidth
3158 // settings (it should never be greater than the default).
3159 // This should prevent someone from using unlimited data bandwidth through
3160 // JS and "breaking the Internet".
3161 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:163162 std::string sdp_with_bandwidth = kSdpString;
3163 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
Yves Gerey665174f2018-06-19 13:03:053164 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
wu@webrtc.orgcadf9042013-08-30 21:24:163165 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:413166 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
wu@webrtc.orgcadf9042013-08-30 21:24:163167
Peter Thatcherc0c3a862015-06-24 22:31:253168 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
3169}
3170
3171TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-18 03:48:383172 bool use_sctpmap = true;
3173 AddSctpDataChannel(use_sctpmap);
Steve Antona3a92c22017-12-07 18:27:413174 JsepSessionDescription jdesc(kDummyType);
Harald Alvestrand5fc28b12019-05-13 11:36:163175 SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_);
Peter Thatcherc0c3a862015-06-24 22:31:253176 dcd->set_bandwidth(100 * 1000);
Harald Alvestrand4d7160e2019-04-12 05:01:293177 ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion));
Peter Thatcherc0c3a862015-06-24 22:31:253178
3179 std::string sdp_with_bandwidth = kSdpString;
3180 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
Yves Gerey665174f2018-06-19 13:03:053181 InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n",
Peter Thatcherc0c3a862015-06-24 22:31:253182 &sdp_with_bandwidth);
Steve Antona3a92c22017-12-07 18:27:413183 JsepSessionDescription jdesc_with_bandwidth(kDummyType);
Peter Thatcherc0c3a862015-06-24 22:31:253184
3185 // SCTP has congestion control, so we shouldn't limit the bandwidth
3186 // as we do for RTP.
3187 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:163188 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
3189}
3190
Yves Gerey665174f2018-06-19 13:03:053191class WebRtcSdpExtmapTest : public WebRtcSdpTest,
Mirko Bonadei6a489f22019-04-09 13:11:123192 public ::testing::WithParamInterface<bool> {};
jbauch5869f502017-06-29 19:31:363193
3194TEST_P(WebRtcSdpExtmapTest,
Yves Gerey665174f2018-06-19 13:03:053195 DeserializeSessionDescriptionWithSessionLevelExtmap) {
jbauch5869f502017-06-29 19:31:363196 bool encrypted = GetParam();
3197 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363198}
3199
Yves Gerey665174f2018-06-19 13:03:053200TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
jbauch5869f502017-06-29 19:31:363201 bool encrypted = GetParam();
3202 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363203}
3204
Yves Gerey665174f2018-06-19 13:03:053205TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) {
jbauch5869f502017-06-29 19:31:363206 bool encrypted = GetParam();
3207 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:363208}
3209
Mirko Bonadeic84f6612019-01-31 11:20:573210INSTANTIATE_TEST_SUITE_P(Encrypted,
3211 WebRtcSdpExtmapTest,
3212 ::testing::Values(false, true));
jbauch5869f502017-06-29 19:31:363213
sergeyu@chromium.org5bc25c42013-12-05 00:24:063214TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
Steve Antona3a92c22017-12-07 18:27:413215 JsepSessionDescription jdesc(kDummyType);
sergeyu@chromium.org5bc25c42013-12-05 00:24:063216 std::string sdp = kSdpFullString;
3217 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
3218 // Deserialize
3219 SdpParseError error;
3220 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-17 01:54:103221 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:063222 EXPECT_EQ(lastline, error.line);
3223 EXPECT_EQ("Invalid SDP line.", error.description);
3224}
3225
henrike@webrtc.org28e20752013-07-10 00:45:363226TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
3227 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
3228 std::string new_sdp = kSdpOneCandidate;
3229 Replace("udp", "unsupported_transport", &new_sdp);
3230 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3231 new_sdp = kSdpOneCandidate;
3232 Replace("udp", "uDP", &new_sdp);
3233 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
3234 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3235 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3236 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
3237}
3238
honghaiza54a0802015-12-17 02:37:233239TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:363240 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:233241 EXPECT_TRUE(
3242 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:363243 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
3244 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
3245 Candidate ref_candidate = jcandidate_->candidate();
3246 ref_candidate.set_username("user_rtp");
3247 ref_candidate.set_password("password_rtp");
3248 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
3249}
3250
henrike@webrtc.org704bf9e2014-02-27 17:52:043251TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413252 JsepSessionDescription jdesc(kDummyType);
henrike@webrtc.org704bf9e2014-02-27 17:52:043253
3254 // Deserialize
3255 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
3256
3257 // Verify
3258 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303259 cricket::GetFirstAudioContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043260 EXPECT_TRUE(audio->conference_mode());
3261
3262 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303263 cricket::GetFirstVideoContentDescription(jdesc.description());
henrike@webrtc.org704bf9e2014-02-27 17:52:043264 EXPECT_TRUE(video->conference_mode());
3265}
3266
deadbeefd45aea82017-09-16 08:24:293267TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
Steve Antona3a92c22017-12-07 18:27:413268 JsepSessionDescription jdesc(kDummyType);
deadbeefd45aea82017-09-16 08:24:293269
3270 // We tested deserialization already above, so just test that if we serialize
3271 // and deserialize the flag doesn't disappear.
3272 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
Steve Antone831b8c2018-02-01 20:22:163273 std::string reserialized = webrtc::SdpSerialize(jdesc);
deadbeefd45aea82017-09-16 08:24:293274 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
3275
3276 // Verify.
3277 cricket::AudioContentDescription* audio =
Steve Anton06817cd2018-12-18 23:55:303278 cricket::GetFirstAudioContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293279 EXPECT_TRUE(audio->conference_mode());
3280
3281 cricket::VideoContentDescription* video =
Steve Anton06817cd2018-12-18 23:55:303282 cricket::GetFirstVideoContentDescription(jdesc.description());
deadbeefd45aea82017-09-16 08:24:293283 EXPECT_TRUE(video->conference_mode());
3284}
3285
Sebastian Jansson97321b62019-07-24 12:01:183286TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) {
3287 {
3288 // By default remote estimates are disabled.
3289 JsepSessionDescription dst(kDummyType);
3290 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3291 EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description())
3292 ->remote_estimate());
3293 }
3294 {
3295 // When remote estimate is enabled, the setting is propagated via SDP.
3296 cricket::GetFirstVideoContentDescription(jdesc_.description())
3297 ->set_remote_estimate(true);
3298 JsepSessionDescription dst(kDummyType);
3299 SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst);
3300 EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description())
3301 ->remote_estimate());
3302 }
3303}
3304
henrike@webrtc.org28e20752013-07-10 00:45:363305TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
3306 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:513307 const char kSdpEmptyType[] = " =candidate";
3308 const char kSdpEqualAsPlus[] = "a+candidate";
3309 const char kSdpSpaceAfterEqual[] = "a= candidate";
3310 const char kSdpUpperType[] = "A=candidate";
3311 const char kSdpEmptyLine[] = "";
3312 const char kSdpMissingValue[] = "a=";
3313
Yves Gerey665174f2018-06-19 13:03:053314 const char kSdpBrokenFingerprint[] =
3315 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363316 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
Yves Gerey665174f2018-06-19 13:03:053317 const char kSdpExtraField[] =
3318 "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:363319 "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 13:03:053320 const char kSdpMissingSpace[] =
3321 "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:363322 "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:583323 // MD5 is not allowed in fingerprints.
Yves Gerey665174f2018-06-19 13:03:053324 const char kSdpMd5[] =
3325 "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:583326 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:363327
3328 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:093329 ExpectParseFailure("v=", kSdpDestroyer);
3330 ExpectParseFailure("o=", kSdpDestroyer);
3331 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363332 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:093333 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363334
3335 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:093336 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
3337 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:363338
3339 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:513340 ExpectParseFailure("a=candidate", kSdpEmptyType);
3341 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
3342 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
3343 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:363344
3345 // Bogus fingerprint replacing a=sendrev. We selected this attribute
3346 // because it's orthogonal to what we are replacing and hence
3347 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:513348 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
3349 ExpectParseFailure("a=sendrecv", kSdpExtraField);
3350 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
3351 ExpectParseFailure("a=sendrecv", kSdpMd5);
3352
3353 // Empty Line
3354 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
3355 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:093356}
3357
3358TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
3359 // ssrc
3360 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:103361 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:093362 // crypto
3363 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
3364 // rtpmap
3365 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
3366 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
3367 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
3368 // candidate
3369 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
3370 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
3371 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
3372 ExpectParseFailure("rport 2346", "rport badvalue");
3373 ExpectParseFailure("rport 2346 generation 2",
3374 "rport 2346 generation badvalue");
3375 // m line
3376 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
3377 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
3378
3379 // bandwidth
3380 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
Yves Gerey665174f2018-06-19 13:03:053381 "b=AS:badvalue\r\n", "b=AS:badvalue");
wu@webrtc.org5e760e72014-04-02 23:19:093382 // rtcp-fb
3383 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3384 "a=rtcp-fb:badvalue nack\r\n",
3385 "a=rtcp-fb:badvalue nack");
3386 // extmap
3387 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
3388 "a=extmap:badvalue http://example.com\r\n",
3389 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:363390}
3391
3392TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
Steve Antona3a92c22017-12-07 18:27:413393 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363394
3395 const char kSdpWithReorderedPlTypesString[] =
3396 "v=0\r\n"
3397 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3398 "s=-\r\n"
3399 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:223400 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
Yves Gerey665174f2018-06-19 13:03:053401 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
3402 // in the map.
henrike@webrtc.org28e20752013-07-10 00:45:363403 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413404 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363405
3406 // Deserialize
3407 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
3408
henrike@webrtc.org28e20752013-07-10 00:45:363409 const AudioContentDescription* acd =
Steve Antonb1c1de12017-12-21 23:14:303410 GetFirstAudioContentDescription(jdesc_output.description());
3411 ASSERT_TRUE(acd);
henrike@webrtc.org28e20752013-07-10 00:45:363412 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:413413 EXPECT_EQ("ISAC", acd->codecs()[0].name);
3414 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:363415 EXPECT_EQ(104, acd->codecs()[0].id);
3416}
3417
3418TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
Steve Antona3a92c22017-12-07 18:27:413419 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363420 CodecParams params;
3421 params.max_ptime = 40;
3422 params.ptime = 30;
3423 params.min_ptime = 10;
3424 params.sprop_stereo = 1;
3425 params.stereo = 1;
3426 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:593427 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:363428 TestDeserializeCodecParams(params, &jdesc_output);
Steve Antone831b8c2018-02-01 20:22:163429 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363430}
3431
3432TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
3433 const bool kUseWildcard = false;
Steve Antona3a92c22017-12-07 18:27:413434 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363435 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163436 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363437}
3438
3439TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
3440 const bool kUseWildcard = true;
Steve Antona3a92c22017-12-07 18:27:413441 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363442 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
Steve Antone831b8c2018-02-01 20:22:163443 TestSerialize(jdesc_output);
henrike@webrtc.org28e20752013-07-10 00:45:363444}
3445
3446TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
Steve Antona3a92c22017-12-07 18:27:413447 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363448
3449 const char kSdpWithFmtpString[] =
3450 "v=0\r\n"
3451 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3452 "s=-\r\n"
3453 "t=0 0\r\n"
3454 "m=video 3457 RTP/SAVPF 120\r\n"
3455 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:233456 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
3457
3458 // Deserialize
3459 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:243460 EXPECT_TRUE(
3461 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:233462
Donald Curtis0e07f922015-05-15 16:21:233463 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303464 GetFirstVideoContentDescription(jdesc_output.description());
3465 ASSERT_TRUE(vcd);
Donald Curtis0e07f922015-05-15 16:21:233466 ASSERT_FALSE(vcd->codecs().empty());
3467 cricket::VideoCodec vp8 = vcd->codecs()[0];
3468 EXPECT_EQ("VP8", vp8.name);
3469 EXPECT_EQ(120, vp8.id);
3470 cricket::CodecParameterMap::iterator found =
3471 vp8.params.find("x-google-min-bitrate");
3472 ASSERT_TRUE(found != vp8.params.end());
3473 EXPECT_EQ(found->second, "10");
3474 found = vp8.params.find("x-google-max-quantization");
3475 ASSERT_TRUE(found != vp8.params.end());
3476 EXPECT_EQ(found->second, "40");
3477}
3478
johan2d8d23e2016-06-03 08:22:423479TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
Steve Antona3a92c22017-12-07 18:27:413480 JsepSessionDescription jdesc_output(kDummyType);
johan2d8d23e2016-06-03 08:22:423481
3482 const char kSdpWithFmtpString[] =
3483 "v=0\r\n"
3484 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3485 "s=-\r\n"
3486 "t=0 0\r\n"
3487 "m=video 49170 RTP/AVP 98\r\n"
3488 "a=rtpmap:98 H264/90000\r\n"
3489 "a=fmtp:98 profile-level-id=42A01E; "
3490 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
3491
3492 // Deserialize.
3493 SdpParseError error;
3494 EXPECT_TRUE(
3495 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
3496
johan2d8d23e2016-06-03 08:22:423497 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303498 GetFirstVideoContentDescription(jdesc_output.description());
3499 ASSERT_TRUE(vcd);
johan2d8d23e2016-06-03 08:22:423500 ASSERT_FALSE(vcd->codecs().empty());
3501 cricket::VideoCodec h264 = vcd->codecs()[0];
3502 EXPECT_EQ("H264", h264.name);
3503 EXPECT_EQ(98, h264.id);
3504 cricket::CodecParameterMap::const_iterator found =
3505 h264.params.find("profile-level-id");
3506 ASSERT_TRUE(found != h264.params.end());
3507 EXPECT_EQ(found->second, "42A01E");
3508 found = h264.params.find("sprop-parameter-sets");
3509 ASSERT_TRUE(found != h264.params.end());
3510 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3511}
3512
Donald Curtis0e07f922015-05-15 16:21:233513TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
Steve Antona3a92c22017-12-07 18:27:413514 JsepSessionDescription jdesc_output(kDummyType);
Donald Curtis0e07f922015-05-15 16:21:233515
3516 const char kSdpWithFmtpString[] =
3517 "v=0\r\n"
3518 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3519 "s=-\r\n"
3520 "t=0 0\r\n"
3521 "m=video 3457 RTP/SAVPF 120\r\n"
3522 "a=rtpmap:120 VP8/90000\r\n"
3523 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363524
3525 // Deserialize
3526 SdpParseError error;
Yves Gerey665174f2018-06-19 13:03:053527 EXPECT_TRUE(
3528 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
henrike@webrtc.org28e20752013-07-10 00:45:363529
henrike@webrtc.org28e20752013-07-10 00:45:363530 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:303531 GetFirstVideoContentDescription(jdesc_output.description());
3532 ASSERT_TRUE(vcd);
henrike@webrtc.org28e20752013-07-10 00:45:363533 ASSERT_FALSE(vcd->codecs().empty());
3534 cricket::VideoCodec vp8 = vcd->codecs()[0];
3535 EXPECT_EQ("VP8", vp8.name);
3536 EXPECT_EQ(120, vp8.id);
3537 cricket::CodecParameterMap::iterator found =
3538 vp8.params.find("x-google-min-bitrate");
3539 ASSERT_TRUE(found != vp8.params.end());
3540 EXPECT_EQ(found->second, "10");
3541 found = vp8.params.find("x-google-max-quantization");
3542 ASSERT_TRUE(found != vp8.params.end());
3543 EXPECT_EQ(found->second, "40");
3544}
3545
Mirta Dvornicic479a3c02019-06-04 13:38:503546TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) {
3547 JsepSessionDescription jdesc_output(kDummyType);
3548
3549 const char kSdpWithPacketizationString[] =
3550 "v=0\r\n"
3551 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3552 "s=-\r\n"
3553 "t=0 0\r\n"
3554 "m=audio 9 RTP/SAVPF 111\r\n"
3555 "a=rtpmap:111 opus/48000/2\r\n"
3556 "a=packetization:111 unknownpacketizationattributeforaudio\r\n"
3557 "m=video 3457 RTP/SAVPF 120 121 122\r\n"
3558 "a=rtpmap:120 VP8/90000\r\n"
3559 "a=packetization:120 raw\r\n"
3560 "a=rtpmap:121 VP9/90000\r\n"
3561 "a=rtpmap:122 H264/90000\r\n"
3562 "a=packetization:122 unknownpacketizationattributevalue\r\n";
3563
3564 SdpParseError error;
3565 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output,
3566 &error));
3567
3568 AudioContentDescription* acd =
3569 GetFirstAudioContentDescription(jdesc_output.description());
3570 ASSERT_TRUE(acd);
3571 ASSERT_THAT(acd->codecs(), testing::SizeIs(1));
3572 cricket::AudioCodec opus = acd->codecs()[0];
3573 EXPECT_EQ(opus.name, "opus");
3574 EXPECT_EQ(opus.id, 111);
3575
3576 const VideoContentDescription* vcd =
3577 GetFirstVideoContentDescription(jdesc_output.description());
3578 ASSERT_TRUE(vcd);
3579 ASSERT_THAT(vcd->codecs(), testing::SizeIs(3));
3580 cricket::VideoCodec vp8 = vcd->codecs()[0];
3581 EXPECT_EQ(vp8.name, "VP8");
3582 EXPECT_EQ(vp8.id, 120);
3583 EXPECT_EQ(vp8.packetization, "raw");
3584 cricket::VideoCodec vp9 = vcd->codecs()[1];
3585 EXPECT_EQ(vp9.name, "VP9");
3586 EXPECT_EQ(vp9.id, 121);
3587 EXPECT_EQ(vp9.packetization, absl::nullopt);
3588 cricket::VideoCodec h264 = vcd->codecs()[2];
3589 EXPECT_EQ(h264.name, "H264");
3590 EXPECT_EQ(h264.id, 122);
3591 EXPECT_EQ(h264.packetization, absl::nullopt);
3592}
3593
ossuaa4b0772017-01-30 15:41:183594TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
Steve Antonb1c1de12017-12-21 23:14:303595 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183596
3597 cricket::AudioCodecs codecs = acd->codecs();
3598 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3599 acd->set_codecs(codecs);
3600
Harald Alvestrand4d7160e2019-04-12 05:01:293601 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183602 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163603 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183604 std::string sdp_with_fmtp = kSdpFullString;
3605 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3606 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3607 &sdp_with_fmtp);
3608 EXPECT_EQ(sdp_with_fmtp, message);
3609}
3610
3611TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
Steve Antonb1c1de12017-12-21 23:14:303612 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183613
3614 cricket::AudioCodecs codecs = acd->codecs();
3615 codecs[0].params["stereo"] = "1";
3616 acd->set_codecs(codecs);
3617
Harald Alvestrand4d7160e2019-04-12 05:01:293618 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183619 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163620 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183621 std::string sdp_with_fmtp = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053622 InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n",
ossuaa4b0772017-01-30 15:41:183623 &sdp_with_fmtp);
3624 EXPECT_EQ(sdp_with_fmtp, message);
3625}
3626
3627TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
Steve Antonb1c1de12017-12-21 23:14:303628 AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_);
ossuaa4b0772017-01-30 15:41:183629
3630 cricket::AudioCodecs codecs = acd->codecs();
3631 codecs[0].params["ptime"] = "20";
3632 codecs[0].params["maxptime"] = "120";
3633 acd->set_codecs(codecs);
3634
Harald Alvestrand4d7160e2019-04-12 05:01:293635 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
ossuaa4b0772017-01-30 15:41:183636 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163637 std::string message = webrtc::SdpSerialize(jdesc_);
ossuaa4b0772017-01-30 15:41:183638 std::string sdp_with_fmtp = kSdpFullString;
3639 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3640 "a=maxptime:120\r\n" // No comma here. String merging!
3641 "a=ptime:20\r\n",
3642 &sdp_with_fmtp);
3643 EXPECT_EQ(sdp_with_fmtp, message);
3644}
3645
henrike@webrtc.org28e20752013-07-10 00:45:363646TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
Steve Antonb1c1de12017-12-21 23:14:303647 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
henrike@webrtc.org28e20752013-07-10 00:45:363648
3649 cricket::VideoCodecs codecs = vcd->codecs();
3650 codecs[0].params["x-google-min-bitrate"] = "10";
3651 vcd->set_codecs(codecs);
3652
Harald Alvestrand4d7160e2019-04-12 05:01:293653 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
henrike@webrtc.org28e20752013-07-10 00:45:363654 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163655 std::string message = webrtc::SdpSerialize(jdesc_);
henrike@webrtc.org28e20752013-07-10 00:45:363656 std::string sdp_with_fmtp = kSdpFullString;
3657 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
Yves Gerey665174f2018-06-19 13:03:053658 "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp);
henrike@webrtc.org28e20752013-07-10 00:45:363659 EXPECT_EQ(sdp_with_fmtp, message);
3660}
3661
Mirta Dvornicic479a3c02019-06-04 13:38:503662TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) {
3663 VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_);
3664
3665 cricket::VideoCodecs codecs = vcd->codecs();
3666 codecs[0].packetization = "raw";
3667 vcd->set_codecs(codecs);
3668
3669 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
3670 jdesc_.session_version()));
3671 std::string message = webrtc::SdpSerialize(jdesc_);
3672 std::string sdp_with_packetization = kSdpFullString;
3673 InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n",
3674 &sdp_with_packetization);
3675 EXPECT_EQ(sdp_with_packetization, message);
3676}
3677
Taylor Brandstetter2f65ec52018-05-24 18:37:283678TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) {
3679 // Deserialize the baseline description, making sure it's ICE full.
Steve Antona3a92c22017-12-07 18:27:413680 JsepSessionDescription jdesc_with_icelite(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363681 std::string sdp_with_icelite = kSdpFullString;
3682 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3683 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3684 const cricket::TransportInfo* tinfo1 =
3685 desc->GetTransportInfoByName("audio_content_name");
3686 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3687 const cricket::TransportInfo* tinfo2 =
3688 desc->GetTransportInfoByName("video_content_name");
3689 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283690
3691 // Add "a=ice-lite" and deserialize, making sure it's ICE lite.
Yves Gerey665174f2018-06-19 13:03:053692 InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363693 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3694 desc = jdesc_with_icelite.description();
3695 const cricket::TransportInfo* atinfo =
3696 desc->GetTransportInfoByName("audio_content_name");
3697 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3698 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053699 desc->GetTransportInfoByName("video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:363700 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
Taylor Brandstetter2f65ec52018-05-24 18:37:283701
3702 // Now that we know deserialization works, we can use TestSerialize to test
3703 // serialization.
3704 TestSerialize(jdesc_with_icelite);
henrike@webrtc.org28e20752013-07-10 00:45:363705}
3706
3707// Verifies that the candidates in the input SDP are parsed and serialized
3708// correctly in the output SDP.
3709TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3710 std::string sdp_with_data = kSdpString;
3711 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
Steve Antona3a92c22017-12-07 18:27:413712 JsepSessionDescription jdesc_output(kDummyType);
henrike@webrtc.org28e20752013-07-10 00:45:363713
3714 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
Steve Antone831b8c2018-02-01 20:22:163715 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output));
henrike@webrtc.org28e20752013-07-10 00:45:363716}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253717
3718TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3719 AddFingerprint();
3720 TransportInfo audio_transport_info =
3721 *(desc_.GetTransportInfoByName(kAudioContentName));
3722 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3723 audio_transport_info.description.connection_role);
3724 audio_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053725 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253726
3727 TransportInfo video_transport_info =
3728 *(desc_.GetTransportInfoByName(kVideoContentName));
3729 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3730 video_transport_info.description.connection_role);
3731 video_transport_info.description.connection_role =
Yves Gerey665174f2018-06-19 13:03:053732 cricket::CONNECTIONROLE_ACTIVE;
sergeyu@chromium.org0be6aa02013-08-23 23:21:253733
3734 desc_.RemoveTransportInfoByName(kAudioContentName);
3735 desc_.RemoveTransportInfoByName(kVideoContentName);
3736
3737 desc_.AddTransportInfo(audio_transport_info);
3738 desc_.AddTransportInfo(video_transport_info);
3739
Harald Alvestrand4d7160e2019-04-12 05:01:293740 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
sergeyu@chromium.org0be6aa02013-08-23 23:21:253741 jdesc_.session_version()));
Steve Antone831b8c2018-02-01 20:22:163742 std::string message = webrtc::SdpSerialize(jdesc_);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253743 std::string sdp_with_dtlssetup = kSdpFullString;
3744
3745 // Fingerprint attribute is necessary to add DTLS setup attribute.
Yves Gerey665174f2018-06-19 13:03:053746 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup);
3747 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253748 // Now adding |setup| attribute.
Yves Gerey665174f2018-06-19 13:03:053749 InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253750 EXPECT_EQ(sdp_with_dtlssetup, message);
3751}
3752
3753TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
Steve Antona3a92c22017-12-07 18:27:413754 JsepSessionDescription jdesc_with_dtlssetup(kDummyType);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253755 std::string sdp_with_dtlssetup = kSdpFullString;
Yves Gerey665174f2018-06-19 13:03:053756 InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253757 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3758 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3759 const cricket::TransportInfo* atinfo =
3760 desc->GetTransportInfoByName("audio_content_name");
3761 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3762 atinfo->description.connection_role);
3763 const cricket::TransportInfo* vtinfo =
Yves Gerey665174f2018-06-19 13:03:053764 desc->GetTransportInfoByName("video_content_name");
sergeyu@chromium.org0be6aa02013-08-23 23:21:253765 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3766 vtinfo->description.connection_role);
3767}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053768
3769// Verifies that the order of the serialized m-lines follows the order of the
3770// ContentInfo in SessionDescription, and vise versa for deserialization.
3771TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
Steve Antona3a92c22017-12-07 18:27:413772 JsepSessionDescription jdesc(kDummyType);
Yves Gerey665174f2018-06-19 13:03:053773 const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString,
3774 kSdpSctpDataChannelString};
3775 const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO,
3776 cricket::MEDIA_TYPE_VIDEO,
3777 cricket::MEDIA_TYPE_DATA};
jiayl@webrtc.orge7d47a12014-08-05 19:19:053778
3779 // Verifies all 6 permutations.
3780 for (size_t i = 0; i < 6; ++i) {
3781 size_t media_content_in_sdp[3];
3782 // The index of the first media content.
3783 media_content_in_sdp[0] = i / 2;
3784 // The index of the second media content.
3785 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3786 // The index of the third media content.
3787 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3788
3789 std::string sdp_string = kSdpSessionString;
3790 for (size_t i = 0; i < 3; ++i)
3791 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3792
3793 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3794 cricket::SessionDescription* desc = jdesc.description();
3795 EXPECT_EQ(3u, desc->contents().size());
3796
3797 for (size_t i = 0; i < 3; ++i) {
3798 const cricket::MediaContentDescription* mdesc =
Steve Antonb1c1de12017-12-21 23:14:303799 desc->contents()[i].media_description();
jiayl@webrtc.orge7d47a12014-08-05 19:19:053800 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3801 }
3802
Steve Antone831b8c2018-02-01 20:22:163803 std::string serialized_sdp = webrtc::SdpSerialize(jdesc);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053804 EXPECT_EQ(sdp_string, serialized_sdp);
3805 }
3806}
deadbeef9d3584c2016-02-17 01:54:103807
deadbeef25ed4352016-12-13 02:37:363808TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3809 MakeBundleOnlyDescription();
Steve Antona3a92c22017-12-07 18:27:413810 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473811 ASSERT_TRUE(
deadbeef25ed4352016-12-13 02:37:363812 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3813 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3814}
3815
deadbeef12771a12017-01-03 21:53:473816// The semantics of "a=bundle-only" are only defined when it's used in
3817// combination with a 0 port on the m= line. We should ignore it if used with a
3818// nonzero port.
3819TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3820 // Make the base bundle-only description but unset the bundle-only flag.
3821 MakeBundleOnlyDescription();
3822 jdesc_.description()->contents()[1].bundle_only = false;
3823
3824 std::string modified_sdp = kBundleOnlySdpFullString;
3825 Replace("m=video 0", "m=video 9", &modified_sdp);
Steve Antona3a92c22017-12-07 18:27:413826 JsepSessionDescription deserialized_description(kDummyType);
deadbeef12771a12017-01-03 21:53:473827 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3828 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-13 02:37:363829}
3830
3831TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3832 MakeBundleOnlyDescription();
Steve Antone831b8c2018-02-01 20:22:163833 TestSerialize(jdesc_);
deadbeef25ed4352016-12-13 02:37:363834}
3835
deadbeef9d3584c2016-02-17 01:54:103836TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3837 MakePlanBDescription();
3838
Steve Antona3a92c22017-12-07 18:27:413839 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103840 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3841
3842 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3843}
3844
3845TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3846 MakePlanBDescription();
Steve Antone831b8c2018-02-01 20:22:163847 TestSerialize(jdesc_);
deadbeef9d3584c2016-02-17 01:54:103848}
3849
3850TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3851 MakeUnifiedPlanDescription();
3852
Steve Antona3a92c22017-12-07 18:27:413853 JsepSessionDescription deserialized_description(kDummyType);
deadbeef9d3584c2016-02-17 01:54:103854 EXPECT_TRUE(
3855 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3856
3857 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3858}
3859
3860TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3861 MakeUnifiedPlanDescription();
Steve Antone831b8c2018-02-01 20:22:163862 TestSerialize(jdesc_);
3863}
3864
Seth Hampson5b4f0752018-04-02 23:31:363865// This tests deserializing a Unified Plan SDP that is compatible with both
Seth Hampson7fa6ee62018-10-17 17:25:283866// Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc
3867// msid" lines and "a=msid " lines. It tests the case for audio/video tracks
Seth Hampson5b4f0752018-04-02 23:31:363868// with no stream ids and multiple stream ids. For parsing this, the Unified
3869// Plan a=msid lines should take priority, because the Plan B style a=ssrc msid
3870// lines do not support multiple stream ids and no stream ids.
Seth Hampson7fa6ee62018-10-17 17:25:283871TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) {
3872 // Create both msid lines for Plan B and Unified Plan support.
3873 MakeUnifiedPlanDescriptionMultipleStreamIds(
3874 cricket::kMsidSignalingMediaSection |
3875 cricket::kMsidSignalingSsrcAttribute);
Seth Hampson5b4f0752018-04-02 23:31:363876
3877 JsepSessionDescription deserialized_description(kDummyType);
3878 EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid,
3879 &deserialized_description));
3880
3881 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
Henrik Boström5b147782018-12-04 10:25:053882 EXPECT_EQ(cricket::kMsidSignalingMediaSection |
3883 cricket::kMsidSignalingSsrcAttribute,
3884 deserialized_description.description()->msid_signaling());
Seth Hampson5b4f0752018-04-02 23:31:363885}
3886
Seth Hampson7fa6ee62018-10-17 17:25:283887// Tests the serialization of a Unified Plan SDP that is compatible for both
3888// Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc
3889// msid" lines and "a=msid " lines. It tests the case for no stream ids and
3890// multiple stream ids.
3891TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) {
3892 // Create both msid lines for Plan B and Unified Plan support.
3893 MakeUnifiedPlanDescriptionMultipleStreamIds(
3894 cricket::kMsidSignalingMediaSection |
3895 cricket::kMsidSignalingSsrcAttribute);
3896 std::string serialized_sdp = webrtc::SdpSerialize(jdesc_);
3897 // We explicitly test that the serialized SDP string is equal to the hard
3898 // coded SDP string. This is necessary, because in the parser "a=msid" lines
3899 // take priority over "a=ssrc msid" lines. This means if we just used
3900 // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines,
3901 // and still pass, because the deserialized version would be the same.
3902 EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp);
3903}
3904
3905// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3906// that signal stream IDs) is deserialized appropriately. It tests the case for
3907// no stream ids and multiple stream ids.
3908TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) {
3909 // Only create a=msid lines for strictly Unified Plan stream ID support.
3910 MakeUnifiedPlanDescriptionMultipleStreamIds(
3911 cricket::kMsidSignalingMediaSection);
3912
3913 JsepSessionDescription deserialized_description(kDummyType);
3914 std::string unified_plan_sdp_string =
3915 kUnifiedPlanSdpFullStringWithSpecialMsid;
3916 RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string);
3917 EXPECT_TRUE(
3918 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3919
3920 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3921}
3922
3923// Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines
3924// that signal stream IDs) is serialized appropriately. It tests the case for no
3925// stream ids and multiple stream ids.
3926TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) {
3927 // Only create a=msid lines for strictly Unified Plan stream ID support.
3928 MakeUnifiedPlanDescriptionMultipleStreamIds(
3929 cricket::kMsidSignalingMediaSection);
3930
Seth Hampson5b4f0752018-04-02 23:31:363931 TestSerialize(jdesc_);
3932}
3933
Seth Hampson5897a6e2018-04-03 18:16:333934// This tests that a Unified Plan SDP with no a=ssrc lines is
3935// serialized/deserialized appropriately. In this case the
3936// MediaContentDescription will contain a StreamParams object that doesn't have
3937// any SSRCs. Vice versa, this will be created upon deserializing an SDP with no
3938// SSRC lines.
3939TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3940 MakeUnifiedPlanDescription();
3941 RemoveSsrcSignalingFromStreamParams();
3942 std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString;
3943 RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string);
3944
3945 JsepSessionDescription deserialized_description(kDummyType);
3946 EXPECT_TRUE(
3947 SdpDeserialize(unified_plan_sdp_string, &deserialized_description));
3948 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3949}
3950
3951TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) {
3952 MakeUnifiedPlanDescription();
3953 RemoveSsrcSignalingFromStreamParams();
3954
3955 TestSerialize(jdesc_);
3956}
3957
Steve Antone831b8c2018-02-01 20:22:163958TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) {
3959 JsepSessionDescription jsep_desc(kDummyType);
3960 ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc));
3961 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3962}
3963
3964TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) {
3965 JsepSessionDescription jsep_desc(kDummyType);
3966 std::string sdp = kSdpSessionString;
3967 sdp += kSdpSctpDataChannelString;
3968 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3969 EXPECT_EQ(0, jsep_desc.description()->msid_signaling());
3970}
3971
3972TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) {
3973 JsepSessionDescription jsep_desc(kDummyType);
3974 ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc));
3975 EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute,
3976 jsep_desc.description()->msid_signaling());
3977}
3978
3979TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) {
3980 JsepSessionDescription jsep_desc(kDummyType);
3981 ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc));
3982 EXPECT_EQ(cricket::kMsidSignalingMediaSection,
3983 jsep_desc.description()->msid_signaling());
3984}
3985
3986const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1";
3987const char kSsrcAttributeMsidLine[] =
3988 "a=ssrc:1 msid:local_stream_1 audio_track_id_1";
3989
3990TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) {
3991 jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection);
3992 std::string sdp = webrtc::SdpSerialize(jdesc_);
3993
3994 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
3995 EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
3996}
3997
3998TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) {
3999 jdesc_.description()->set_msid_signaling(
4000 cricket::kMsidSignalingSsrcAttribute);
4001 std::string sdp = webrtc::SdpSerialize(jdesc_);
4002
4003 EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine));
4004 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
4005}
4006
4007TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) {
4008 jdesc_.description()->set_msid_signaling(
4009 cricket::kMsidSignalingMediaSection |
4010 cricket::kMsidSignalingSsrcAttribute);
4011 std::string sdp = webrtc::SdpSerialize(jdesc_);
4012
4013 EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine));
4014 EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine));
deadbeef9d3584c2016-02-17 01:54:104015}
deadbeef7e146cb2016-09-28 17:04:344016
4017// Regression test for heap overflow bug:
4018// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
4019TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 17:04:344020 // The issue occurs when the sctp-port attribute is found in a video
4021 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 20:43:584022 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 17:04:344023 "v=0\r\n"
4024 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4025 "s=-\r\n"
4026 "t=0 0\r\n"
4027 "m=video 9 UDP/DTLS/SCTP 120\r\n"
4028 "a=sctp-port 5000\r\n"
4029 "a=fmtp:108 foo=10\r\n";
4030
4031 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
4032 "sctp-port");
4033}
deadbeefb2362572016-12-14 00:37:064034
4035// Regression test for integer overflow bug:
4036// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
4037TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-14 00:37:064038 // Bandwidth attribute is the max signed 32-bit int, which will get
4039 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 20:43:584040 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-14 00:37:064041 "v=0\r\n"
4042 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4043 "s=-\r\n"
4044 "t=0 0\r\n"
4045 "m=video 3457 RTP/SAVPF 120\r\n"
4046 "b=AS:2147483647\r\n"
4047 "foo=fail\r\n";
4048
4049 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
4050}
deadbeef7bcdb692017-01-20 20:43:584051
deadbeefbc88c6b2017-08-02 18:26:344052// Similar to the above, except that negative values are illegal, not just
4053// error-prone as large values are.
4054// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
4055TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
4056 static const char kSdpWithNegativeBandwidth[] =
4057 "v=0\r\n"
4058 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4059 "s=-\r\n"
4060 "t=0 0\r\n"
4061 "m=video 3457 RTP/SAVPF 120\r\n"
4062 "b=AS:-1000\r\n";
4063
4064 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
4065}
4066
deadbeef3e8016e2017-08-04 00:49:304067// An exception to the above rule: a value of -1 for b=AS should just be
4068// ignored, resulting in "kAutoBandwidth" in the deserialized object.
4069// Applications historically may be using "b=AS:-1" to mean "no bandwidth
4070// limit", but this is now what ommitting the attribute entirely will do, so
4071// ignoring it will have the intended effect.
4072TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
4073 static const char kSdpWithBandwidthOfNegativeOne[] =
4074 "v=0\r\n"
4075 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4076 "s=-\r\n"
4077 "t=0 0\r\n"
4078 "m=video 3457 RTP/SAVPF 120\r\n"
4079 "b=AS:-1\r\n";
4080
Steve Antona3a92c22017-12-07 18:27:414081 JsepSessionDescription jdesc_output(kDummyType);
deadbeef3e8016e2017-08-04 00:49:304082 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
deadbeef3e8016e2017-08-04 00:49:304083 const VideoContentDescription* vcd =
Steve Antonb1c1de12017-12-21 23:14:304084 GetFirstVideoContentDescription(jdesc_output.description());
4085 ASSERT_TRUE(vcd);
deadbeef3e8016e2017-08-04 00:49:304086 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
4087}
4088
deadbeef7bcdb692017-01-20 20:43:584089// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
4090// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4091// Regression test for:
4092// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
4093TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
4094 // Important piece is "ufrag foo pwd bar".
4095 static const char kSdpWithIceCredentialsInCandidateString[] =
4096 "v=0\r\n"
4097 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4098 "s=-\r\n"
4099 "t=0 0\r\n"
4100 "m=audio 9 RTP/SAVPF 111\r\n"
4101 "c=IN IP4 0.0.0.0\r\n"
4102 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4103 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4104 "a=rtpmap:111 opus/48000/2\r\n"
4105 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4106 "generation 2 ufrag foo pwd bar\r\n";
4107
Steve Antona3a92c22017-12-07 18:27:414108 JsepSessionDescription jdesc_output(kDummyType);
deadbeef7bcdb692017-01-20 20:43:584109 EXPECT_TRUE(
4110 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
4111 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4112 ASSERT_NE(nullptr, candidates);
Mirko Bonadeie12c1fe2018-07-03 10:53:234113 ASSERT_EQ(1U, candidates->count());
deadbeef7bcdb692017-01-20 20:43:584114 cricket::Candidate c = candidates->at(0)->candidate();
4115 EXPECT_EQ("ufrag_voice", c.username());
4116 EXPECT_EQ("pwd_voice", c.password());
4117}
deadbeef90f1e1e2017-02-10 20:35:054118
Johannes Kron211856b2018-09-06 10:12:284119// Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are
4120// ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
4121// Regression test for:
4122// https://bugs.chromium.org/p/webrtc/issues/detail?id=9712
4123TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) {
4124 static const char kSdpWithFooIceCredentials[] =
4125 "v=0\r\n"
4126 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4127 "s=-\r\n"
4128 "t=0 0\r\n"
4129 "m=audio 9 RTP/SAVPF 111\r\n"
4130 "c=IN IP4 0.0.0.0\r\n"
4131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4132 "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n"
4133 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4134 "a=rtpmap:111 opus/48000/2\r\n"
4135 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
4136 "generation 2\r\n";
4137
4138 JsepSessionDescription jdesc_output(kDummyType);
4139 EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output));
4140 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
4141 ASSERT_NE(nullptr, candidates);
4142 ASSERT_EQ(1U, candidates->count());
4143 cricket::Candidate c = candidates->at(0)->candidate();
4144 EXPECT_EQ("ufrag_voice", c.username());
4145 EXPECT_EQ("pwd_voice", c.password());
4146}
4147
deadbeef90f1e1e2017-02-10 20:35:054148// Test that SDP with an invalid port number in "a=candidate" lines is
4149// rejected, without crashing.
4150// Regression test for:
4151// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
4152TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
4153 static const char kSdpWithInvalidCandidatePort[] =
4154 "v=0\r\n"
4155 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4156 "s=-\r\n"
4157 "t=0 0\r\n"
4158 "m=audio 9 RTP/SAVPF 111\r\n"
4159 "c=IN IP4 0.0.0.0\r\n"
4160 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
4161 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
4162 "a=rtpmap:111 opus/48000/2\r\n"
4163 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
4164 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
4165
Steve Antona3a92c22017-12-07 18:27:414166 JsepSessionDescription jdesc_output(kDummyType);
deadbeef90f1e1e2017-02-10 20:35:054167 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
4168}
deadbeefa4549d62017-02-11 01:26:224169
4170// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
4171// Regression test for:
4172// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
4173TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
4174 static const char kSdpWithMissingTrackId[] =
4175 "v=0\r\n"
4176 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4177 "s=-\r\n"
4178 "t=0 0\r\n"
4179 "m=audio 9 RTP/SAVPF 111\r\n"
4180 "c=IN IP4 0.0.0.0\r\n"
4181 "a=rtpmap:111 opus/48000/2\r\n"
4182 "a=msid:stream_id \r\n";
4183
Steve Antona3a92c22017-12-07 18:27:414184 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224185 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
4186}
4187
4188TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
4189 static const char kSdpWithMissingStreamId[] =
4190 "v=0\r\n"
4191 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
4192 "s=-\r\n"
4193 "t=0 0\r\n"
4194 "m=audio 9 RTP/SAVPF 111\r\n"
4195 "c=IN IP4 0.0.0.0\r\n"
4196 "a=rtpmap:111 opus/48000/2\r\n"
4197 "a=msid: track_id\r\n";
4198
Steve Antona3a92c22017-12-07 18:27:414199 JsepSessionDescription jdesc_output(kDummyType);
deadbeefa4549d62017-02-11 01:26:224200 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
4201}
zhihuang38989e52017-03-21 18:04:534202
4203// Tests that if both session-level address and media-level address exist, use
4204// the media-level address.
4205TEST_F(WebRtcSdpTest, ParseConnectionData) {
Steve Antona3a92c22017-12-07 18:27:414206 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534207
4208 // Sesssion-level address.
4209 std::string sdp = kSdpFullString;
4210 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4211 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4212
4213 const auto& content1 = jsep_desc.description()->contents()[0];
4214 EXPECT_EQ("74.125.127.126:2345",
Steve Antonb1c1de12017-12-21 23:14:304215 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534216 const auto& content2 = jsep_desc.description()->contents()[1];
4217 EXPECT_EQ("74.125.224.39:3457",
Steve Antonb1c1de12017-12-21 23:14:304218 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534219}
4220
4221// Tests that the session-level connection address will be used if the media
4222// level-addresses are not specified.
4223TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
Steve Antona3a92c22017-12-07 18:27:414224 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534225
4226 // Sesssion-level address.
4227 std::string sdp = kSdpString;
4228 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
4229 // Remove the media level addresses.
4230 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4231 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
4232 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4233
4234 const auto& content1 = jsep_desc.description()->contents()[0];
4235 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304236 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534237 const auto& content2 = jsep_desc.description()->contents()[1];
4238 EXPECT_EQ("192.168.0.3:9",
Steve Antonb1c1de12017-12-21 23:14:304239 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534240}
4241
4242TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
Steve Antona3a92c22017-12-07 18:27:414243 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534244
4245 std::string sdp = kSdpString;
4246 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4247 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
4248 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
4249 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
4250 &sdp);
4251 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
4252 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
4253 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
4254 &sdp);
4255 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4256 const auto& content1 = jsep_desc.description()->contents()[0];
4257 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
Steve Antonb1c1de12017-12-21 23:14:304258 content1.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534259 const auto& content2 = jsep_desc.description()->contents()[1];
4260 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
Steve Antonb1c1de12017-12-21 23:14:304261 content2.media_description()->connection_address().ToString());
zhihuang38989e52017-03-21 18:04:534262}
4263
Qingsi Wang56991422019-02-08 20:53:064264// Test that a c= line that contains a hostname connection address can be
4265// parsed.
4266TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) {
4267 JsepSessionDescription jsep_desc(kDummyType);
4268 std::string sdp = kSdpString;
4269 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4270
4271 sdp = kSdpString;
4272 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4273 Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp);
4274 ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4275
4276 ASSERT_NE(nullptr, jsep_desc.description());
4277 const auto& content1 = jsep_desc.description()->contents()[0];
4278 EXPECT_EQ("example.local:9",
4279 content1.media_description()->connection_address().ToString());
4280 const auto& content2 = jsep_desc.description()->contents()[1];
4281 EXPECT_EQ("example.local:9",
4282 content2.media_description()->connection_address().ToString());
4283}
4284
4285// Test that the invalid or unsupported connection data cannot be parsed.
zhihuang38989e52017-03-21 18:04:534286TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
Steve Antona3a92c22017-12-07 18:27:414287 JsepSessionDescription jsep_desc(kDummyType);
zhihuang38989e52017-03-21 18:04:534288 std::string sdp = kSdpString;
4289 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4290
4291 // Unsupported multicast IPv4 address.
4292 sdp = kSdpFullString;
4293 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
4294 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4295
4296 // Unsupported multicast IPv6 address.
4297 sdp = kSdpFullString;
4298 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
4299 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4300
4301 // Mismatched address type.
4302 sdp = kSdpFullString;
4303 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
4304 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4305
4306 sdp = kSdpFullString;
4307 Replace("c=IN IP4 74.125.224.39\r\n",
4308 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
4309 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
4310}
4311
4312TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
Steve Antona3a92c22017-12-07 18:27:414313 JsepSessionDescription expected_jsep(kDummyType);
zhihuang38989e52017-03-21 18:04:534314 MakeDescriptionWithoutCandidates(&expected_jsep);
4315 // Serialization.
Steve Antone831b8c2018-02-01 20:22:164316 std::string message = webrtc::SdpSerialize(expected_jsep);
zhihuang38989e52017-03-21 18:04:534317 // Deserialization.
Steve Antona3a92c22017-12-07 18:27:414318 JsepSessionDescription jdesc(kDummyType);
zhihuang38989e52017-03-21 18:04:534319 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
Steve Antonb1c1de12017-12-21 23:14:304320 auto audio_desc = jdesc.description()
4321 ->GetContentByName(kAudioContentName)
4322 ->media_description();
4323 auto video_desc = jdesc.description()
4324 ->GetContentByName(kVideoContentName)
4325 ->media_description();
zhihuang38989e52017-03-21 18:04:534326 EXPECT_EQ(audio_desc_->connection_address().ToString(),
4327 audio_desc->connection_address().ToString());
4328 EXPECT_EQ(video_desc_->connection_address().ToString(),
4329 video_desc->connection_address().ToString());
4330}
Taylor Brandstetter93a7b242018-04-16 17:45:244331
4332// RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be
4333// used (i.e., a single space as the session name)." So we should accept that.
4334TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) {
4335 JsepSessionDescription jsep_desc(kDummyType);
4336 std::string sdp = kSdpString;
4337 Replace("s=-\r\n", "s= \r\n", &sdp);
4338 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
4339}
Amit Hilbucha2012042018-12-03 19:35:054340
4341// Simulcast malformed input test for invalid format.
4342TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) {
4343 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4344 "a=simulcast:\r\n", "a=simulcast:");
4345}
4346
4347// Tests that duplicate simulcast entries in the SDP triggers a parse failure.
4348TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) {
4349 ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n",
4350 "a=simulcast:send 1\r\na=simulcast:recv 2\r\n",
4351 "a=simulcast:");
4352}
4353
4354// Validates that deserialization uses the a=simulcast: attribute
4355TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) {
Amit Hilbuchc57d5732018-12-11 23:30:114356 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4357 sdp += "a=rid:1 send\r\n";
4358 sdp += "a=rid:2 send\r\n";
4359 sdp += "a=rid:3 send\r\n";
4360 sdp += "a=rid:4 recv\r\n";
4361 sdp += "a=rid:5 recv\r\n";
4362 sdp += "a=rid:6 recv\r\n";
Amit Hilbucha2012042018-12-03 19:35:054363 sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n";
4364 JsepSessionDescription output(kDummyType);
4365 SdpParseError error;
4366 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4367 const cricket::ContentInfos& contents = output.description()->contents();
4368 const cricket::MediaContentDescription* media =
4369 contents.back().media_description();
4370 EXPECT_TRUE(media->HasSimulcast());
4371 EXPECT_EQ(2ul, media->simulcast_description().send_layers().size());
4372 EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size());
Amit Hilbuchc57d5732018-12-11 23:30:114373 EXPECT_FALSE(media->streams().empty());
4374 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4375 CompareRidDescriptionIds(rids, {"1", "2", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114376}
4377
4378// Validates that deserialization removes rids that do not appear in SDP
4379TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) {
4380 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4381 sdp += "a=rid:1 send\r\n";
4382 sdp += "a=rid:3 send\r\n";
4383 sdp += "a=rid:4 recv\r\n";
4384 sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n";
4385 JsepSessionDescription output(kDummyType);
4386 SdpParseError error;
4387 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4388 const cricket::ContentInfos& contents = output.description()->contents();
4389 const cricket::MediaContentDescription* media =
4390 contents.back().media_description();
4391 EXPECT_TRUE(media->HasSimulcast());
4392 const SimulcastDescription& simulcast = media->simulcast_description();
4393 EXPECT_EQ(2ul, simulcast.send_layers().size());
4394 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4395
4396 std::vector<SimulcastLayer> all_send_layers =
4397 simulcast.send_layers().GetAllLayers();
4398 EXPECT_EQ(2ul, all_send_layers.size());
Steve Anton64b626b2019-01-29 01:25:264399 EXPECT_EQ(0,
4400 absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) {
4401 return layer.rid == "2";
4402 }));
Amit Hilbuchc57d5732018-12-11 23:30:114403
4404 std::vector<SimulcastLayer> all_receive_layers =
4405 simulcast.receive_layers().GetAllLayers();
4406 ASSERT_EQ(1ul, all_receive_layers.size());
4407 EXPECT_EQ("4", all_receive_layers[0].rid);
4408
4409 EXPECT_FALSE(media->streams().empty());
4410 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4411 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114412}
4413
4414// Validates that Simulcast removes rids that appear in both send and receive.
4415TEST_F(WebRtcSdpTest,
4416 TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) {
4417 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4418 sdp += "a=rid:1 send\r\n";
4419 sdp += "a=rid:2 send\r\n";
4420 sdp += "a=rid:3 send\r\n";
4421 sdp += "a=rid:4 recv\r\n";
4422 sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n";
4423 JsepSessionDescription output(kDummyType);
4424 SdpParseError error;
4425 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4426 const cricket::ContentInfos& contents = output.description()->contents();
4427 const cricket::MediaContentDescription* media =
4428 contents.back().media_description();
4429 EXPECT_TRUE(media->HasSimulcast());
4430 const SimulcastDescription& simulcast = media->simulcast_description();
4431 EXPECT_EQ(2ul, simulcast.send_layers().size());
4432 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4433 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4434 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4435
4436 EXPECT_FALSE(media->streams().empty());
4437 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4438 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbuchc57d5732018-12-11 23:30:114439}
4440
4441// Ignores empty rid line.
4442TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) {
4443 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4444 sdp += "a=rid:1 send\r\n";
4445 sdp += "a=rid:2 send\r\n";
4446 sdp += "a=rid\r\n"; // Should ignore this line.
4447 sdp += "a=rid:\r\n"; // Should ignore this line.
4448 sdp += "a=simulcast:send 1;2\r\n";
4449 JsepSessionDescription output(kDummyType);
4450 SdpParseError error;
4451 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4452 const cricket::ContentInfos& contents = output.description()->contents();
4453 const cricket::MediaContentDescription* media =
4454 contents.back().media_description();
4455 EXPECT_TRUE(media->HasSimulcast());
4456 const SimulcastDescription& simulcast = media->simulcast_description();
4457 EXPECT_TRUE(simulcast.receive_layers().empty());
4458 EXPECT_EQ(2ul, simulcast.send_layers().size());
4459 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4460
4461 EXPECT_FALSE(media->streams().empty());
4462 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4463 CompareRidDescriptionIds(rids, {"1", "2"});
Amit Hilbuchc57d5732018-12-11 23:30:114464}
4465
4466// Ignores malformed rid lines.
4467TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) {
4468 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4469 sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line.
4470 sdp += "a=rid:2 receive\r\n"; // Should ignore this line.
4471 sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line.
4472 sdp += "a=rid:4\r\n"; // Should ignore this line.
4473 sdp += "a=rid:5 send\r\n";
4474 sdp += "a=simulcast:send 1,2,3;4,5\r\n";
4475 JsepSessionDescription output(kDummyType);
4476 SdpParseError error;
4477 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4478 const cricket::ContentInfos& contents = output.description()->contents();
4479 const cricket::MediaContentDescription* media =
4480 contents.back().media_description();
4481 EXPECT_TRUE(media->HasSimulcast());
4482 const SimulcastDescription& simulcast = media->simulcast_description();
4483 EXPECT_TRUE(simulcast.receive_layers().empty());
4484 EXPECT_EQ(1ul, simulcast.send_layers().size());
4485 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4486
4487 EXPECT_FALSE(media->streams().empty());
4488 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4489 CompareRidDescriptionIds(rids, {"5"});
Amit Hilbuchc57d5732018-12-11 23:30:114490}
4491
4492// Removes RIDs that specify a different format than the m= section.
4493TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) {
4494 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4495 sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID.
4496 sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether.
4497 sdp += "a=simulcast:send 1;2\r\n";
4498 JsepSessionDescription output(kDummyType);
4499 SdpParseError error;
4500 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4501 const cricket::ContentInfos& contents = output.description()->contents();
4502 const cricket::MediaContentDescription* media =
4503 contents.back().media_description();
4504 EXPECT_TRUE(media->HasSimulcast());
4505 const SimulcastDescription& simulcast = media->simulcast_description();
4506 EXPECT_TRUE(simulcast.receive_layers().empty());
4507 EXPECT_EQ(1ul, simulcast.send_layers().size());
4508 EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size());
4509 EXPECT_EQ("1", simulcast.send_layers()[0][0].rid);
4510 EXPECT_EQ(1ul, media->streams().size());
4511 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4512 EXPECT_EQ(1ul, rids.size());
4513 EXPECT_EQ("1", rids[0].rid);
4514 EXPECT_EQ(1ul, rids[0].payload_types.size());
4515 EXPECT_EQ(120, rids[0].payload_types[0]);
Amit Hilbuchc57d5732018-12-11 23:30:114516}
4517
4518// Ignores duplicate rid lines
4519TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) {
4520 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4521 sdp += "a=rid:1 send\r\n";
4522 sdp += "a=rid:2 send\r\n";
4523 sdp += "a=rid:2 send\r\n";
4524 sdp += "a=rid:3 send\r\n";
4525 sdp += "a=rid:4 recv\r\n";
4526 sdp += "a=simulcast:send 1,2;3 recv 4\r\n";
4527 JsepSessionDescription output(kDummyType);
4528 SdpParseError error;
4529 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4530 const cricket::ContentInfos& contents = output.description()->contents();
4531 const cricket::MediaContentDescription* media =
4532 contents.back().media_description();
4533 EXPECT_TRUE(media->HasSimulcast());
4534 const SimulcastDescription& simulcast = media->simulcast_description();
4535 EXPECT_EQ(2ul, simulcast.send_layers().size());
4536 EXPECT_EQ(1ul, simulcast.receive_layers().size());
4537 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4538 EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size());
4539
4540 EXPECT_FALSE(media->streams().empty());
4541 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4542 CompareRidDescriptionIds(rids, {"1", "3"});
Amit Hilbucha2012042018-12-03 19:35:054543}
4544
Florent Castellic4421972019-07-02 18:27:424545TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) {
4546 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4547 sdp += "a=rid:1 recv\r\n";
4548 sdp += "a=rid:2 recv\r\n";
4549 sdp += "a=simulcast:send 1;2\r\n";
4550 JsepSessionDescription output(kDummyType);
4551 SdpParseError error;
4552 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4553 const cricket::ContentInfos& contents = output.description()->contents();
4554 const cricket::MediaContentDescription* media =
4555 contents.back().media_description();
4556 EXPECT_FALSE(media->HasSimulcast());
4557}
4558
4559TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) {
4560 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4561 sdp += "a=rid:1 send\r\n";
4562 sdp += "a=rid:2 send\r\n";
4563 sdp += "a=simulcast:recv 1;2\r\n";
4564 JsepSessionDescription output(kDummyType);
4565 SdpParseError error;
4566 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4567 const cricket::ContentInfos& contents = output.description()->contents();
4568 const cricket::MediaContentDescription* media =
4569 contents.back().media_description();
4570 EXPECT_FALSE(media->HasSimulcast());
4571}
4572
4573TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) {
4574 std::string sdp = kUnifiedPlanSdpFullStringNoSsrc;
4575 sdp += "a=rid:1 send\r\n";
4576 sdp += "a=rid:2 send\r\n";
4577 sdp += "a=rid:3 send\r\n";
4578 sdp += "a=rid:4 recv\r\n";
4579 sdp += "a=rid:5 recv\r\n";
4580 sdp += "a=rid:6 recv\r\n";
4581 sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n";
4582 JsepSessionDescription output(kDummyType);
4583 SdpParseError error;
4584 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4585 const cricket::ContentInfos& contents = output.description()->contents();
4586 const cricket::MediaContentDescription* media =
4587 contents.back().media_description();
4588 EXPECT_TRUE(media->HasSimulcast());
4589 const SimulcastDescription& simulcast = media->simulcast_description();
4590 EXPECT_EQ(2ul, simulcast.send_layers().size());
4591 EXPECT_EQ(2ul, simulcast.receive_layers().size());
4592 EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size());
4593 EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size());
4594
4595 EXPECT_FALSE(media->streams().empty());
4596 const std::vector<RidDescription>& rids = media->streams()[0].rids();
4597 CompareRidDescriptionIds(rids, {"1", "3"});
4598}
4599
Amit Hilbucha2012042018-12-03 19:35:054600// Simulcast serialization integration test.
4601// This test will serialize and deserialize the description and compare.
4602// More detailed tests for parsing simulcast can be found in
4603// unit tests for SdpSerializer.
4604TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) {
Amit Hilbuchc57d5732018-12-11 23:30:114605 MakeUnifiedPlanDescription(/* use_ssrcs = */ false);
Amit Hilbucha2012042018-12-03 19:35:054606 auto description = jdesc_.description();
4607 auto media = description->GetContentDescriptionByName(kVideoContentName3);
Amit Hilbuchc57d5732018-12-11 23:30:114608 ASSERT_EQ(media->streams().size(), 1ul);
4609 StreamParams& send_stream = media->mutable_streams()[0];
4610 std::vector<RidDescription> send_rids;
4611 send_rids.push_back(RidDescription("1", RidDirection::kSend));
4612 send_rids.push_back(RidDescription("2", RidDirection::kSend));
4613 send_rids.push_back(RidDescription("3", RidDirection::kSend));
4614 send_rids.push_back(RidDescription("4", RidDirection::kSend));
4615 send_stream.set_rids(send_rids);
Florent Castellib60141b2019-07-03 10:47:544616 std::vector<RidDescription> receive_rids;
4617 receive_rids.push_back(RidDescription("5", RidDirection::kReceive));
4618 receive_rids.push_back(RidDescription("6", RidDirection::kReceive));
4619 receive_rids.push_back(RidDescription("7", RidDirection::kReceive));
4620 media->set_receive_rids(receive_rids);
Amit Hilbuchc57d5732018-12-11 23:30:114621
Amit Hilbucha2012042018-12-03 19:35:054622 SimulcastDescription& simulcast = media->simulcast_description();
4623 simulcast.send_layers().AddLayerWithAlternatives(
4624 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
4625 simulcast.send_layers().AddLayerWithAlternatives(
4626 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
Florent Castellib60141b2019-07-03 10:47:544627 simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)});
4628 simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)});
4629 simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)});
Amit Hilbucha2012042018-12-03 19:35:054630
Amit Hilbucha2012042018-12-03 19:35:054631 TestSerialize(jdesc_);
4632}
Steve Anton06817cd2018-12-18 23:55:304633
4634// Test that the content name is empty if the media section does not have an
4635// a=mid line.
4636TEST_F(WebRtcSdpTest, ParseNoMid) {
4637 std::string sdp = kSdpString;
4638 Replace("a=mid:audio_content_name\r\n", "", &sdp);
4639 Replace("a=mid:video_content_name\r\n", "", &sdp);
4640
4641 JsepSessionDescription output(kDummyType);
4642 SdpParseError error;
4643 ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error));
4644
4645 EXPECT_THAT(output.description()->contents(),
4646 ElementsAre(Field("name", &cricket::ContentInfo::name, ""),
4647 Field("name", &cricket::ContentInfo::name, "")));
4648}
Piotr (Peter) Slatala13e570f2019-02-27 19:34:264649
Guido Urdanetacecf87f2019-05-31 10:17:384650TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) {
4651 AddSctpDataChannel(false); // Don't use sctpmap
4652 JsepSessionDescription jsep_desc(kDummyType);
4653 MakeDescriptionWithoutCandidates(&jsep_desc);
4654 std::string message = webrtc::SdpSerialize(jsep_desc);
4655 EXPECT_NE(std::string::npos,
4656 message.find(cricket::kMediaProtocolUdpDtlsSctp));
4657}
4658
4659TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) {
4660 AddSctpDataChannel(false);
4661 std::string protocols[] = {cricket::kMediaProtocolDtlsSctp,
4662 cricket::kMediaProtocolUdpDtlsSctp,
4663 cricket::kMediaProtocolTcpDtlsSctp};
4664 for (const auto& protocol : protocols) {
4665 sctp_desc_->set_protocol(protocol);
4666 JsepSessionDescription jsep_desc(kDummyType);
4667 MakeDescriptionWithoutCandidates(&jsep_desc);
4668 std::string message = webrtc::SdpSerialize(jsep_desc);
4669 EXPECT_NE(std::string::npos, message.find(protocol));
4670 JsepSessionDescription jsep_output(kDummyType);
4671 SdpParseError error;
4672 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error));
4673 }
4674}
Taylor Brandstetter4256df02020-02-18 22:05:074675
4676// According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME
4677// attribute is mandatory, but we relax that restriction.
4678TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) {
4679 std::string sdp_without_cname = kSdpFullString;
4680 Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname);
4681 JsepSessionDescription new_jdesc(kDummyType);
4682 EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc));
4683
4684 audio_desc_->mutable_streams()[0].cname = "";
4685 ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(),
4686 jdesc_.session_version()));
4687 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
4688}