blob: 07270ee7e60eab0590060a6342faa506113c7375 [file] [log] [blame]
Steve Anton4ab68ee2017-12-19 14:26:11 -08001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * 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.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_SESSION_DESCRIPTION_H_
12#define PC_SESSION_DESCRIPTION_H_
Steve Anton4ab68ee2017-12-19 14:26:11 -080013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000017#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010018#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020019#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080020#include <string>
Harald Alvestrand1716d392019-06-03 20:35:45 +020021#include <utility>
Steve Anton4ab68ee2017-12-19 14:26:11 -080022#include <vector>
23
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020024#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/crypto_params.h"
26#include "api/media_types.h"
27#include "api/rtp_parameters.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000028#include "api/rtp_transceiver_direction.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/rtp_transceiver_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000030#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "media/base/media_channel.h"
Taylor Brandstetteree8c2462020-07-27 15:52:02 -070032#include "media/base/media_constants.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000033#include "media/base/rid_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "media/base/stream_params.h"
35#include "p2p/base/transport_description.h"
36#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020037#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "pc/simulcast_description.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000039#include "rtc_base/checks.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020040#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/socket_address.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020042#include "rtc_base/system/rtc_export.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080043
44namespace cricket {
45
Steve Antonafd8e8c2017-12-19 16:35:35 -080046typedef std::vector<AudioCodec> AudioCodecs;
47typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020048typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080049typedef std::vector<CryptoParams> CryptoParamsVec;
50typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
51
52// RTC4585 RTP/AVPF
53extern const char kMediaProtocolAvpf[];
54// RFC5124 RTP/SAVPF
55extern const char kMediaProtocolSavpf[];
56
57extern const char kMediaProtocolDtlsSavpf[];
58
Steve Antonafd8e8c2017-12-19 16:35:35 -080059// Options to control how session descriptions are generated.
60const int kAutoBandwidth = -1;
61
Steve Anton5adfafd2017-12-20 16:34:00 -080062class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070063class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020064class RtpDataContentDescription;
65class SctpDataContentDescription;
Philipp Hancke4e8c1152020-10-13 12:43:15 +020066class UnsupportedContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080067
Steve Anton5adfafd2017-12-20 16:34:00 -080068// Describes a session description media section. There are subclasses for each
69// media type (audio, video, data) that will have additional information.
70class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080071 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080072 MediaContentDescription() = default;
73 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080074
75 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080076
77 // Try to cast this media description to an AudioContentDescription. Returns
78 // nullptr if the cast fails.
79 virtual AudioContentDescription* as_audio() { return nullptr; }
80 virtual const AudioContentDescription* as_audio() const { return nullptr; }
81
82 // Try to cast this media description to a VideoContentDescription. Returns
83 // nullptr if the cast fails.
84 virtual VideoContentDescription* as_video() { return nullptr; }
85 virtual const VideoContentDescription* as_video() const { return nullptr; }
86
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020087 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
88 virtual const RtpDataContentDescription* as_rtp_data() const {
89 return nullptr;
90 }
91
92 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
93 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
94
Philipp Hancke4e8c1152020-10-13 12:43:15 +020095 virtual UnsupportedContentDescription* as_unsupported() { return nullptr; }
96 virtual const UnsupportedContentDescription* as_unsupported() const {
97 return nullptr;
98 }
99
Steve Antonafd8e8c2017-12-19 16:35:35 -0800100 virtual bool has_codecs() const = 0;
101
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100102 // Copy operator that returns an unique_ptr.
103 // Not a virtual function.
104 // If a type-specific variant of Clone() is desired, override it, or
105 // simply use std::make_unique<typename>(*this) instead of Clone().
106 std::unique_ptr<MediaContentDescription> Clone() const {
107 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 20:35:45 +0200108 }
Steve Anton5adfafd2017-12-20 16:34:00 -0800109
Steve Antonafd8e8c2017-12-19 16:35:35 -0800110 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
111 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200112 virtual std::string protocol() const { return protocol_; }
113 virtual void set_protocol(const std::string& protocol) {
114 protocol_ = protocol;
115 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800116
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200117 virtual webrtc::RtpTransceiverDirection direction() const {
118 return direction_;
119 }
120 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800121 direction_ = direction;
122 }
123
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200124 virtual bool rtcp_mux() const { return rtcp_mux_; }
125 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800126
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200127 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
128 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800129 rtcp_reduced_size_ = reduced_size;
130 }
131
Sebastian Jansson97321b62019-07-24 14:01:18 +0200132 // Indicates support for the remote network estimate packet type. This
133 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200134 virtual bool remote_estimate() const { return remote_estimate_; }
135 virtual void set_remote_estimate(bool remote_estimate) {
136 remote_estimate_ = remote_estimate;
137 }
138
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200139 virtual int bandwidth() const { return bandwidth_; }
140 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700141 virtual std::string bandwidth_type() const { return bandwidth_type_; }
142 virtual void set_bandwidth_type(std::string bandwidth_type) {
143 bandwidth_type_ = bandwidth_type;
144 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800145
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
147 virtual void AddCrypto(const CryptoParams& params) {
148 cryptos_.push_back(params);
149 }
150 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800151 cryptos_ = cryptos;
152 }
153
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200154 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800155 return rtp_header_extensions_;
156 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200157 virtual void set_rtp_header_extensions(
158 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800159 rtp_header_extensions_ = extensions;
160 rtp_header_extensions_set_ = true;
161 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200162 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800163 rtp_header_extensions_.push_back(ext);
164 rtp_header_extensions_set_ = true;
165 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200166 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800167 rtp_header_extensions_.clear();
168 rtp_header_extensions_set_ = true;
169 }
170 // We can't always tell if an empty list of header extensions is
171 // because the other side doesn't support them, or just isn't hooked up to
172 // signal them. For now we assume an empty list means no signaling, but
173 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
174 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200175 virtual bool rtp_header_extensions_set() const {
176 return rtp_header_extensions_set_;
177 }
178 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800179 // TODO(pthatcher): Remove this by giving mediamessage.cc access
180 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200181 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
182 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800183 send_streams_.push_back(stream);
184 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 // Legacy streams have an ssrc, but nothing else.
186 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200187 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800188 }
189 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
190 StreamParams sp = StreamParams::CreateLegacy(ssrc);
191 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200192 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800193 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194
Steve Antonafd8e8c2017-12-19 16:35:35 -0800195 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200196 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800197 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
198 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800199 if (it->cname.empty())
200 it->cname = cname;
201 }
202 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200203 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800204 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800205 return 0;
206 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800207 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800208 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200209 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800210 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800211 return false;
212 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800213 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800214 }
215
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200216 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
217 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800218
219 // https://tools.ietf.org/html/rfc4566#section-5.7
220 // May be present at the media or session level of SDP. If present at both
221 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200222 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800223 connection_address_ = address;
224 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200225 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800226 return connection_address_;
227 }
228
Johannes Kron0854eb62018-10-10 22:33:20 +0200229 // Determines if it's allowed to mix one- and two-byte rtp header extensions
230 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200231 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200232 virtual void set_extmap_allow_mixed_enum(
233 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200234 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200235 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200236 // Do not downgrade from session level to media level.
237 return;
238 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200239 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200240 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200241 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200242 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200243 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200244 virtual bool extmap_allow_mixed() const {
245 return extmap_allow_mixed_enum_ != kNo;
246 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200247
Amit Hilbucha2012042018-12-03 11:35:05 -0800248 // Simulcast functionality.
249 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
250 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
251 virtual const SimulcastDescription& simulcast_description() const {
252 return simulcast_;
253 }
254 virtual void set_simulcast_description(
255 const SimulcastDescription& simulcast) {
256 simulcast_ = simulcast;
257 }
Florent Castellib60141b2019-07-03 12:47:54 +0200258 virtual const std::vector<RidDescription>& receive_rids() const {
259 return receive_rids_;
260 }
261 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
262 receive_rids_ = rids;
263 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800264
Steve Antonafd8e8c2017-12-19 16:35:35 -0800265 protected:
266 bool rtcp_mux_ = false;
267 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200268 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800269 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700270 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800271 std::string protocol_;
272 std::vector<CryptoParams> cryptos_;
273 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
274 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800275 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800276 bool conference_mode_ = false;
277 webrtc::RtpTransceiverDirection direction_ =
278 webrtc::RtpTransceiverDirection::kSendRecv;
279 rtc::SocketAddress connection_address_;
Emil Lundmark801c9992021-01-19 13:06:32 +0100280 ExtmapAllowMixed extmap_allow_mixed_enum_ = kMedia;
Amit Hilbucha2012042018-12-03 11:35:05 -0800281
282 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200283 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700284
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100285 private:
286 // Copy function that returns a raw pointer. Caller will assert ownership.
287 // Should only be called by the Clone() function. Must be implemented
288 // by each final subclass.
289 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800290};
291
292template <class C>
293class MediaContentDescriptionImpl : public MediaContentDescription {
294 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200295 void set_protocol(const std::string& protocol) override {
296 RTC_DCHECK(IsRtpProtocol(protocol));
297 protocol_ = protocol;
298 }
299
Steve Antonafd8e8c2017-12-19 16:35:35 -0800300 typedef C CodecType;
301
302 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200303 virtual const std::vector<C>& codecs() const { return codecs_; }
304 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
305 bool has_codecs() const override { return !codecs_.empty(); }
306 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800307 bool found = false;
308 for (typename std::vector<C>::iterator iter = codecs_.begin();
309 iter != codecs_.end(); ++iter) {
310 if (iter->id == id) {
311 found = true;
312 break;
313 }
314 }
315 return found;
316 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200317 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
318 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800319 for (typename std::vector<C>::iterator iter = codecs_.begin();
320 iter != codecs_.end(); ++iter) {
321 if (iter->id == codec.id) {
322 *iter = codec;
323 return;
324 }
325 }
326 AddCodec(codec);
327 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200328 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800329 typename std::vector<C>::const_iterator codec;
330 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
331 AddCodec(*codec);
332 }
333 }
334
335 private:
336 std::vector<C> codecs_;
337};
338
339class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
340 public:
341 AudioContentDescription() {}
342
Steve Antonafd8e8c2017-12-19 16:35:35 -0800343 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800344 virtual AudioContentDescription* as_audio() { return this; }
345 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100346
347 private:
348 virtual AudioContentDescription* CloneInternal() const {
349 return new AudioContentDescription(*this);
350 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800351};
352
353class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
354 public:
Steve Antonafd8e8c2017-12-19 16:35:35 -0800355 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800356 virtual VideoContentDescription* as_video() { return this; }
357 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100358
359 private:
360 virtual VideoContentDescription* CloneInternal() const {
361 return new VideoContentDescription(*this);
362 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800363};
364
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200365class RtpDataContentDescription
366 : public MediaContentDescriptionImpl<RtpDataCodec> {
367 public:
368 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200369 MediaType type() const override { return MEDIA_TYPE_DATA; }
370 RtpDataContentDescription* as_rtp_data() override { return this; }
371 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100372
373 private:
374 RtpDataContentDescription* CloneInternal() const override {
375 return new RtpDataContentDescription(*this);
376 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200377};
378
379class SctpDataContentDescription : public MediaContentDescription {
380 public:
381 SctpDataContentDescription() {}
382 SctpDataContentDescription(const SctpDataContentDescription& o)
383 : MediaContentDescription(o),
384 use_sctpmap_(o.use_sctpmap_),
385 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200386 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200387 MediaType type() const override { return MEDIA_TYPE_DATA; }
388 SctpDataContentDescription* as_sctp() override { return this; }
389 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200390
391 bool has_codecs() const override { return false; }
392 void set_protocol(const std::string& protocol) override {
393 RTC_DCHECK(IsSctpProtocol(protocol));
394 protocol_ = protocol;
395 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800396
397 bool use_sctpmap() const { return use_sctpmap_; }
398 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200399 int port() const { return port_; }
400 void set_port(int port) { port_ = port; }
401 int max_message_size() const { return max_message_size_; }
402 void set_max_message_size(int max_message_size) {
403 max_message_size_ = max_message_size;
404 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800405
406 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100407 SctpDataContentDescription* CloneInternal() const override {
408 return new SctpDataContentDescription(*this);
409 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200410 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
411 // Defaults should be constants imported from SCTP. Quick hack.
412 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200413 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
414 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800415};
416
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200417class UnsupportedContentDescription : public MediaContentDescription {
418 public:
419 explicit UnsupportedContentDescription(const std::string& media_type)
420 : media_type_(media_type) {}
421 MediaType type() const override { return MEDIA_TYPE_UNSUPPORTED; }
422
423 UnsupportedContentDescription* as_unsupported() override { return this; }
424 const UnsupportedContentDescription* as_unsupported() const override {
425 return this;
426 }
427
428 bool has_codecs() const override { return false; }
429 const std::string& media_type() const { return media_type_; }
430
431 private:
432 UnsupportedContentDescription* CloneInternal() const override {
433 return new UnsupportedContentDescription(*this);
434 }
435
436 std::string media_type_;
437};
438
Steve Anton5adfafd2017-12-20 16:34:00 -0800439// Protocol used for encoding media. This is the "top level" protocol that may
440// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
441enum class MediaProtocolType {
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200442 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
443 // https://tools.ietf.org/html/rfc3550
444 kSctp, // Section will use the SCTP protocol (e.g., for a data channel).
445 // https://tools.ietf.org/html/rfc4960
446 kOther // Section will use another top protocol which is not
447 // explicitly supported.
Steve Anton5adfafd2017-12-20 16:34:00 -0800448};
449
Steve Anton5adfafd2017-12-20 16:34:00 -0800450// Represents a session description section. Most information about the section
451// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200452// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200453class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200454 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800455 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200456 ~ContentInfo();
457 // Copy
458 ContentInfo(const ContentInfo& o);
459 ContentInfo& operator=(const ContentInfo& o);
460 ContentInfo(ContentInfo&& o) = default;
461 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800462
463 // Alias for |name|.
464 std::string mid() const { return name; }
465 void set_mid(const std::string& mid) { this->name = mid; }
466
467 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200468 MediaContentDescription* media_description();
469 const MediaContentDescription* media_description() const;
470
471 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
472 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800473 }
474
Steve Anton81712112018-01-05 11:27:54 -0800475 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800476 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800477 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800478 bool rejected = false;
479 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200480
481 private:
482 friend class SessionDescription;
483 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800484};
485
486typedef std::vector<std::string> ContentNames;
487
488// This class provides a mechanism to aggregate different media contents into a
489// group. This group can also be shared with the peers in a pre-defined format.
490// GroupInfo should be populated only with the |content_name| of the
491// MediaDescription.
492class ContentGroup {
493 public:
494 explicit ContentGroup(const std::string& semantics);
495 ContentGroup(const ContentGroup&);
496 ContentGroup(ContentGroup&&);
497 ContentGroup& operator=(const ContentGroup&);
498 ContentGroup& operator=(ContentGroup&&);
499 ~ContentGroup();
500
501 const std::string& semantics() const { return semantics_; }
502 const ContentNames& content_names() const { return content_names_; }
503
504 const std::string* FirstContentName() const;
505 bool HasContentName(const std::string& content_name) const;
506 void AddContentName(const std::string& content_name);
507 bool RemoveContentName(const std::string& content_name);
508
509 private:
510 std::string semantics_;
511 ContentNames content_names_;
512};
513
514typedef std::vector<ContentInfo> ContentInfos;
515typedef std::vector<ContentGroup> ContentGroups;
516
517const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
518 const std::string& name);
519const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
520 const std::string& type);
521
Steve Antone831b8c2018-02-01 12:22:16 -0800522// Determines how the MSID will be signaled in the SDP. These can be used as
523// flags to indicate both or none.
524enum MsidSignaling {
525 // Signal MSID with one a=msid line in the media section.
526 kMsidSignalingMediaSection = 0x1,
527 // Signal MSID with a=ssrc: msid lines in the media section.
528 kMsidSignalingSsrcAttribute = 0x2
529};
530
Steve Anton4ab68ee2017-12-19 14:26:11 -0800531// Describes a collection of contents, each with its own name and
532// type. Analogous to a <jingle> or <session> stanza. Assumes that
533// contents are unique be name, but doesn't enforce that.
534class SessionDescription {
535 public:
536 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800537 ~SessionDescription();
538
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200539 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800540
541 // Content accessors.
542 const ContentInfos& contents() const { return contents_; }
543 ContentInfos& contents() { return contents_; }
544 const ContentInfo* GetContentByName(const std::string& name) const;
545 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800546 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800547 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800548 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800549 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800550 const ContentInfo* FirstContent() const;
551
552 // Content mutators.
553 // Adds a content to this description. Takes ownership of ContentDescription*.
554 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800555 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200556 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800557 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800558 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800559 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200560 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800561 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800562 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800563 bool rejected,
564 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200565 std::unique_ptr<MediaContentDescription> description);
566 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200567
Steve Anton4ab68ee2017-12-19 14:26:11 -0800568 bool RemoveContentByName(const std::string& name);
569
570 // Transport accessors.
571 const TransportInfos& transport_infos() const { return transport_infos_; }
572 TransportInfos& transport_infos() { return transport_infos_; }
573 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
574 TransportInfo* GetTransportInfoByName(const std::string& name);
575 const TransportDescription* GetTransportDescriptionByName(
576 const std::string& name) const {
577 const TransportInfo* tinfo = GetTransportInfoByName(name);
578 return tinfo ? &tinfo->description : NULL;
579 }
580
581 // Transport mutators.
582 void set_transport_infos(const TransportInfos& transport_infos) {
583 transport_infos_ = transport_infos;
584 }
585 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800586 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800587 bool RemoveTransportInfoByName(const std::string& name);
588
589 // Group accessors.
590 const ContentGroups& groups() const { return content_groups_; }
591 const ContentGroup* GetGroupByName(const std::string& name) const;
592 bool HasGroup(const std::string& name) const;
593
594 // Group mutators.
595 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
596 // Remove the first group with the same semantics specified by |name|.
597 void RemoveGroupByName(const std::string& name);
598
599 // Global attributes.
600 void set_msid_supported(bool supported) { msid_supported_ = supported; }
601 bool msid_supported() const { return msid_supported_; }
602
Steve Antone831b8c2018-02-01 12:22:16 -0800603 // Determines how the MSIDs were/will be signaled. Flag value composed of
604 // MsidSignaling bits (see enum above).
605 void set_msid_signaling(int msid_signaling) {
606 msid_signaling_ = msid_signaling;
607 }
608 int msid_signaling() const { return msid_signaling_; }
609
Johannes Kron0854eb62018-10-10 22:33:20 +0200610 // Determines if it's allowed to mix one- and two-byte rtp header extensions
611 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200612 void set_extmap_allow_mixed(bool supported) {
613 extmap_allow_mixed_ = supported;
614 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200615 supported ? MediaContentDescription::kSession
616 : MediaContentDescription::kNo;
617 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200618 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200619 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
620 MediaContentDescription::kMedia) {
621 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200622 media_level_setting);
623 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200624 }
625 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200626 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200627
Steve Anton4ab68ee2017-12-19 14:26:11 -0800628 private:
629 SessionDescription(const SessionDescription&);
630
631 ContentInfos contents_;
632 TransportInfos transport_infos_;
633 ContentGroups content_groups_;
634 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800635 // Default to what Plan B would do.
636 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
637 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Emil Lundmark801c9992021-01-19 13:06:32 +0100638 bool extmap_allow_mixed_ = true;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800639};
640
Steve Antonb1c1de12017-12-21 15:14:30 -0800641// Indicates whether a session description was sent by the local client or
642// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800643enum ContentSource { CS_LOCAL, CS_REMOTE };
644
645} // namespace cricket
646
Steve Anton10542f22019-01-11 09:11:00 -0800647#endif // PC_SESSION_DESCRIPTION_H_