blob: fed083987d104722fd81e28d546883e4531f8f53 [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
Artem Titov880fa812021-07-30 22:30:23 +0200102 // `protocol` is the expected media transport protocol, such as RTP/AVPF,
Steve Antonafd8e8c2017-12-19 16:35:35 -0800103 // 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
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200146 // List of RTP header extensions. URIs are **NOT** guaranteed to be unique
147 // as they can appear twice when both encrypted and non-encrypted extensions
148 // are present.
149 // Use RtpExtension::FindHeaderExtensionByUri for finding and
150 // RtpExtension::DeduplicateHeaderExtensions for filtering.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200151 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800152 return rtp_header_extensions_;
153 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200154 virtual void set_rtp_header_extensions(
155 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800156 rtp_header_extensions_ = extensions;
157 rtp_header_extensions_set_ = true;
158 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200159 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800160 rtp_header_extensions_.push_back(ext);
161 rtp_header_extensions_set_ = true;
162 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200163 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800164 rtp_header_extensions_.clear();
165 rtp_header_extensions_set_ = true;
166 }
167 // We can't always tell if an empty list of header extensions is
168 // because the other side doesn't support them, or just isn't hooked up to
169 // signal them. For now we assume an empty list means no signaling, but
170 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
171 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200172 virtual bool rtp_header_extensions_set() const {
173 return rtp_header_extensions_set_;
174 }
175 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800176 // TODO(pthatcher): Remove this by giving mediamessage.cc access
177 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200178 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
179 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800180 send_streams_.push_back(stream);
181 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800182 // Legacy streams have an ssrc, but nothing else.
183 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200184 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 }
186 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
187 StreamParams sp = StreamParams::CreateLegacy(ssrc);
188 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200189 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800190 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800191
Steve Antonafd8e8c2017-12-19 16:35:35 -0800192 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200193 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
195 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800196 if (it->cname.empty())
197 it->cname = cname;
198 }
199 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200200 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800201 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800202 return 0;
203 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800204 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800205 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200206 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800207 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800208 return false;
209 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800210 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800211 }
212
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200213 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
214 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800215
216 // https://tools.ietf.org/html/rfc4566#section-5.7
217 // May be present at the media or session level of SDP. If present at both
218 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200219 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800220 connection_address_ = address;
221 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200222 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800223 return connection_address_;
224 }
225
Johannes Kron0854eb62018-10-10 22:33:20 +0200226 // Determines if it's allowed to mix one- and two-byte rtp header extensions
227 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200228 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200229 virtual void set_extmap_allow_mixed_enum(
230 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200231 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200232 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200233 // Do not downgrade from session level to media level.
234 return;
235 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200236 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200237 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200238 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200239 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200240 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200241 virtual bool extmap_allow_mixed() const {
242 return extmap_allow_mixed_enum_ != kNo;
243 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200244
Amit Hilbucha2012042018-12-03 11:35:05 -0800245 // Simulcast functionality.
246 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
247 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
248 virtual const SimulcastDescription& simulcast_description() const {
249 return simulcast_;
250 }
251 virtual void set_simulcast_description(
252 const SimulcastDescription& simulcast) {
253 simulcast_ = simulcast;
254 }
Florent Castellib60141b2019-07-03 12:47:54 +0200255 virtual const std::vector<RidDescription>& receive_rids() const {
256 return receive_rids_;
257 }
258 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
259 receive_rids_ = rids;
260 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800261
Steve Antonafd8e8c2017-12-19 16:35:35 -0800262 protected:
263 bool rtcp_mux_ = false;
264 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200265 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800266 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700267 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800268 std::string protocol_;
269 std::vector<CryptoParams> cryptos_;
270 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
271 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800272 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800273 bool conference_mode_ = false;
274 webrtc::RtpTransceiverDirection direction_ =
275 webrtc::RtpTransceiverDirection::kSendRecv;
276 rtc::SocketAddress connection_address_;
Emil Lundmark801c9992021-01-19 13:06:32 +0100277 ExtmapAllowMixed extmap_allow_mixed_enum_ = kMedia;
Amit Hilbucha2012042018-12-03 11:35:05 -0800278
279 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200280 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700281
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100282 private:
283 // Copy function that returns a raw pointer. Caller will assert ownership.
284 // Should only be called by the Clone() function. Must be implemented
285 // by each final subclass.
286 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800287};
288
289template <class C>
290class MediaContentDescriptionImpl : public MediaContentDescription {
291 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200292 void set_protocol(const std::string& protocol) override {
293 RTC_DCHECK(IsRtpProtocol(protocol));
294 protocol_ = protocol;
295 }
296
Steve Antonafd8e8c2017-12-19 16:35:35 -0800297 typedef C CodecType;
298
299 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200300 virtual const std::vector<C>& codecs() const { return codecs_; }
301 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
302 bool has_codecs() const override { return !codecs_.empty(); }
303 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800304 bool found = false;
305 for (typename std::vector<C>::iterator iter = codecs_.begin();
306 iter != codecs_.end(); ++iter) {
307 if (iter->id == id) {
308 found = true;
309 break;
310 }
311 }
312 return found;
313 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200314 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
315 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800316 for (typename std::vector<C>::iterator iter = codecs_.begin();
317 iter != codecs_.end(); ++iter) {
318 if (iter->id == codec.id) {
319 *iter = codec;
320 return;
321 }
322 }
323 AddCodec(codec);
324 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200325 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800326 typename std::vector<C>::const_iterator codec;
327 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
328 AddCodec(*codec);
329 }
330 }
331
332 private:
333 std::vector<C> codecs_;
334};
335
336class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
337 public:
338 AudioContentDescription() {}
339
Steve Antonafd8e8c2017-12-19 16:35:35 -0800340 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800341 virtual AudioContentDescription* as_audio() { return this; }
342 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100343
344 private:
345 virtual AudioContentDescription* CloneInternal() const {
346 return new AudioContentDescription(*this);
347 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800348};
349
350class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
351 public:
Steve Antonafd8e8c2017-12-19 16:35:35 -0800352 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800353 virtual VideoContentDescription* as_video() { return this; }
354 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100355
356 private:
357 virtual VideoContentDescription* CloneInternal() const {
358 return new VideoContentDescription(*this);
359 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800360};
361
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200362class SctpDataContentDescription : public MediaContentDescription {
363 public:
364 SctpDataContentDescription() {}
365 SctpDataContentDescription(const SctpDataContentDescription& o)
366 : MediaContentDescription(o),
367 use_sctpmap_(o.use_sctpmap_),
368 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200369 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200370 MediaType type() const override { return MEDIA_TYPE_DATA; }
371 SctpDataContentDescription* as_sctp() override { return this; }
372 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200373
374 bool has_codecs() const override { return false; }
375 void set_protocol(const std::string& protocol) override {
376 RTC_DCHECK(IsSctpProtocol(protocol));
377 protocol_ = protocol;
378 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800379
380 bool use_sctpmap() const { return use_sctpmap_; }
381 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200382 int port() const { return port_; }
383 void set_port(int port) { port_ = port; }
384 int max_message_size() const { return max_message_size_; }
385 void set_max_message_size(int max_message_size) {
386 max_message_size_ = max_message_size;
387 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800388
389 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100390 SctpDataContentDescription* CloneInternal() const override {
391 return new SctpDataContentDescription(*this);
392 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200393 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
394 // Defaults should be constants imported from SCTP. Quick hack.
395 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200396 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
397 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800398};
399
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200400class UnsupportedContentDescription : public MediaContentDescription {
401 public:
402 explicit UnsupportedContentDescription(const std::string& media_type)
403 : media_type_(media_type) {}
404 MediaType type() const override { return MEDIA_TYPE_UNSUPPORTED; }
405
406 UnsupportedContentDescription* as_unsupported() override { return this; }
407 const UnsupportedContentDescription* as_unsupported() const override {
408 return this;
409 }
410
411 bool has_codecs() const override { return false; }
412 const std::string& media_type() const { return media_type_; }
413
414 private:
415 UnsupportedContentDescription* CloneInternal() const override {
416 return new UnsupportedContentDescription(*this);
417 }
418
419 std::string media_type_;
420};
421
Steve Anton5adfafd2017-12-20 16:34:00 -0800422// Protocol used for encoding media. This is the "top level" protocol that may
423// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
424enum class MediaProtocolType {
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200425 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
426 // https://tools.ietf.org/html/rfc3550
427 kSctp, // Section will use the SCTP protocol (e.g., for a data channel).
428 // https://tools.ietf.org/html/rfc4960
429 kOther // Section will use another top protocol which is not
430 // explicitly supported.
Steve Anton5adfafd2017-12-20 16:34:00 -0800431};
432
Steve Anton5adfafd2017-12-20 16:34:00 -0800433// Represents a session description section. Most information about the section
434// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200435// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200436class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200437 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800438 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200439 ~ContentInfo();
440 // Copy
441 ContentInfo(const ContentInfo& o);
442 ContentInfo& operator=(const ContentInfo& o);
443 ContentInfo(ContentInfo&& o) = default;
444 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800445
Artem Titov880fa812021-07-30 22:30:23 +0200446 // Alias for `name`.
Steve Anton5adfafd2017-12-20 16:34:00 -0800447 std::string mid() const { return name; }
448 void set_mid(const std::string& mid) { this->name = mid; }
449
Artem Titov880fa812021-07-30 22:30:23 +0200450 // Alias for `description`.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200451 MediaContentDescription* media_description();
452 const MediaContentDescription* media_description() const;
453
454 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
455 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800456 }
457
Steve Anton81712112018-01-05 11:27:54 -0800458 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800459 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800460 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800461 bool rejected = false;
462 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200463
464 private:
465 friend class SessionDescription;
466 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800467};
468
469typedef std::vector<std::string> ContentNames;
470
471// This class provides a mechanism to aggregate different media contents into a
472// group. This group can also be shared with the peers in a pre-defined format.
Artem Titov880fa812021-07-30 22:30:23 +0200473// GroupInfo should be populated only with the `content_name` of the
Steve Anton4ab68ee2017-12-19 14:26:11 -0800474// MediaDescription.
475class ContentGroup {
476 public:
477 explicit ContentGroup(const std::string& semantics);
478 ContentGroup(const ContentGroup&);
479 ContentGroup(ContentGroup&&);
480 ContentGroup& operator=(const ContentGroup&);
481 ContentGroup& operator=(ContentGroup&&);
482 ~ContentGroup();
483
484 const std::string& semantics() const { return semantics_; }
485 const ContentNames& content_names() const { return content_names_; }
486
487 const std::string* FirstContentName() const;
488 bool HasContentName(const std::string& content_name) const;
489 void AddContentName(const std::string& content_name);
490 bool RemoveContentName(const std::string& content_name);
Harald Alvestrand7a2db8a2021-06-14 15:41:30 +0000491 // for debugging
492 std::string ToString() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800493
494 private:
495 std::string semantics_;
496 ContentNames content_names_;
497};
498
499typedef std::vector<ContentInfo> ContentInfos;
500typedef std::vector<ContentGroup> ContentGroups;
501
502const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
503 const std::string& name);
504const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
505 const std::string& type);
506
Steve Antone831b8c2018-02-01 12:22:16 -0800507// Determines how the MSID will be signaled in the SDP. These can be used as
508// flags to indicate both or none.
509enum MsidSignaling {
510 // Signal MSID with one a=msid line in the media section.
511 kMsidSignalingMediaSection = 0x1,
512 // Signal MSID with a=ssrc: msid lines in the media section.
513 kMsidSignalingSsrcAttribute = 0x2
514};
515
Steve Anton4ab68ee2017-12-19 14:26:11 -0800516// Describes a collection of contents, each with its own name and
517// type. Analogous to a <jingle> or <session> stanza. Assumes that
518// contents are unique be name, but doesn't enforce that.
519class SessionDescription {
520 public:
521 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800522 ~SessionDescription();
523
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200524 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800525
526 // Content accessors.
527 const ContentInfos& contents() const { return contents_; }
528 ContentInfos& contents() { return contents_; }
529 const ContentInfo* GetContentByName(const std::string& name) const;
530 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800531 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800532 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800533 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800534 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800535 const ContentInfo* FirstContent() const;
536
537 // Content mutators.
538 // Adds a content to this description. Takes ownership of ContentDescription*.
539 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800540 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200541 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800542 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800543 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800544 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200545 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800546 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800547 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800548 bool rejected,
549 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200550 std::unique_ptr<MediaContentDescription> description);
551 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200552
Steve Anton4ab68ee2017-12-19 14:26:11 -0800553 bool RemoveContentByName(const std::string& name);
554
555 // Transport accessors.
556 const TransportInfos& transport_infos() const { return transport_infos_; }
557 TransportInfos& transport_infos() { return transport_infos_; }
558 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
559 TransportInfo* GetTransportInfoByName(const std::string& name);
560 const TransportDescription* GetTransportDescriptionByName(
561 const std::string& name) const {
562 const TransportInfo* tinfo = GetTransportInfoByName(name);
563 return tinfo ? &tinfo->description : NULL;
564 }
565
566 // Transport mutators.
567 void set_transport_infos(const TransportInfos& transport_infos) {
568 transport_infos_ = transport_infos;
569 }
570 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800571 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800572 bool RemoveTransportInfoByName(const std::string& name);
573
574 // Group accessors.
575 const ContentGroups& groups() const { return content_groups_; }
576 const ContentGroup* GetGroupByName(const std::string& name) const;
Henrik Boströmf8187e02021-04-26 21:04:26 +0200577 std::vector<const ContentGroup*> GetGroupsByName(
578 const std::string& name) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800579 bool HasGroup(const std::string& name) const;
580
581 // Group mutators.
582 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
Artem Titov880fa812021-07-30 22:30:23 +0200583 // Remove the first group with the same semantics specified by `name`.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800584 void RemoveGroupByName(const std::string& name);
585
586 // Global attributes.
587 void set_msid_supported(bool supported) { msid_supported_ = supported; }
588 bool msid_supported() const { return msid_supported_; }
589
Steve Antone831b8c2018-02-01 12:22:16 -0800590 // Determines how the MSIDs were/will be signaled. Flag value composed of
591 // MsidSignaling bits (see enum above).
592 void set_msid_signaling(int msid_signaling) {
593 msid_signaling_ = msid_signaling;
594 }
595 int msid_signaling() const { return msid_signaling_; }
596
Johannes Kron0854eb62018-10-10 22:33:20 +0200597 // Determines if it's allowed to mix one- and two-byte rtp header extensions
598 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200599 void set_extmap_allow_mixed(bool supported) {
600 extmap_allow_mixed_ = supported;
601 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200602 supported ? MediaContentDescription::kSession
603 : MediaContentDescription::kNo;
604 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200605 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200606 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
607 MediaContentDescription::kMedia) {
608 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200609 media_level_setting);
610 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200611 }
612 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200613 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200614
Steve Anton4ab68ee2017-12-19 14:26:11 -0800615 private:
616 SessionDescription(const SessionDescription&);
617
618 ContentInfos contents_;
619 TransportInfos transport_infos_;
620 ContentGroups content_groups_;
621 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800622 // Default to what Plan B would do.
623 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
624 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Emil Lundmark801c9992021-01-19 13:06:32 +0100625 bool extmap_allow_mixed_ = true;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800626};
627
Steve Antonb1c1de12017-12-21 15:14:30 -0800628// Indicates whether a session description was sent by the local client or
629// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800630enum ContentSource { CS_LOCAL, CS_REMOTE };
631
632} // namespace cricket
633
Steve Anton10542f22019-01-11 09:11:00 -0800634#endif // PC_SESSION_DESCRIPTION_H_