blob: 96aa9967528a7f478760267440fb5e15e3b23b78 [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"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "rtc_base/socket_address.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020041#include "rtc_base/system/rtc_export.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080042
43namespace cricket {
44
Steve Antonafd8e8c2017-12-19 16:35:35 -080045typedef std::vector<AudioCodec> AudioCodecs;
46typedef std::vector<VideoCodec> VideoCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080047typedef std::vector<CryptoParams> CryptoParamsVec;
48typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
49
50// RTC4585 RTP/AVPF
51extern const char kMediaProtocolAvpf[];
52// RFC5124 RTP/SAVPF
53extern const char kMediaProtocolSavpf[];
54
55extern const char kMediaProtocolDtlsSavpf[];
56
Steve Antonafd8e8c2017-12-19 16:35:35 -080057// Options to control how session descriptions are generated.
58const int kAutoBandwidth = -1;
59
Steve Anton5adfafd2017-12-20 16:34:00 -080060class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070061class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020062class SctpDataContentDescription;
Philipp Hancke4e8c1152020-10-13 12:43:15 +020063class UnsupportedContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080064
Steve Anton5adfafd2017-12-20 16:34:00 -080065// Describes a session description media section. There are subclasses for each
66// media type (audio, video, data) that will have additional information.
67class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080068 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080069 MediaContentDescription() = default;
70 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080071
72 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080073
74 // Try to cast this media description to an AudioContentDescription. Returns
75 // nullptr if the cast fails.
76 virtual AudioContentDescription* as_audio() { return nullptr; }
77 virtual const AudioContentDescription* as_audio() const { return nullptr; }
78
79 // Try to cast this media description to a VideoContentDescription. Returns
80 // nullptr if the cast fails.
81 virtual VideoContentDescription* as_video() { return nullptr; }
82 virtual const VideoContentDescription* as_video() const { return nullptr; }
83
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020084 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
85 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
86
Philipp Hancke4e8c1152020-10-13 12:43:15 +020087 virtual UnsupportedContentDescription* as_unsupported() { return nullptr; }
88 virtual const UnsupportedContentDescription* as_unsupported() const {
89 return nullptr;
90 }
91
Steve Antonafd8e8c2017-12-19 16:35:35 -080092 virtual bool has_codecs() const = 0;
93
Harald Alvestrand0fb07f82020-02-27 20:21:37 +010094 // Copy operator that returns an unique_ptr.
95 // Not a virtual function.
96 // If a type-specific variant of Clone() is desired, override it, or
97 // simply use std::make_unique<typename>(*this) instead of Clone().
98 std::unique_ptr<MediaContentDescription> Clone() const {
99 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 20:35:45 +0200100 }
Steve Anton5adfafd2017-12-20 16:34:00 -0800101
Steve Antonafd8e8c2017-12-19 16:35:35 -0800102 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
103 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200104 virtual std::string protocol() const { return protocol_; }
105 virtual void set_protocol(const std::string& protocol) {
106 protocol_ = protocol;
107 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800108
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200109 virtual webrtc::RtpTransceiverDirection direction() const {
110 return direction_;
111 }
112 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800113 direction_ = direction;
114 }
115
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200116 virtual bool rtcp_mux() const { return rtcp_mux_; }
117 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800118
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200119 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
120 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800121 rtcp_reduced_size_ = reduced_size;
122 }
123
Sebastian Jansson97321b62019-07-24 14:01:18 +0200124 // Indicates support for the remote network estimate packet type. This
125 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200126 virtual bool remote_estimate() const { return remote_estimate_; }
127 virtual void set_remote_estimate(bool remote_estimate) {
128 remote_estimate_ = remote_estimate;
129 }
130
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200131 virtual int bandwidth() const { return bandwidth_; }
132 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700133 virtual std::string bandwidth_type() const { return bandwidth_type_; }
134 virtual void set_bandwidth_type(std::string bandwidth_type) {
135 bandwidth_type_ = bandwidth_type;
136 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800137
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200138 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
139 virtual void AddCrypto(const CryptoParams& params) {
140 cryptos_.push_back(params);
141 }
142 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800143 cryptos_ = cryptos;
144 }
145
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800147 return rtp_header_extensions_;
148 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200149 virtual void set_rtp_header_extensions(
150 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800151 rtp_header_extensions_ = extensions;
152 rtp_header_extensions_set_ = true;
153 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200154 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800155 rtp_header_extensions_.push_back(ext);
156 rtp_header_extensions_set_ = true;
157 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200158 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800159 rtp_header_extensions_.clear();
160 rtp_header_extensions_set_ = true;
161 }
162 // We can't always tell if an empty list of header extensions is
163 // because the other side doesn't support them, or just isn't hooked up to
164 // signal them. For now we assume an empty list means no signaling, but
165 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
166 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200167 virtual bool rtp_header_extensions_set() const {
168 return rtp_header_extensions_set_;
169 }
170 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800171 // TODO(pthatcher): Remove this by giving mediamessage.cc access
172 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200173 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
174 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800175 send_streams_.push_back(stream);
176 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800177 // Legacy streams have an ssrc, but nothing else.
178 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200179 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800180 }
181 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
182 StreamParams sp = StreamParams::CreateLegacy(ssrc);
183 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200184 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800186
Steve Antonafd8e8c2017-12-19 16:35:35 -0800187 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200188 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800189 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
190 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800191 if (it->cname.empty())
192 it->cname = cname;
193 }
194 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200195 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800196 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800197 return 0;
198 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800199 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800200 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200201 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800202 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800203 return false;
204 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800205 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800206 }
207
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200208 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
209 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800210
211 // https://tools.ietf.org/html/rfc4566#section-5.7
212 // May be present at the media or session level of SDP. If present at both
213 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200214 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800215 connection_address_ = address;
216 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200217 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800218 return connection_address_;
219 }
220
Johannes Kron0854eb62018-10-10 22:33:20 +0200221 // Determines if it's allowed to mix one- and two-byte rtp header extensions
222 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200223 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200224 virtual void set_extmap_allow_mixed_enum(
225 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200226 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200227 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200228 // Do not downgrade from session level to media level.
229 return;
230 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200231 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200232 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200233 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200234 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200235 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200236 virtual bool extmap_allow_mixed() const {
237 return extmap_allow_mixed_enum_ != kNo;
238 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200239
Amit Hilbucha2012042018-12-03 11:35:05 -0800240 // Simulcast functionality.
241 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
242 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
243 virtual const SimulcastDescription& simulcast_description() const {
244 return simulcast_;
245 }
246 virtual void set_simulcast_description(
247 const SimulcastDescription& simulcast) {
248 simulcast_ = simulcast;
249 }
Florent Castellib60141b2019-07-03 12:47:54 +0200250 virtual const std::vector<RidDescription>& receive_rids() const {
251 return receive_rids_;
252 }
253 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
254 receive_rids_ = rids;
255 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800256
Steve Antonafd8e8c2017-12-19 16:35:35 -0800257 protected:
258 bool rtcp_mux_ = false;
259 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200260 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800261 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700262 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800263 std::string protocol_;
264 std::vector<CryptoParams> cryptos_;
265 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
266 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800267 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800268 bool conference_mode_ = false;
269 webrtc::RtpTransceiverDirection direction_ =
270 webrtc::RtpTransceiverDirection::kSendRecv;
271 rtc::SocketAddress connection_address_;
Emil Lundmark801c9992021-01-19 13:06:32 +0100272 ExtmapAllowMixed extmap_allow_mixed_enum_ = kMedia;
Amit Hilbucha2012042018-12-03 11:35:05 -0800273
274 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200275 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700276
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100277 private:
278 // Copy function that returns a raw pointer. Caller will assert ownership.
279 // Should only be called by the Clone() function. Must be implemented
280 // by each final subclass.
281 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800282};
283
284template <class C>
285class MediaContentDescriptionImpl : public MediaContentDescription {
286 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200287 void set_protocol(const std::string& protocol) override {
288 RTC_DCHECK(IsRtpProtocol(protocol));
289 protocol_ = protocol;
290 }
291
Steve Antonafd8e8c2017-12-19 16:35:35 -0800292 typedef C CodecType;
293
294 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200295 virtual const std::vector<C>& codecs() const { return codecs_; }
296 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
297 bool has_codecs() const override { return !codecs_.empty(); }
298 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800299 bool found = false;
300 for (typename std::vector<C>::iterator iter = codecs_.begin();
301 iter != codecs_.end(); ++iter) {
302 if (iter->id == id) {
303 found = true;
304 break;
305 }
306 }
307 return found;
308 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200309 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
310 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800311 for (typename std::vector<C>::iterator iter = codecs_.begin();
312 iter != codecs_.end(); ++iter) {
313 if (iter->id == codec.id) {
314 *iter = codec;
315 return;
316 }
317 }
318 AddCodec(codec);
319 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200320 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800321 typename std::vector<C>::const_iterator codec;
322 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
323 AddCodec(*codec);
324 }
325 }
326
327 private:
328 std::vector<C> codecs_;
329};
330
331class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
332 public:
333 AudioContentDescription() {}
334
Steve Antonafd8e8c2017-12-19 16:35:35 -0800335 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800336 virtual AudioContentDescription* as_audio() { return this; }
337 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100338
339 private:
340 virtual AudioContentDescription* CloneInternal() const {
341 return new AudioContentDescription(*this);
342 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800343};
344
345class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
346 public:
Steve Antonafd8e8c2017-12-19 16:35:35 -0800347 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800348 virtual VideoContentDescription* as_video() { return this; }
349 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100350
351 private:
352 virtual VideoContentDescription* CloneInternal() const {
353 return new VideoContentDescription(*this);
354 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800355};
356
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200357class SctpDataContentDescription : public MediaContentDescription {
358 public:
359 SctpDataContentDescription() {}
360 SctpDataContentDescription(const SctpDataContentDescription& o)
361 : MediaContentDescription(o),
362 use_sctpmap_(o.use_sctpmap_),
363 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200364 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200365 MediaType type() const override { return MEDIA_TYPE_DATA; }
366 SctpDataContentDescription* as_sctp() override { return this; }
367 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200368
369 bool has_codecs() const override { return false; }
370 void set_protocol(const std::string& protocol) override {
371 RTC_DCHECK(IsSctpProtocol(protocol));
372 protocol_ = protocol;
373 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800374
375 bool use_sctpmap() const { return use_sctpmap_; }
376 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200377 int port() const { return port_; }
378 void set_port(int port) { port_ = port; }
379 int max_message_size() const { return max_message_size_; }
380 void set_max_message_size(int max_message_size) {
381 max_message_size_ = max_message_size;
382 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800383
384 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100385 SctpDataContentDescription* CloneInternal() const override {
386 return new SctpDataContentDescription(*this);
387 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200388 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
389 // Defaults should be constants imported from SCTP. Quick hack.
390 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200391 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
392 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800393};
394
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200395class UnsupportedContentDescription : public MediaContentDescription {
396 public:
397 explicit UnsupportedContentDescription(const std::string& media_type)
398 : media_type_(media_type) {}
399 MediaType type() const override { return MEDIA_TYPE_UNSUPPORTED; }
400
401 UnsupportedContentDescription* as_unsupported() override { return this; }
402 const UnsupportedContentDescription* as_unsupported() const override {
403 return this;
404 }
405
406 bool has_codecs() const override { return false; }
407 const std::string& media_type() const { return media_type_; }
408
409 private:
410 UnsupportedContentDescription* CloneInternal() const override {
411 return new UnsupportedContentDescription(*this);
412 }
413
414 std::string media_type_;
415};
416
Steve Anton5adfafd2017-12-20 16:34:00 -0800417// Protocol used for encoding media. This is the "top level" protocol that may
418// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
419enum class MediaProtocolType {
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200420 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
421 // https://tools.ietf.org/html/rfc3550
422 kSctp, // Section will use the SCTP protocol (e.g., for a data channel).
423 // https://tools.ietf.org/html/rfc4960
424 kOther // Section will use another top protocol which is not
425 // explicitly supported.
Steve Anton5adfafd2017-12-20 16:34:00 -0800426};
427
Steve Anton5adfafd2017-12-20 16:34:00 -0800428// Represents a session description section. Most information about the section
429// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200430// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200431class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200432 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800433 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200434 ~ContentInfo();
435 // Copy
436 ContentInfo(const ContentInfo& o);
437 ContentInfo& operator=(const ContentInfo& o);
438 ContentInfo(ContentInfo&& o) = default;
439 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800440
441 // Alias for |name|.
442 std::string mid() const { return name; }
443 void set_mid(const std::string& mid) { this->name = mid; }
444
445 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200446 MediaContentDescription* media_description();
447 const MediaContentDescription* media_description() const;
448
449 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
450 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800451 }
452
Steve Anton81712112018-01-05 11:27:54 -0800453 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800454 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800455 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800456 bool rejected = false;
457 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200458
459 private:
460 friend class SessionDescription;
461 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800462};
463
464typedef std::vector<std::string> ContentNames;
465
466// This class provides a mechanism to aggregate different media contents into a
467// group. This group can also be shared with the peers in a pre-defined format.
468// GroupInfo should be populated only with the |content_name| of the
469// MediaDescription.
470class ContentGroup {
471 public:
472 explicit ContentGroup(const std::string& semantics);
473 ContentGroup(const ContentGroup&);
474 ContentGroup(ContentGroup&&);
475 ContentGroup& operator=(const ContentGroup&);
476 ContentGroup& operator=(ContentGroup&&);
477 ~ContentGroup();
478
479 const std::string& semantics() const { return semantics_; }
480 const ContentNames& content_names() const { return content_names_; }
481
482 const std::string* FirstContentName() const;
483 bool HasContentName(const std::string& content_name) const;
484 void AddContentName(const std::string& content_name);
485 bool RemoveContentName(const std::string& content_name);
486
487 private:
488 std::string semantics_;
489 ContentNames content_names_;
490};
491
492typedef std::vector<ContentInfo> ContentInfos;
493typedef std::vector<ContentGroup> ContentGroups;
494
495const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
496 const std::string& name);
497const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
498 const std::string& type);
499
Steve Antone831b8c2018-02-01 12:22:16 -0800500// Determines how the MSID will be signaled in the SDP. These can be used as
501// flags to indicate both or none.
502enum MsidSignaling {
503 // Signal MSID with one a=msid line in the media section.
504 kMsidSignalingMediaSection = 0x1,
505 // Signal MSID with a=ssrc: msid lines in the media section.
506 kMsidSignalingSsrcAttribute = 0x2
507};
508
Steve Anton4ab68ee2017-12-19 14:26:11 -0800509// Describes a collection of contents, each with its own name and
510// type. Analogous to a <jingle> or <session> stanza. Assumes that
511// contents are unique be name, but doesn't enforce that.
512class SessionDescription {
513 public:
514 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800515 ~SessionDescription();
516
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200517 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800518
519 // Content accessors.
520 const ContentInfos& contents() const { return contents_; }
521 ContentInfos& contents() { return contents_; }
522 const ContentInfo* GetContentByName(const std::string& name) const;
523 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800524 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800525 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800526 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800527 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800528 const ContentInfo* FirstContent() const;
529
530 // Content mutators.
531 // Adds a content to this description. Takes ownership of ContentDescription*.
532 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800533 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200534 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800535 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800536 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800537 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200538 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800539 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800540 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800541 bool rejected,
542 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200543 std::unique_ptr<MediaContentDescription> description);
544 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200545
Steve Anton4ab68ee2017-12-19 14:26:11 -0800546 bool RemoveContentByName(const std::string& name);
547
548 // Transport accessors.
549 const TransportInfos& transport_infos() const { return transport_infos_; }
550 TransportInfos& transport_infos() { return transport_infos_; }
551 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
552 TransportInfo* GetTransportInfoByName(const std::string& name);
553 const TransportDescription* GetTransportDescriptionByName(
554 const std::string& name) const {
555 const TransportInfo* tinfo = GetTransportInfoByName(name);
556 return tinfo ? &tinfo->description : NULL;
557 }
558
559 // Transport mutators.
560 void set_transport_infos(const TransportInfos& transport_infos) {
561 transport_infos_ = transport_infos;
562 }
563 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800564 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800565 bool RemoveTransportInfoByName(const std::string& name);
566
567 // Group accessors.
568 const ContentGroups& groups() const { return content_groups_; }
569 const ContentGroup* GetGroupByName(const std::string& name) const;
Henrik Boströmf8187e02021-04-26 21:04:26 +0200570 std::vector<const ContentGroup*> GetGroupsByName(
571 const std::string& name) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800572 bool HasGroup(const std::string& name) const;
573
574 // Group mutators.
575 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
576 // Remove the first group with the same semantics specified by |name|.
577 void RemoveGroupByName(const std::string& name);
578
579 // Global attributes.
580 void set_msid_supported(bool supported) { msid_supported_ = supported; }
581 bool msid_supported() const { return msid_supported_; }
582
Steve Antone831b8c2018-02-01 12:22:16 -0800583 // Determines how the MSIDs were/will be signaled. Flag value composed of
584 // MsidSignaling bits (see enum above).
585 void set_msid_signaling(int msid_signaling) {
586 msid_signaling_ = msid_signaling;
587 }
588 int msid_signaling() const { return msid_signaling_; }
589
Johannes Kron0854eb62018-10-10 22:33:20 +0200590 // Determines if it's allowed to mix one- and two-byte rtp header extensions
591 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200592 void set_extmap_allow_mixed(bool supported) {
593 extmap_allow_mixed_ = supported;
594 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200595 supported ? MediaContentDescription::kSession
596 : MediaContentDescription::kNo;
597 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200598 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200599 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
600 MediaContentDescription::kMedia) {
601 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200602 media_level_setting);
603 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200604 }
605 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200606 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200607
Steve Anton4ab68ee2017-12-19 14:26:11 -0800608 private:
609 SessionDescription(const SessionDescription&);
610
611 ContentInfos contents_;
612 TransportInfos transport_infos_;
613 ContentGroups content_groups_;
614 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800615 // Default to what Plan B would do.
616 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
617 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Emil Lundmark801c9992021-01-19 13:06:32 +0100618 bool extmap_allow_mixed_ = true;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800619};
620
Steve Antonb1c1de12017-12-21 15:14:30 -0800621// Indicates whether a session description was sent by the local client or
622// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800623enum ContentSource { CS_LOCAL, CS_REMOTE };
624
625} // namespace cricket
626
Steve Anton10542f22019-01-11 09:11:00 -0800627#endif // PC_SESSION_DESCRIPTION_H_