blob: 53c981a346e2335180b063ce890bfb5d5ab6506e [file] [log] [blame]
Steve Anton4ab68ee2017-12-19 22:26:111/*
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 17:11:0011#ifndef PC_SESSION_DESCRIPTION_H_
12#define PC_SESSION_DESCRIPTION_H_
Steve Anton4ab68ee2017-12-19 22:26:1113
Yves Gerey3e707812018-11-28 15:47:4914#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3316
Yves Gerey3e707812018-11-28 15:47:4917#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 05:01:2918#include <memory>
Steve Anton4ab68ee2017-12-19 22:26:1119#include <string>
Harald Alvestrand1716d392019-06-03 18:35:4520#include <utility>
Steve Anton4ab68ee2017-12-19 22:26:1121#include <vector>
22
Harald Alvestrand5fc28b12019-05-13 11:36:1623#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 17:11:0024#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 22:52:0229#include "media/base/media_constants.h"
Steve Anton10542f22019-01-11 17:11:0030#include "media/base/stream_params.h"
31#include "p2p/base/transport_description.h"
32#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 11:36:1633#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 17:11:0034#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 07:31:0435#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 17:11:0036#include "rtc_base/socket_address.h"
Mirko Bonadei35214fc2019-09-23 12:54:2837#include "rtc_base/system/rtc_export.h"
Steve Anton4ab68ee2017-12-19 22:26:1138
39namespace cricket {
40
Steve Antonafd8e8c2017-12-20 00:35:3541typedef std::vector<AudioCodec> AudioCodecs;
42typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 11:36:1643typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-20 00:35:3544typedef 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-20 00:35:3554// Options to control how session descriptions are generated.
55const int kAutoBandwidth = -1;
56
Steve Anton5adfafd2017-12-21 00:34:0057class AudioContentDescription;
Steve Anton46afbf92019-05-10 18:15:1858class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 11:36:1659class RtpDataContentDescription;
60class SctpDataContentDescription;
Steve Anton4ab68ee2017-12-19 22:26:1161
Steve Anton5adfafd2017-12-21 00:34:0062// Describes a session description media section. There are subclasses for each
63// media type (audio, video, data) that will have additional information.
64class MediaContentDescription {
Steve Antonafd8e8c2017-12-20 00:35:3565 public:
Steve Anton5adfafd2017-12-21 00:34:0066 MediaContentDescription() = default;
67 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-20 00:35:3568
69 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-21 00:34:0070
71 // Try to cast this media description to an AudioContentDescription. Returns
72 // nullptr if the cast fails.
73 virtual AudioContentDescription* as_audio() { return nullptr; }
74 virtual const AudioContentDescription* as_audio() const { return nullptr; }
75
76 // Try to cast this media description to a VideoContentDescription. Returns
77 // nullptr if the cast fails.
78 virtual VideoContentDescription* as_video() { return nullptr; }
79 virtual const VideoContentDescription* as_video() const { return nullptr; }
80
Harald Alvestrand5fc28b12019-05-13 11:36:1681 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
82 virtual const RtpDataContentDescription* as_rtp_data() const {
83 return nullptr;
84 }
85
86 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
87 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
88
Steve Antonafd8e8c2017-12-20 00:35:3589 virtual bool has_codecs() const = 0;
90
Harald Alvestrand0fb07f82020-02-27 19:21:3791 // Copy operator that returns an unique_ptr.
92 // Not a virtual function.
93 // If a type-specific variant of Clone() is desired, override it, or
94 // simply use std::make_unique<typename>(*this) instead of Clone().
95 std::unique_ptr<MediaContentDescription> Clone() const {
96 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 18:35:4597 }
Steve Anton5adfafd2017-12-21 00:34:0098
Steve Antonafd8e8c2017-12-20 00:35:3599 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
100 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 11:36:16101 virtual std::string protocol() const { return protocol_; }
102 virtual void set_protocol(const std::string& protocol) {
103 protocol_ = protocol;
104 }
Steve Antonafd8e8c2017-12-20 00:35:35105
Harald Alvestrand5fc28b12019-05-13 11:36:16106 virtual webrtc::RtpTransceiverDirection direction() const {
107 return direction_;
108 }
109 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-20 00:35:35110 direction_ = direction;
111 }
112
Harald Alvestrand5fc28b12019-05-13 11:36:16113 virtual bool rtcp_mux() const { return rtcp_mux_; }
114 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-20 00:35:35115
Harald Alvestrand5fc28b12019-05-13 11:36:16116 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
117 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-20 00:35:35118 rtcp_reduced_size_ = reduced_size;
119 }
120
Sebastian Jansson97321b62019-07-24 12:01:18121 // Indicates support for the remote network estimate packet type. This
122 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 09:38:03123 virtual bool remote_estimate() const { return remote_estimate_; }
124 virtual void set_remote_estimate(bool remote_estimate) {
125 remote_estimate_ = remote_estimate;
126 }
127
Harald Alvestrand5fc28b12019-05-13 11:36:16128 virtual int bandwidth() const { return bandwidth_; }
129 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Taylor Brandstetteree8c2462020-07-27 22:52:02130 virtual std::string bandwidth_type() const { return bandwidth_type_; }
131 virtual void set_bandwidth_type(std::string bandwidth_type) {
132 bandwidth_type_ = bandwidth_type;
133 }
Steve Antonafd8e8c2017-12-20 00:35:35134
Harald Alvestrand5fc28b12019-05-13 11:36:16135 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
136 virtual void AddCrypto(const CryptoParams& params) {
137 cryptos_.push_back(params);
138 }
139 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-20 00:35:35140 cryptos_ = cryptos;
141 }
142
Harald Alvestrand5fc28b12019-05-13 11:36:16143 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-20 00:35:35144 return rtp_header_extensions_;
145 }
Harald Alvestrand5fc28b12019-05-13 11:36:16146 virtual void set_rtp_header_extensions(
147 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-20 00:35:35148 rtp_header_extensions_ = extensions;
149 rtp_header_extensions_set_ = true;
150 }
Harald Alvestrand5fc28b12019-05-13 11:36:16151 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-20 00:35:35152 rtp_header_extensions_.push_back(ext);
153 rtp_header_extensions_set_ = true;
154 }
Harald Alvestrand5fc28b12019-05-13 11:36:16155 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-20 00:35:35156 rtp_header_extensions_.clear();
157 rtp_header_extensions_set_ = true;
158 }
159 // We can't always tell if an empty list of header extensions is
160 // because the other side doesn't support them, or just isn't hooked up to
161 // signal them. For now we assume an empty list means no signaling, but
162 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
163 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 11:36:16164 virtual bool rtp_header_extensions_set() const {
165 return rtp_header_extensions_set_;
166 }
167 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-20 00:35:35168 // TODO(pthatcher): Remove this by giving mediamessage.cc access
169 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 11:36:16170 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
171 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 23:30:11172 send_streams_.push_back(stream);
173 }
Steve Antonafd8e8c2017-12-20 00:35:35174 // Legacy streams have an ssrc, but nothing else.
175 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 11:36:16176 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-20 00:35:35177 }
178 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
179 StreamParams sp = StreamParams::CreateLegacy(ssrc);
180 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 11:36:16181 AddStream(sp);
Steve Antonafd8e8c2017-12-20 00:35:35182 }
Amit Hilbuchc57d5732018-12-11 23:30:11183
Steve Antonafd8e8c2017-12-20 00:35:35184 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 11:36:16185 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 23:30:11186 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
187 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-20 00:35:35188 if (it->cname.empty())
189 it->cname = cname;
190 }
191 }
Harald Alvestrand5fc28b12019-05-13 11:36:16192 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 23:30:11193 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-20 00:35:35194 return 0;
195 }
Amit Hilbuchc57d5732018-12-11 23:30:11196 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-20 00:35:35197 }
Harald Alvestrand5fc28b12019-05-13 11:36:16198 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 23:30:11199 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-20 00:35:35200 return false;
201 }
Amit Hilbuchc57d5732018-12-11 23:30:11202 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-20 00:35:35203 }
204
Harald Alvestrand5fc28b12019-05-13 11:36:16205 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
206 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-20 00:35:35207
208 // https://tools.ietf.org/html/rfc4566#section-5.7
209 // May be present at the media or session level of SDP. If present at both
210 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 11:36:16211 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-20 00:35:35212 connection_address_ = address;
213 }
Harald Alvestrand5fc28b12019-05-13 11:36:16214 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-20 00:35:35215 return connection_address_;
216 }
217
Johannes Kron0854eb62018-10-10 20:33:20218 // Determines if it's allowed to mix one- and two-byte rtp header extensions
219 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 08:17:39220 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 11:36:16221 virtual void set_extmap_allow_mixed_enum(
222 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 08:54:26223 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 08:17:39224 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 20:33:20225 // Do not downgrade from session level to media level.
226 return;
227 }
Johannes Kron9581bc42018-10-23 08:17:39228 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 20:33:20229 }
Harald Alvestrand5fc28b12019-05-13 11:36:16230 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 08:17:39231 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 08:54:26232 }
Harald Alvestrand5fc28b12019-05-13 11:36:16233 virtual bool extmap_allow_mixed() const {
234 return extmap_allow_mixed_enum_ != kNo;
235 }
Johannes Kron0854eb62018-10-10 20:33:20236
Amit Hilbucha2012042018-12-03 19:35:05237 // Simulcast functionality.
238 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
239 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
240 virtual const SimulcastDescription& simulcast_description() const {
241 return simulcast_;
242 }
243 virtual void set_simulcast_description(
244 const SimulcastDescription& simulcast) {
245 simulcast_ = simulcast;
246 }
Florent Castellib60141b2019-07-03 10:47:54247 virtual const std::vector<RidDescription>& receive_rids() const {
248 return receive_rids_;
249 }
250 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
251 receive_rids_ = rids;
252 }
Amit Hilbucha2012042018-12-03 19:35:05253
Steve Antonafd8e8c2017-12-20 00:35:35254 protected:
255 bool rtcp_mux_ = false;
256 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 09:38:03257 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-20 00:35:35258 int bandwidth_ = kAutoBandwidth;
Taylor Brandstetteree8c2462020-07-27 22:52:02259 std::string bandwidth_type_ = kApplicationSpecificBandwidth;
Steve Antonafd8e8c2017-12-20 00:35:35260 std::string protocol_;
261 std::vector<CryptoParams> cryptos_;
262 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
263 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 23:30:11264 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-20 00:35:35265 bool conference_mode_ = false;
266 webrtc::RtpTransceiverDirection direction_ =
267 webrtc::RtpTransceiverDirection::kSendRecv;
268 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 20:33:20269 // Mixed one- and two-byte header not included in offer on media level or
270 // session level, but we will respond that we support it. The plan is to add
271 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 08:17:39272 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 19:35:05273
274 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 10:47:54275 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 22:12:47276
Harald Alvestrand0fb07f82020-02-27 19:21:37277 private:
278 // Copy function that returns a raw pointer. Caller will assert ownership.
279 // Should only be called by the Clone() function. Must be implemented
280 // by each final subclass.
281 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-20 00:35:35282};
283
284template <class C>
285class MediaContentDescriptionImpl : public MediaContentDescription {
286 public:
Harald Alvestrand5fc28b12019-05-13 11:36:16287 void set_protocol(const std::string& protocol) override {
288 RTC_DCHECK(IsRtpProtocol(protocol));
289 protocol_ = protocol;
290 }
291
Steve Antonafd8e8c2017-12-20 00:35:35292 typedef C CodecType;
293
294 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 11:36:16295 virtual const std::vector<C>& codecs() const { return codecs_; }
296 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
297 bool has_codecs() const override { return !codecs_.empty(); }
298 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-20 00:35:35299 bool found = false;
300 for (typename std::vector<C>::iterator iter = codecs_.begin();
301 iter != codecs_.end(); ++iter) {
302 if (iter->id == id) {
303 found = true;
304 break;
305 }
306 }
307 return found;
308 }
Harald Alvestrand5fc28b12019-05-13 11:36:16309 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
310 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-20 00:35:35311 for (typename std::vector<C>::iterator iter = codecs_.begin();
312 iter != codecs_.end(); ++iter) {
313 if (iter->id == codec.id) {
314 *iter = codec;
315 return;
316 }
317 }
318 AddCodec(codec);
319 }
Harald Alvestrand5fc28b12019-05-13 11:36:16320 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-20 00:35:35321 typename std::vector<C>::const_iterator codec;
322 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
323 AddCodec(*codec);
324 }
325 }
326
327 private:
328 std::vector<C> codecs_;
329};
330
331class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
332 public:
333 AudioContentDescription() {}
334
Steve Antonafd8e8c2017-12-20 00:35:35335 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-21 00:34:00336 virtual AudioContentDescription* as_audio() { return this; }
337 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 19:21:37338
339 private:
340 virtual AudioContentDescription* CloneInternal() const {
341 return new AudioContentDescription(*this);
342 }
Steve Antonafd8e8c2017-12-20 00:35:35343};
344
345class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
346 public:
Steve Antonafd8e8c2017-12-20 00:35:35347 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-21 00:34:00348 virtual VideoContentDescription* as_video() { return this; }
349 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 19:21:37350
351 private:
352 virtual VideoContentDescription* CloneInternal() const {
353 return new VideoContentDescription(*this);
354 }
Steve Antonafd8e8c2017-12-20 00:35:35355};
356
Harald Alvestrand5fc28b12019-05-13 11:36:16357class RtpDataContentDescription
358 : public MediaContentDescriptionImpl<RtpDataCodec> {
359 public:
360 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 11:36:16361 MediaType type() const override { return MEDIA_TYPE_DATA; }
362 RtpDataContentDescription* as_rtp_data() override { return this; }
363 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand0fb07f82020-02-27 19:21:37364
365 private:
366 RtpDataContentDescription* CloneInternal() const override {
367 return new RtpDataContentDescription(*this);
368 }
Harald Alvestrand5fc28b12019-05-13 11:36:16369};
370
371class SctpDataContentDescription : public MediaContentDescription {
372 public:
373 SctpDataContentDescription() {}
374 SctpDataContentDescription(const SctpDataContentDescription& o)
375 : MediaContentDescription(o),
376 use_sctpmap_(o.use_sctpmap_),
377 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 09:46:59378 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 11:36:16379 MediaType type() const override { return MEDIA_TYPE_DATA; }
380 SctpDataContentDescription* as_sctp() override { return this; }
381 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 11:36:16382
383 bool has_codecs() const override { return false; }
384 void set_protocol(const std::string& protocol) override {
385 RTC_DCHECK(IsSctpProtocol(protocol));
386 protocol_ = protocol;
387 }
Steve Antonafd8e8c2017-12-20 00:35:35388
389 bool use_sctpmap() const { return use_sctpmap_; }
390 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 11:36:16391 int port() const { return port_; }
392 void set_port(int port) { port_ = port; }
393 int max_message_size() const { return max_message_size_; }
394 void set_max_message_size(int max_message_size) {
395 max_message_size_ = max_message_size;
396 }
Steve Antonafd8e8c2017-12-20 00:35:35397
398 private:
Harald Alvestrand0fb07f82020-02-27 19:21:37399 SctpDataContentDescription* CloneInternal() const override {
400 return new SctpDataContentDescription(*this);
401 }
Harald Alvestrand5fc28b12019-05-13 11:36:16402 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
403 // Defaults should be constants imported from SCTP. Quick hack.
404 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 06:07:47405 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
406 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-20 00:35:35407};
408
Steve Anton5adfafd2017-12-21 00:34:00409// Protocol used for encoding media. This is the "top level" protocol that may
410// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
411enum class MediaProtocolType {
412 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
413 // https://tools.ietf.org/html/rfc3550
414 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
415 // https://tools.ietf.org/html/rfc4960
416};
417
Steve Anton5adfafd2017-12-21 00:34:00418// Represents a session description section. Most information about the section
419// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 18:35:45420// Owns the description.
Mirko Bonadei35214fc2019-09-23 12:54:28421class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 18:35:45422 public:
Steve Anton5adfafd2017-12-21 00:34:00423 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 18:35:45424 ~ContentInfo();
425 // Copy
426 ContentInfo(const ContentInfo& o);
427 ContentInfo& operator=(const ContentInfo& o);
428 ContentInfo(ContentInfo&& o) = default;
429 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-21 00:34:00430
431 // Alias for |name|.
432 std::string mid() const { return name; }
433 void set_mid(const std::string& mid) { this->name = mid; }
434
435 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 18:35:45436 MediaContentDescription* media_description();
437 const MediaContentDescription* media_description() const;
438
439 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
440 description_ = std::move(desc);
Steve Anton5adfafd2017-12-21 00:34:00441 }
442
Steve Anton81712112018-01-05 19:27:54443 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 22:26:11444 std::string name;
Steve Anton5adfafd2017-12-21 00:34:00445 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 22:26:11446 bool rejected = false;
447 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 18:35:45448
449 private:
450 friend class SessionDescription;
451 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 22:26:11452};
453
454typedef std::vector<std::string> ContentNames;
455
456// This class provides a mechanism to aggregate different media contents into a
457// group. This group can also be shared with the peers in a pre-defined format.
458// GroupInfo should be populated only with the |content_name| of the
459// MediaDescription.
460class ContentGroup {
461 public:
462 explicit ContentGroup(const std::string& semantics);
463 ContentGroup(const ContentGroup&);
464 ContentGroup(ContentGroup&&);
465 ContentGroup& operator=(const ContentGroup&);
466 ContentGroup& operator=(ContentGroup&&);
467 ~ContentGroup();
468
469 const std::string& semantics() const { return semantics_; }
470 const ContentNames& content_names() const { return content_names_; }
471
472 const std::string* FirstContentName() const;
473 bool HasContentName(const std::string& content_name) const;
474 void AddContentName(const std::string& content_name);
475 bool RemoveContentName(const std::string& content_name);
476
477 private:
478 std::string semantics_;
479 ContentNames content_names_;
480};
481
482typedef std::vector<ContentInfo> ContentInfos;
483typedef std::vector<ContentGroup> ContentGroups;
484
485const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
486 const std::string& name);
487const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
488 const std::string& type);
489
Steve Antone831b8c2018-02-01 20:22:16490// Determines how the MSID will be signaled in the SDP. These can be used as
491// flags to indicate both or none.
492enum MsidSignaling {
493 // Signal MSID with one a=msid line in the media section.
494 kMsidSignalingMediaSection = 0x1,
495 // Signal MSID with a=ssrc: msid lines in the media section.
496 kMsidSignalingSsrcAttribute = 0x2
497};
498
Steve Anton4ab68ee2017-12-19 22:26:11499// Describes a collection of contents, each with its own name and
500// type. Analogous to a <jingle> or <session> stanza. Assumes that
501// contents are unique be name, but doesn't enforce that.
502class SessionDescription {
503 public:
504 SessionDescription();
Steve Anton4ab68ee2017-12-19 22:26:11505 ~SessionDescription();
506
Harald Alvestrand4d7160e2019-04-12 05:01:29507 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 22:26:11508
509 // Content accessors.
510 const ContentInfos& contents() const { return contents_; }
511 ContentInfos& contents() { return contents_; }
512 const ContentInfo* GetContentByName(const std::string& name) const;
513 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 23:14:30514 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 22:26:11515 const std::string& name) const;
Steve Antonb1c1de12017-12-21 23:14:30516 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-21 00:34:00517 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 22:26:11518 const ContentInfo* FirstContent() const;
519
520 // Content mutators.
521 // Adds a content to this description. Takes ownership of ContentDescription*.
522 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-21 00:34:00523 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 18:35:45524 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 22:26:11525 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-21 00:34:00526 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 22:26:11527 bool rejected,
Harald Alvestrand1716d392019-06-03 18:35:45528 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 22:26:11529 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-21 00:34:00530 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 22:26:11531 bool rejected,
532 bool bundle_only,
Harald Alvestrand1716d392019-06-03 18:35:45533 std::unique_ptr<MediaContentDescription> description);
534 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 08:54:26535
Steve Anton4ab68ee2017-12-19 22:26:11536 bool RemoveContentByName(const std::string& name);
537
538 // Transport accessors.
539 const TransportInfos& transport_infos() const { return transport_infos_; }
540 TransportInfos& transport_infos() { return transport_infos_; }
541 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
542 TransportInfo* GetTransportInfoByName(const std::string& name);
543 const TransportDescription* GetTransportDescriptionByName(
544 const std::string& name) const {
545 const TransportInfo* tinfo = GetTransportInfoByName(name);
546 return tinfo ? &tinfo->description : NULL;
547 }
548
549 // Transport mutators.
550 void set_transport_infos(const TransportInfos& transport_infos) {
551 transport_infos_ = transport_infos;
552 }
553 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 23:55:30554 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 22:26:11555 bool RemoveTransportInfoByName(const std::string& name);
556
557 // Group accessors.
558 const ContentGroups& groups() const { return content_groups_; }
559 const ContentGroup* GetGroupByName(const std::string& name) const;
560 bool HasGroup(const std::string& name) const;
561
562 // Group mutators.
563 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
564 // Remove the first group with the same semantics specified by |name|.
565 void RemoveGroupByName(const std::string& name);
566
567 // Global attributes.
568 void set_msid_supported(bool supported) { msid_supported_ = supported; }
569 bool msid_supported() const { return msid_supported_; }
570
Steve Antone831b8c2018-02-01 20:22:16571 // Determines how the MSIDs were/will be signaled. Flag value composed of
572 // MsidSignaling bits (see enum above).
573 void set_msid_signaling(int msid_signaling) {
574 msid_signaling_ = msid_signaling;
575 }
576 int msid_signaling() const { return msid_signaling_; }
577
Johannes Kron0854eb62018-10-10 20:33:20578 // Determines if it's allowed to mix one- and two-byte rtp header extensions
579 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 08:17:39580 void set_extmap_allow_mixed(bool supported) {
581 extmap_allow_mixed_ = supported;
582 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 20:33:20583 supported ? MediaContentDescription::kSession
584 : MediaContentDescription::kNo;
585 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 08:54:26586 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 08:17:39587 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
588 MediaContentDescription::kMedia) {
589 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 08:54:26590 media_level_setting);
591 }
Johannes Kron0854eb62018-10-10 20:33:20592 }
593 }
Johannes Kron9581bc42018-10-23 08:17:39594 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 20:33:20595
Steve Anton4ab68ee2017-12-19 22:26:11596 private:
597 SessionDescription(const SessionDescription&);
598
599 ContentInfos contents_;
600 TransportInfos transport_infos_;
601 ContentGroups content_groups_;
602 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 20:22:16603 // Default to what Plan B would do.
604 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
605 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 09:25:48606 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
607 // offer at session level. It's currently not included in offer by default
608 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
609 // correctly. If it's included in offer to us we will respond that we support
610 // it.
Johannes Kron9581bc42018-10-23 08:17:39611 bool extmap_allow_mixed_ = false;
Steve Anton4ab68ee2017-12-19 22:26:11612};
613
Steve Antonb1c1de12017-12-21 23:14:30614// Indicates whether a session description was sent by the local client or
615// received from the remote client.
Steve Anton4ab68ee2017-12-19 22:26:11616enum ContentSource { CS_LOCAL, CS_REMOTE };
617
618} // namespace cricket
619
Steve Anton10542f22019-01-11 17:11:00620#endif // PC_SESSION_DESCRIPTION_H_