blob: a68c312f4279f737cf03e9ff7811fae6e294c4b0 [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>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020018#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080019#include <string>
Harald Alvestrandc24a2182022-02-23 13:44:59 +000020#include <type_traits>
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"
Harald Alvestrand0d018412021-11-04 13:52:31 +000025#include "api/crypto_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#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;
Harald Alvestrand0d018412021-11-04 13:52:31 +000047typedef std::vector<CryptoParams> CryptoParamsVec;
Steve Antonafd8e8c2017-12-19 16:35:35 -080048typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
49
Steve Antonafd8e8c2017-12-19 16:35:35 -080050// Options to control how session descriptions are generated.
51const int kAutoBandwidth = -1;
52
Steve Anton5adfafd2017-12-20 16:34:00 -080053class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070054class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020055class SctpDataContentDescription;
Philipp Hancke4e8c1152020-10-13 12:43:15 +020056class UnsupportedContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080057
Steve Anton5adfafd2017-12-20 16:34:00 -080058// Describes a session description media section. There are subclasses for each
59// media type (audio, video, data) that will have additional information.
60class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080061 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080062 MediaContentDescription() = default;
63 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080064
65 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080066
67 // Try to cast this media description to an AudioContentDescription. Returns
68 // nullptr if the cast fails.
69 virtual AudioContentDescription* as_audio() { return nullptr; }
70 virtual const AudioContentDescription* as_audio() const { return nullptr; }
71
72 // Try to cast this media description to a VideoContentDescription. Returns
73 // nullptr if the cast fails.
74 virtual VideoContentDescription* as_video() { return nullptr; }
75 virtual const VideoContentDescription* as_video() const { return nullptr; }
76
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020077 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
78 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
79
Philipp Hancke4e8c1152020-10-13 12:43:15 +020080 virtual UnsupportedContentDescription* as_unsupported() { return nullptr; }
81 virtual const UnsupportedContentDescription* as_unsupported() const {
82 return nullptr;
83 }
84
Steve Antonafd8e8c2017-12-19 16:35:35 -080085 virtual bool has_codecs() const = 0;
86
Harald Alvestrand0fb07f82020-02-27 20:21:37 +010087 // Copy operator that returns an unique_ptr.
88 // Not a virtual function.
89 // If a type-specific variant of Clone() is desired, override it, or
90 // simply use std::make_unique<typename>(*this) instead of Clone().
91 std::unique_ptr<MediaContentDescription> Clone() const {
92 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 20:35:45 +020093 }
Steve Anton5adfafd2017-12-20 16:34:00 -080094
Artem Titov880fa812021-07-30 22:30:23 +020095 // `protocol` is the expected media transport protocol, such as RTP/AVPF,
Steve Antonafd8e8c2017-12-19 16:35:35 -080096 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020097 virtual std::string protocol() const { return protocol_; }
98 virtual void set_protocol(const std::string& protocol) {
99 protocol_ = protocol;
100 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800101
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200102 virtual webrtc::RtpTransceiverDirection direction() const {
103 return direction_;
104 }
105 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800106 direction_ = direction;
107 }
108
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200109 virtual bool rtcp_mux() const { return rtcp_mux_; }
110 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800111
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200112 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
113 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800114 rtcp_reduced_size_ = reduced_size;
115 }
116
Sebastian Jansson97321b62019-07-24 14:01:18 +0200117 // Indicates support for the remote network estimate packet type. This
118 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200119 virtual bool remote_estimate() const { return remote_estimate_; }
120 virtual void set_remote_estimate(bool remote_estimate) {
121 remote_estimate_ = remote_estimate;
122 }
123
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200124 virtual int bandwidth() const { return bandwidth_; }
125 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700126 virtual std::string bandwidth_type() const { return bandwidth_type_; }
127 virtual void set_bandwidth_type(std::string bandwidth_type) {
128 bandwidth_type_ = bandwidth_type;
129 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800130
Harald Alvestrand0d018412021-11-04 13:52:31 +0000131 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
132 virtual void AddCrypto(const CryptoParams& params) {
133 cryptos_.push_back(params);
134 }
135 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
136 cryptos_ = cryptos;
137 }
138
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200139 // List of RTP header extensions. URIs are **NOT** guaranteed to be unique
140 // as they can appear twice when both encrypted and non-encrypted extensions
141 // are present.
142 // Use RtpExtension::FindHeaderExtensionByUri for finding and
143 // RtpExtension::DeduplicateHeaderExtensions for filtering.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200144 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800145 return rtp_header_extensions_;
146 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200147 virtual void set_rtp_header_extensions(
148 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800149 rtp_header_extensions_ = extensions;
150 rtp_header_extensions_set_ = true;
151 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200152 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800153 rtp_header_extensions_.push_back(ext);
154 rtp_header_extensions_set_ = true;
155 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200156 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800157 rtp_header_extensions_.clear();
158 rtp_header_extensions_set_ = true;
159 }
160 // We can't always tell if an empty list of header extensions is
161 // because the other side doesn't support them, or just isn't hooked up to
162 // signal them. For now we assume an empty list means no signaling, but
163 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
164 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200165 virtual bool rtp_header_extensions_set() const {
166 return rtp_header_extensions_set_;
167 }
168 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800169 // TODO(pthatcher): Remove this by giving mediamessage.cc access
170 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200171 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
172 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800173 send_streams_.push_back(stream);
174 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 // Legacy streams have an ssrc, but nothing else.
176 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200177 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800178 }
179 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
180 StreamParams sp = StreamParams::CreateLegacy(ssrc);
181 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200182 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800183 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800184
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200186 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800187 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
188 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800189 if (it->cname.empty())
190 it->cname = cname;
191 }
192 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200193 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800195 return 0;
196 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800197 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800198 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200199 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800200 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800201 return false;
202 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800203 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800204 }
205
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200206 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
207 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800208
209 // https://tools.ietf.org/html/rfc4566#section-5.7
210 // May be present at the media or session level of SDP. If present at both
211 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200212 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800213 connection_address_ = address;
214 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200215 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800216 return connection_address_;
217 }
218
Johannes Kron0854eb62018-10-10 22:33:20 +0200219 // Determines if it's allowed to mix one- and two-byte rtp header extensions
220 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200221 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200222 virtual void set_extmap_allow_mixed_enum(
223 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200224 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200225 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200226 // Do not downgrade from session level to media level.
227 return;
228 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200229 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200230 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200231 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200232 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200233 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200234 virtual bool extmap_allow_mixed() const {
235 return extmap_allow_mixed_enum_ != kNo;
236 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200237
Amit Hilbucha2012042018-12-03 11:35:05 -0800238 // Simulcast functionality.
239 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
240 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
241 virtual const SimulcastDescription& simulcast_description() const {
242 return simulcast_;
243 }
244 virtual void set_simulcast_description(
245 const SimulcastDescription& simulcast) {
246 simulcast_ = simulcast;
247 }
Florent Castellib60141b2019-07-03 12:47:54 +0200248 virtual const std::vector<RidDescription>& receive_rids() const {
249 return receive_rids_;
250 }
251 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
252 receive_rids_ = rids;
253 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800254
Steve Antonafd8e8c2017-12-19 16:35:35 -0800255 protected:
256 bool rtcp_mux_ = false;
257 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200258 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800259 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 15:52:02 -0700260 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800261 std::string protocol_;
Harald Alvestrand0d018412021-11-04 13:52:31 +0000262 std::vector<CryptoParams> cryptos_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800263 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
264 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800265 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800266 bool conference_mode_ = false;
267 webrtc::RtpTransceiverDirection direction_ =
268 webrtc::RtpTransceiverDirection::kSendRecv;
269 rtc::SocketAddress connection_address_;
Emil Lundmark801c9992021-01-19 13:06:32 +0100270 ExtmapAllowMixed extmap_allow_mixed_enum_ = kMedia;
Amit Hilbucha2012042018-12-03 11:35:05 -0800271
272 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200273 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700274
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100275 private:
276 // Copy function that returns a raw pointer. Caller will assert ownership.
277 // Should only be called by the Clone() function. Must be implemented
278 // by each final subclass.
279 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800280};
281
282template <class C>
283class MediaContentDescriptionImpl : public MediaContentDescription {
284 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200285 void set_protocol(const std::string& protocol) override {
286 RTC_DCHECK(IsRtpProtocol(protocol));
287 protocol_ = protocol;
288 }
289
Steve Antonafd8e8c2017-12-19 16:35:35 -0800290 typedef C CodecType;
291
292 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200293 virtual const std::vector<C>& codecs() const { return codecs_; }
294 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
295 bool has_codecs() const override { return !codecs_.empty(); }
296 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800297 bool found = false;
298 for (typename std::vector<C>::iterator iter = codecs_.begin();
299 iter != codecs_.end(); ++iter) {
300 if (iter->id == id) {
301 found = true;
302 break;
303 }
304 }
305 return found;
306 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200307 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
308 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800309 for (typename std::vector<C>::iterator iter = codecs_.begin();
310 iter != codecs_.end(); ++iter) {
311 if (iter->id == codec.id) {
312 *iter = codec;
313 return;
314 }
315 }
316 AddCodec(codec);
317 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200318 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800319 typename std::vector<C>::const_iterator codec;
320 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
321 AddCodec(*codec);
322 }
323 }
324
325 private:
326 std::vector<C> codecs_;
327};
328
329class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
330 public:
331 AudioContentDescription() {}
332
Steve Antonafd8e8c2017-12-19 16:35:35 -0800333 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800334 virtual AudioContentDescription* as_audio() { return this; }
335 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100336
337 private:
338 virtual AudioContentDescription* CloneInternal() const {
339 return new AudioContentDescription(*this);
340 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800341};
342
343class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
344 public:
Steve Antonafd8e8c2017-12-19 16:35:35 -0800345 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800346 virtual VideoContentDescription* as_video() { return this; }
347 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100348
349 private:
350 virtual VideoContentDescription* CloneInternal() const {
351 return new VideoContentDescription(*this);
352 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800353};
354
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200355class SctpDataContentDescription : public MediaContentDescription {
356 public:
357 SctpDataContentDescription() {}
358 SctpDataContentDescription(const SctpDataContentDescription& o)
359 : MediaContentDescription(o),
360 use_sctpmap_(o.use_sctpmap_),
361 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200362 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200363 MediaType type() const override { return MEDIA_TYPE_DATA; }
364 SctpDataContentDescription* as_sctp() override { return this; }
365 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200366
367 bool has_codecs() const override { return false; }
368 void set_protocol(const std::string& protocol) override {
369 RTC_DCHECK(IsSctpProtocol(protocol));
370 protocol_ = protocol;
371 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800372
373 bool use_sctpmap() const { return use_sctpmap_; }
374 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200375 int port() const { return port_; }
376 void set_port(int port) { port_ = port; }
377 int max_message_size() const { return max_message_size_; }
378 void set_max_message_size(int max_message_size) {
379 max_message_size_ = max_message_size;
380 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800381
382 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100383 SctpDataContentDescription* CloneInternal() const override {
384 return new SctpDataContentDescription(*this);
385 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200386 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
387 // Defaults should be constants imported from SCTP. Quick hack.
388 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200389 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
390 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800391};
392
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200393class UnsupportedContentDescription : public MediaContentDescription {
394 public:
395 explicit UnsupportedContentDescription(const std::string& media_type)
396 : media_type_(media_type) {}
397 MediaType type() const override { return MEDIA_TYPE_UNSUPPORTED; }
398
399 UnsupportedContentDescription* as_unsupported() override { return this; }
400 const UnsupportedContentDescription* as_unsupported() const override {
401 return this;
402 }
403
404 bool has_codecs() const override { return false; }
405 const std::string& media_type() const { return media_type_; }
406
407 private:
408 UnsupportedContentDescription* CloneInternal() const override {
409 return new UnsupportedContentDescription(*this);
410 }
411
412 std::string media_type_;
413};
414
Steve Anton5adfafd2017-12-20 16:34:00 -0800415// Protocol used for encoding media. This is the "top level" protocol that may
416// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
417enum class MediaProtocolType {
Philipp Hancke4e8c1152020-10-13 12:43:15 +0200418 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
419 // https://tools.ietf.org/html/rfc3550
420 kSctp, // Section will use the SCTP protocol (e.g., for a data channel).
421 // https://tools.ietf.org/html/rfc4960
422 kOther // Section will use another top protocol which is not
423 // explicitly supported.
Steve Anton5adfafd2017-12-20 16:34:00 -0800424};
425
Steve Anton5adfafd2017-12-20 16:34:00 -0800426// Represents a session description section. Most information about the section
427// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200428// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200429class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200430 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800431 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200432 ~ContentInfo();
433 // Copy
434 ContentInfo(const ContentInfo& o);
435 ContentInfo& operator=(const ContentInfo& o);
436 ContentInfo(ContentInfo&& o) = default;
437 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800438
Artem Titov880fa812021-07-30 22:30:23 +0200439 // Alias for `name`.
Steve Anton5adfafd2017-12-20 16:34:00 -0800440 std::string mid() const { return name; }
441 void set_mid(const std::string& mid) { this->name = mid; }
442
Artem Titov880fa812021-07-30 22:30:23 +0200443 // Alias for `description`.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200444 MediaContentDescription* media_description();
445 const MediaContentDescription* media_description() const;
446
447 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
448 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800449 }
450
Steve Anton81712112018-01-05 11:27:54 -0800451 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800452 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800453 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800454 bool rejected = false;
455 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200456
457 private:
458 friend class SessionDescription;
459 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800460};
461
462typedef std::vector<std::string> ContentNames;
463
464// This class provides a mechanism to aggregate different media contents into a
465// group. This group can also be shared with the peers in a pre-defined format.
Artem Titov880fa812021-07-30 22:30:23 +0200466// GroupInfo should be populated only with the `content_name` of the
Steve Anton4ab68ee2017-12-19 14:26:11 -0800467// MediaDescription.
468class ContentGroup {
469 public:
470 explicit ContentGroup(const std::string& semantics);
471 ContentGroup(const ContentGroup&);
472 ContentGroup(ContentGroup&&);
473 ContentGroup& operator=(const ContentGroup&);
474 ContentGroup& operator=(ContentGroup&&);
475 ~ContentGroup();
476
477 const std::string& semantics() const { return semantics_; }
478 const ContentNames& content_names() const { return content_names_; }
479
480 const std::string* FirstContentName() const;
481 bool HasContentName(const std::string& content_name) const;
482 void AddContentName(const std::string& content_name);
483 bool RemoveContentName(const std::string& content_name);
Harald Alvestrand7a2db8a2021-06-14 15:41:30 +0000484 // for debugging
485 std::string ToString() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800486
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); }
Artem Titov880fa812021-07-30 22:30:23 +0200576 // Remove the first group with the same semantics specified by `name`.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800577 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_