blob: 52a3a1fe0422b93198437bfc6669c56006afed46 [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
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020018#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080019#include <string>
Harald Alvestrand1716d392019-06-03 20:35:45 +020020#include <utility>
Steve Anton4ab68ee2017-12-19 14:26:11 -080021#include <vector>
22
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020023#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto_params.h"
25#include "api/media_types.h"
26#include "api/rtp_parameters.h"
27#include "api/rtp_transceiver_interface.h"
28#include "media/base/media_channel.h"
Taylor Brandstetteree8c2462020-07-27 15:52:02 -070029#include "media/base/media_constants.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "media/base/stream_params.h"
31#include "p2p/base/transport_description.h"
32#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020033#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020035#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "rtc_base/socket_address.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020037#include "rtc_base/system/rtc_export.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080038
39namespace cricket {
40
Steve Antonafd8e8c2017-12-19 16:35:35 -080041typedef std::vector<AudioCodec> AudioCodecs;
42typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020043typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080044typedef std::vector<CryptoParams> CryptoParamsVec;
45typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
46
47// RTC4585 RTP/AVPF
48extern const char kMediaProtocolAvpf[];
49// RFC5124 RTP/SAVPF
50extern const char kMediaProtocolSavpf[];
51
52extern const char kMediaProtocolDtlsSavpf[];
53
Steve Antonafd8e8c2017-12-19 16:35:35 -080054// Options to control how session descriptions are generated.
55const int kAutoBandwidth = -1;
56
Steve Anton5adfafd2017-12-20 16:34:00 -080057class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070058class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020059class RtpDataContentDescription;
60class SctpDataContentDescription;
Philipp Hancke4e8c1152020-10-13 12:43:15 +020061class UnsupportedContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080062
Steve Anton5adfafd2017-12-20 16:34:00 -080063// Describes a session description media section. There are subclasses for each
64// media type (audio, video, data) that will have additional information.
65class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080066 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080067 MediaContentDescription() = default;
68 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080069
70 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080071
72 // Try to cast this media description to an AudioContentDescription. Returns
73 // nullptr if the cast fails.
74 virtual AudioContentDescription* as_audio() { return nullptr; }
75 virtual const AudioContentDescription* as_audio() const { return nullptr; }
76
77 // Try to cast this media description to a VideoContentDescription. Returns
78 // nullptr if the cast fails.
79 virtual VideoContentDescription* as_video() { return nullptr; }
80 virtual const VideoContentDescription* as_video() const { return nullptr; }
81
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020082 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
83 virtual const RtpDataContentDescription* as_rtp_data() const {
84 return nullptr;
85 }
86
87 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
88 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
89
Philipp Hancke4e8c1152020-10-13 12:43:15 +020090 virtual UnsupportedContentDescription* as_unsupported() { return nullptr; }
91 virtual const UnsupportedContentDescription* as_unsupported() const {
92 return nullptr;
93 }
94
Steve Antonafd8e8c2017-12-19 16:35:35 -080095 virtual bool has_codecs() const = 0;
96
Harald Alvestrand0fb07f82020-02-27 20:21:37 +010097 // Copy operator that returns an unique_ptr.
98 // Not a virtual function.
99 // If a type-specific variant of Clone() is desired, override it, or
100 // simply use std::make_unique<typename>(*this) instead of Clone().
101 std::unique_ptr<MediaContentDescription> Clone() const {
102 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 20:35:45 +0200103 }
Steve Anton5adfafd2017-12-20 16:34:00 -0800104
Steve Antonafd8e8c2017-12-19 16:35:35 -0800105 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
106 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200107 virtual std::string protocol() const { return protocol_; }
108 virtual void set_protocol(const std::string& protocol) {
109 protocol_ = protocol;
110 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800111
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200112 virtual webrtc::RtpTransceiverDirection direction() const {
113 return direction_;
114 }
115 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800116 direction_ = direction;
117 }
118
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200119 virtual bool rtcp_mux() const { return rtcp_mux_; }
120 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800121
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200122 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
123 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800124 rtcp_reduced_size_ = reduced_size;
125 }
126
Sebastian Jansson97321b62019-07-24 14:01:18 +0200127 // Indicates support for the remote network estimate packet type. This
128 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200129 virtual bool remote_estimate() const { return remote_estimate_; }
130 virtual void set_remote_estimate(bool remote_estimate) {
131 remote_estimate_ = remote_estimate;
132 }
133
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200134 virtual int bandwidth() const { return bandwidth_; }
135 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700136 virtual std::string bandwidth_type() const { return bandwidth_type_; }
137 virtual void set_bandwidth_type(std::string bandwidth_type) {
138 bandwidth_type_ = bandwidth_type;
139 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800140
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200141 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
142 virtual void AddCrypto(const CryptoParams& params) {
143 cryptos_.push_back(params);
144 }
145 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800146 cryptos_ = cryptos;
147 }
148
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200149 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800150 return rtp_header_extensions_;
151 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200152 virtual void set_rtp_header_extensions(
153 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800154 rtp_header_extensions_ = extensions;
155 rtp_header_extensions_set_ = true;
156 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200157 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800158 rtp_header_extensions_.push_back(ext);
159 rtp_header_extensions_set_ = true;
160 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200161 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800162 rtp_header_extensions_.clear();
163 rtp_header_extensions_set_ = true;
164 }
165 // We can't always tell if an empty list of header extensions is
166 // because the other side doesn't support them, or just isn't hooked up to
167 // signal them. For now we assume an empty list means no signaling, but
168 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
169 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200170 virtual bool rtp_header_extensions_set() const {
171 return rtp_header_extensions_set_;
172 }
173 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800174 // TODO(pthatcher): Remove this by giving mediamessage.cc access
175 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200176 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
177 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800178 send_streams_.push_back(stream);
179 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800180 // Legacy streams have an ssrc, but nothing else.
181 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200182 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800183 }
184 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
185 StreamParams sp = StreamParams::CreateLegacy(ssrc);
186 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200187 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800188 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800189
Steve Antonafd8e8c2017-12-19 16:35:35 -0800190 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200191 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800192 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
193 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800194 if (it->cname.empty())
195 it->cname = cname;
196 }
197 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200198 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800199 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800200 return 0;
201 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800202 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800203 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200204 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800205 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800206 return false;
207 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800208 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800209 }
210
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200211 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
212 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800213
214 // https://tools.ietf.org/html/rfc4566#section-5.7
215 // May be present at the media or session level of SDP. If present at both
216 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200217 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800218 connection_address_ = address;
219 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200220 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800221 return connection_address_;
222 }
223
Johannes Kron0854eb62018-10-10 22:33:20 +0200224 // Determines if it's allowed to mix one- and two-byte rtp header extensions
225 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200226 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200227 virtual void set_extmap_allow_mixed_enum(
228 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200229 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200230 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200231 // Do not downgrade from session level to media level.
232 return;
233 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200234 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200235 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200236 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200237 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200238 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200239 virtual bool extmap_allow_mixed() const {
240 return extmap_allow_mixed_enum_ != kNo;
241 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200242
Amit Hilbucha2012042018-12-03 11:35:05 -0800243 // Simulcast functionality.
244 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
245 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
246 virtual const SimulcastDescription& simulcast_description() const {
247 return simulcast_;
248 }
249 virtual void set_simulcast_description(
250 const SimulcastDescription& simulcast) {
251 simulcast_ = simulcast;
252 }
Florent Castellib60141b2019-07-03 12:47:54 +0200253 virtual const std::vector<RidDescription>& receive_rids() const {
254 return receive_rids_;
255 }
256 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
257 receive_rids_ = rids;
258 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800259
Steve Antonafd8e8c2017-12-19 16:35:35 -0800260 protected:
261 bool rtcp_mux_ = false;
262 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200263 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800264 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700265 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800266 std::string protocol_;
267 std::vector<CryptoParams> cryptos_;
268 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
269 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800270 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800271 bool conference_mode_ = false;
272 webrtc::RtpTransceiverDirection direction_ =
273 webrtc::RtpTransceiverDirection::kSendRecv;
274 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200275 // Mixed one- and two-byte header not included in offer on media level or
276 // session level, but we will respond that we support it. The plan is to add
277 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200278 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800279
280 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200281 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700282
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100283 private:
284 // Copy function that returns a raw pointer. Caller will assert ownership.
285 // Should only be called by the Clone() function. Must be implemented
286 // by each final subclass.
287 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800288};
289
290template <class C>
291class MediaContentDescriptionImpl : public MediaContentDescription {
292 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200293 void set_protocol(const std::string& protocol) override {
294 RTC_DCHECK(IsRtpProtocol(protocol));
295 protocol_ = protocol;
296 }
297
Steve Antonafd8e8c2017-12-19 16:35:35 -0800298 typedef C CodecType;
299
300 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200301 virtual const std::vector<C>& codecs() const { return codecs_; }
302 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
303 bool has_codecs() const override { return !codecs_.empty(); }
304 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800305 bool found = false;
306 for (typename std::vector<C>::iterator iter = codecs_.begin();
307 iter != codecs_.end(); ++iter) {
308 if (iter->id == id) {
309 found = true;
310 break;
311 }
312 }
313 return found;
314 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200315 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
316 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800317 for (typename std::vector<C>::iterator iter = codecs_.begin();
318 iter != codecs_.end(); ++iter) {
319 if (iter->id == codec.id) {
320 *iter = codec;
321 return;
322 }
323 }
324 AddCodec(codec);
325 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200326 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800327 typename std::vector<C>::const_iterator codec;
328 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
329 AddCodec(*codec);
330 }
331 }
332
333 private:
334 std::vector<C> codecs_;
335};
336
337class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
338 public:
339 AudioContentDescription() {}
340
Steve Antonafd8e8c2017-12-19 16:35:35 -0800341 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800342 virtual AudioContentDescription* as_audio() { return this; }
343 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100344
345 private:
346 virtual AudioContentDescription* CloneInternal() const {
347 return new AudioContentDescription(*this);
348 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800349};
350
351class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
352 public:
Steve Antonafd8e8c2017-12-19 16:35:35 -0800353 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800354 virtual VideoContentDescription* as_video() { return this; }
355 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100356
357 private:
358 virtual VideoContentDescription* CloneInternal() const {
359 return new VideoContentDescription(*this);
360 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800361};
362
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200363class RtpDataContentDescription
364 : public MediaContentDescriptionImpl<RtpDataCodec> {
365 public:
366 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200367 MediaType type() const override { return MEDIA_TYPE_DATA; }
368 RtpDataContentDescription* as_rtp_data() override { return this; }
369 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100370
371 private:
372 RtpDataContentDescription* CloneInternal() const override {
373 return new RtpDataContentDescription(*this);
374 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200375};
376
377class SctpDataContentDescription : public MediaContentDescription {
378 public:
379 SctpDataContentDescription() {}
380 SctpDataContentDescription(const SctpDataContentDescription& o)
381 : MediaContentDescription(o),
382 use_sctpmap_(o.use_sctpmap_),
383 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200384 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200385 MediaType type() const override { return MEDIA_TYPE_DATA; }
386 SctpDataContentDescription* as_sctp() override { return this; }
387 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200388
389 bool has_codecs() const override { return false; }
390 void set_protocol(const std::string& protocol) override {
391 RTC_DCHECK(IsSctpProtocol(protocol));
392 protocol_ = protocol;
393 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800394
395 bool use_sctpmap() const { return use_sctpmap_; }
396 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200397 int port() const { return port_; }
398 void set_port(int port) { port_ = port; }
399 int max_message_size() const { return max_message_size_; }
400 void set_max_message_size(int max_message_size) {
401 max_message_size_ = max_message_size;
402 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800403
404 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100405 SctpDataContentDescription* CloneInternal() const override {
406 return new SctpDataContentDescription(*this);
407 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200408 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
409 // Defaults should be constants imported from SCTP. Quick hack.
410 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200411 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
412 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800413};
414
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200415class UnsupportedContentDescription : public MediaContentDescription {
416 public:
417 explicit UnsupportedContentDescription(const std::string& media_type)
418 : media_type_(media_type) {}
419 MediaType type() const override { return MEDIA_TYPE_UNSUPPORTED; }
420
421 UnsupportedContentDescription* as_unsupported() override { return this; }
422 const UnsupportedContentDescription* as_unsupported() const override {
423 return this;
424 }
425
426 bool has_codecs() const override { return false; }
427 const std::string& media_type() const { return media_type_; }
428
429 private:
430 UnsupportedContentDescription* CloneInternal() const override {
431 return new UnsupportedContentDescription(*this);
432 }
433
434 std::string media_type_;
435};
436
Steve Anton5adfafd2017-12-20 16:34:00 -0800437// Protocol used for encoding media. This is the "top level" protocol that may
438// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
439enum class MediaProtocolType {
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200440 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
441 // https://tools.ietf.org/html/rfc3550
442 kSctp, // Section will use the SCTP protocol (e.g., for a data channel).
443 // https://tools.ietf.org/html/rfc4960
444 kOther // Section will use another top protocol which is not
445 // explicitly supported.
Steve Anton5adfafd2017-12-20 16:34:00 -0800446};
447
Steve Anton5adfafd2017-12-20 16:34:00 -0800448// Represents a session description section. Most information about the section
449// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200450// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200451class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200452 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800453 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200454 ~ContentInfo();
455 // Copy
456 ContentInfo(const ContentInfo& o);
457 ContentInfo& operator=(const ContentInfo& o);
458 ContentInfo(ContentInfo&& o) = default;
459 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800460
461 // Alias for |name|.
462 std::string mid() const { return name; }
463 void set_mid(const std::string& mid) { this->name = mid; }
464
465 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200466 MediaContentDescription* media_description();
467 const MediaContentDescription* media_description() const;
468
469 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
470 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800471 }
472
Steve Anton81712112018-01-05 11:27:54 -0800473 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800474 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800475 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800476 bool rejected = false;
477 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200478
479 private:
480 friend class SessionDescription;
481 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800482};
483
484typedef std::vector<std::string> ContentNames;
485
486// This class provides a mechanism to aggregate different media contents into a
487// group. This group can also be shared with the peers in a pre-defined format.
488// GroupInfo should be populated only with the |content_name| of the
489// MediaDescription.
490class ContentGroup {
491 public:
492 explicit ContentGroup(const std::string& semantics);
493 ContentGroup(const ContentGroup&);
494 ContentGroup(ContentGroup&&);
495 ContentGroup& operator=(const ContentGroup&);
496 ContentGroup& operator=(ContentGroup&&);
497 ~ContentGroup();
498
499 const std::string& semantics() const { return semantics_; }
500 const ContentNames& content_names() const { return content_names_; }
501
502 const std::string* FirstContentName() const;
503 bool HasContentName(const std::string& content_name) const;
504 void AddContentName(const std::string& content_name);
505 bool RemoveContentName(const std::string& content_name);
506
507 private:
508 std::string semantics_;
509 ContentNames content_names_;
510};
511
512typedef std::vector<ContentInfo> ContentInfos;
513typedef std::vector<ContentGroup> ContentGroups;
514
515const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
516 const std::string& name);
517const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
518 const std::string& type);
519
Steve Antone831b8c2018-02-01 12:22:16 -0800520// Determines how the MSID will be signaled in the SDP. These can be used as
521// flags to indicate both or none.
522enum MsidSignaling {
523 // Signal MSID with one a=msid line in the media section.
524 kMsidSignalingMediaSection = 0x1,
525 // Signal MSID with a=ssrc: msid lines in the media section.
526 kMsidSignalingSsrcAttribute = 0x2
527};
528
Steve Anton4ab68ee2017-12-19 14:26:11 -0800529// Describes a collection of contents, each with its own name and
530// type. Analogous to a <jingle> or <session> stanza. Assumes that
531// contents are unique be name, but doesn't enforce that.
532class SessionDescription {
533 public:
534 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800535 ~SessionDescription();
536
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200537 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800538
539 // Content accessors.
540 const ContentInfos& contents() const { return contents_; }
541 ContentInfos& contents() { return contents_; }
542 const ContentInfo* GetContentByName(const std::string& name) const;
543 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800544 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800545 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800546 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800547 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800548 const ContentInfo* FirstContent() const;
549
550 // Content mutators.
551 // Adds a content to this description. Takes ownership of ContentDescription*.
552 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800553 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200554 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800555 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800556 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800557 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200558 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800559 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800560 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800561 bool rejected,
562 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200563 std::unique_ptr<MediaContentDescription> description);
564 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200565
Steve Anton4ab68ee2017-12-19 14:26:11 -0800566 bool RemoveContentByName(const std::string& name);
567
568 // Transport accessors.
569 const TransportInfos& transport_infos() const { return transport_infos_; }
570 TransportInfos& transport_infos() { return transport_infos_; }
571 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
572 TransportInfo* GetTransportInfoByName(const std::string& name);
573 const TransportDescription* GetTransportDescriptionByName(
574 const std::string& name) const {
575 const TransportInfo* tinfo = GetTransportInfoByName(name);
576 return tinfo ? &tinfo->description : NULL;
577 }
578
579 // Transport mutators.
580 void set_transport_infos(const TransportInfos& transport_infos) {
581 transport_infos_ = transport_infos;
582 }
583 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800584 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800585 bool RemoveTransportInfoByName(const std::string& name);
586
587 // Group accessors.
588 const ContentGroups& groups() const { return content_groups_; }
589 const ContentGroup* GetGroupByName(const std::string& name) const;
590 bool HasGroup(const std::string& name) const;
591
592 // Group mutators.
593 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
594 // Remove the first group with the same semantics specified by |name|.
595 void RemoveGroupByName(const std::string& name);
596
597 // Global attributes.
598 void set_msid_supported(bool supported) { msid_supported_ = supported; }
599 bool msid_supported() const { return msid_supported_; }
600
Steve Antone831b8c2018-02-01 12:22:16 -0800601 // Determines how the MSIDs were/will be signaled. Flag value composed of
602 // MsidSignaling bits (see enum above).
603 void set_msid_signaling(int msid_signaling) {
604 msid_signaling_ = msid_signaling;
605 }
606 int msid_signaling() const { return msid_signaling_; }
607
Johannes Kron0854eb62018-10-10 22:33:20 +0200608 // Determines if it's allowed to mix one- and two-byte rtp header extensions
609 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200610 void set_extmap_allow_mixed(bool supported) {
611 extmap_allow_mixed_ = supported;
612 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200613 supported ? MediaContentDescription::kSession
614 : MediaContentDescription::kNo;
615 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200616 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200617 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
618 MediaContentDescription::kMedia) {
619 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200620 media_level_setting);
621 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200622 }
623 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200624 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200625
Steve Anton4ab68ee2017-12-19 14:26:11 -0800626 private:
627 SessionDescription(const SessionDescription&);
628
629 ContentInfos contents_;
630 TransportInfos transport_infos_;
631 ContentGroups content_groups_;
632 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800633 // Default to what Plan B would do.
634 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
635 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100636 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
637 // offer at session level. It's currently not included in offer by default
638 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
639 // correctly. If it's included in offer to us we will respond that we support
640 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200641 bool extmap_allow_mixed_ = false;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800642};
643
Steve Antonb1c1de12017-12-21 15:14:30 -0800644// Indicates whether a session description was sent by the local client or
645// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800646enum ContentSource { CS_LOCAL, CS_REMOTE };
647
648} // namespace cricket
649
Steve Anton10542f22019-01-11 09:11:00 -0800650#endif // PC_SESSION_DESCRIPTION_H_