blob: b724cb91f7050cf1561e34fbec1260c0cf790542 [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>
16#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020017#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080018#include <string>
Harald Alvestrand1716d392019-06-03 20:35:45 +020019#include <utility>
Steve Anton4ab68ee2017-12-19 14:26:11 -080020#include <vector>
21
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020022#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/crypto_params.h"
24#include "api/media_types.h"
25#include "api/rtp_parameters.h"
26#include "api/rtp_transceiver_interface.h"
27#include "media/base/media_channel.h"
28#include "media/base/stream_params.h"
29#include "p2p/base/transport_description.h"
30#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020031#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020033#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "rtc_base/socket_address.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080035
36namespace cricket {
37
Steve Antonafd8e8c2017-12-19 16:35:35 -080038typedef std::vector<AudioCodec> AudioCodecs;
39typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020040typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080041typedef std::vector<CryptoParams> CryptoParamsVec;
42typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
43
44// RTC4585 RTP/AVPF
45extern const char kMediaProtocolAvpf[];
46// RFC5124 RTP/SAVPF
47extern const char kMediaProtocolSavpf[];
48
49extern const char kMediaProtocolDtlsSavpf[];
50
Steve Antonafd8e8c2017-12-19 16:35:35 -080051
52// Options to control how session descriptions are generated.
53const int kAutoBandwidth = -1;
54
Steve Anton5adfafd2017-12-20 16:34:00 -080055class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070056class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020057class RtpDataContentDescription;
58class SctpDataContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080059
Steve Anton5adfafd2017-12-20 16:34:00 -080060// Describes a session description media section. There are subclasses for each
61// media type (audio, video, data) that will have additional information.
62class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080063 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080064 MediaContentDescription() = default;
65 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080066
67 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080068
69 // Try to cast this media description to an AudioContentDescription. Returns
70 // nullptr if the cast fails.
71 virtual AudioContentDescription* as_audio() { return nullptr; }
72 virtual const AudioContentDescription* as_audio() const { return nullptr; }
73
74 // Try to cast this media description to a VideoContentDescription. Returns
75 // nullptr if the cast fails.
76 virtual VideoContentDescription* as_video() { return nullptr; }
77 virtual const VideoContentDescription* as_video() const { return nullptr; }
78
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020079 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
80 virtual const RtpDataContentDescription* as_rtp_data() const {
81 return nullptr;
82 }
83
84 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
85 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
86
Steve Antonafd8e8c2017-12-19 16:35:35 -080087 virtual bool has_codecs() const = 0;
88
Steve Anton5adfafd2017-12-20 16:34:00 -080089 virtual MediaContentDescription* Copy() const = 0;
Harald Alvestrand1716d392019-06-03 20:35:45 +020090 virtual std::unique_ptr<MediaContentDescription> Clone() const {
91 return absl::WrapUnique(Copy());
92 }
Steve Anton5adfafd2017-12-20 16:34:00 -080093
Steve Antonafd8e8c2017-12-19 16:35:35 -080094 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
95 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020096 virtual std::string protocol() const { return protocol_; }
97 virtual void set_protocol(const std::string& protocol) {
98 protocol_ = protocol;
99 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800100
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200101 virtual webrtc::RtpTransceiverDirection direction() const {
102 return direction_;
103 }
104 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800105 direction_ = direction;
106 }
107
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200108 virtual bool rtcp_mux() const { return rtcp_mux_; }
109 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800110
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200111 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
112 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800113 rtcp_reduced_size_ = reduced_size;
114 }
115
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200116 virtual int bandwidth() const { return bandwidth_; }
117 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800118
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200119 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
120 virtual void AddCrypto(const CryptoParams& params) {
121 cryptos_.push_back(params);
122 }
123 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800124 cryptos_ = cryptos;
125 }
126
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200127 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800128 return rtp_header_extensions_;
129 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200130 virtual void set_rtp_header_extensions(
131 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800132 rtp_header_extensions_ = extensions;
133 rtp_header_extensions_set_ = true;
134 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200135 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800136 rtp_header_extensions_.push_back(ext);
137 rtp_header_extensions_set_ = true;
138 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200139 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800140 webrtc::RtpExtension webrtc_extension;
141 webrtc_extension.uri = ext.uri;
142 webrtc_extension.id = ext.id;
143 rtp_header_extensions_.push_back(webrtc_extension);
144 rtp_header_extensions_set_ = true;
145 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800147 rtp_header_extensions_.clear();
148 rtp_header_extensions_set_ = true;
149 }
150 // We can't always tell if an empty list of header extensions is
151 // because the other side doesn't support them, or just isn't hooked up to
152 // signal them. For now we assume an empty list means no signaling, but
153 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
154 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200155 virtual bool rtp_header_extensions_set() const {
156 return rtp_header_extensions_set_;
157 }
158 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800159 // TODO(pthatcher): Remove this by giving mediamessage.cc access
160 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200161 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
162 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800163 send_streams_.push_back(stream);
164 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800165 // Legacy streams have an ssrc, but nothing else.
166 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200167 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800168 }
169 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
170 StreamParams sp = StreamParams::CreateLegacy(ssrc);
171 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200172 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800173 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800174
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200176 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800177 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
178 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800179 if (it->cname.empty())
180 it->cname = cname;
181 }
182 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200183 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800184 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 return 0;
186 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800187 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800188 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200189 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800190 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800191 return false;
192 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800193 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800194 }
195
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200196 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
197 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800198
199 // https://tools.ietf.org/html/rfc4566#section-5.7
200 // May be present at the media or session level of SDP. If present at both
201 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200202 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800203 connection_address_ = address;
204 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200205 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800206 return connection_address_;
207 }
208
Johannes Kron0854eb62018-10-10 22:33:20 +0200209 // Determines if it's allowed to mix one- and two-byte rtp header extensions
210 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200211 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200212 virtual void set_extmap_allow_mixed_enum(
213 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200214 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200215 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200216 // Do not downgrade from session level to media level.
217 return;
218 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200219 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200220 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200221 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200222 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200223 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200224 virtual bool extmap_allow_mixed() const {
225 return extmap_allow_mixed_enum_ != kNo;
226 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200227
Amit Hilbucha2012042018-12-03 11:35:05 -0800228 // Simulcast functionality.
229 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
230 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
231 virtual const SimulcastDescription& simulcast_description() const {
232 return simulcast_;
233 }
234 virtual void set_simulcast_description(
235 const SimulcastDescription& simulcast) {
236 simulcast_ = simulcast;
237 }
238
Steve Antonafd8e8c2017-12-19 16:35:35 -0800239 protected:
240 bool rtcp_mux_ = false;
241 bool rtcp_reduced_size_ = false;
242 int bandwidth_ = kAutoBandwidth;
243 std::string protocol_;
244 std::vector<CryptoParams> cryptos_;
245 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
246 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800247 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800248 bool conference_mode_ = false;
249 webrtc::RtpTransceiverDirection direction_ =
250 webrtc::RtpTransceiverDirection::kSendRecv;
251 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200252 // Mixed one- and two-byte header not included in offer on media level or
253 // session level, but we will respond that we support it. The plan is to add
254 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200255 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800256
257 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800258};
259
Steve Anton5adfafd2017-12-20 16:34:00 -0800260// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
261// updated.
262using ContentDescription = MediaContentDescription;
263
Steve Antonafd8e8c2017-12-19 16:35:35 -0800264template <class C>
265class MediaContentDescriptionImpl : public MediaContentDescription {
266 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200267 void set_protocol(const std::string& protocol) override {
268 RTC_DCHECK(IsRtpProtocol(protocol));
269 protocol_ = protocol;
270 }
271
Steve Antonafd8e8c2017-12-19 16:35:35 -0800272 typedef C CodecType;
273
274 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200275 virtual const std::vector<C>& codecs() const { return codecs_; }
276 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
277 bool has_codecs() const override { return !codecs_.empty(); }
278 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800279 bool found = false;
280 for (typename std::vector<C>::iterator iter = codecs_.begin();
281 iter != codecs_.end(); ++iter) {
282 if (iter->id == id) {
283 found = true;
284 break;
285 }
286 }
287 return found;
288 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200289 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
290 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800291 for (typename std::vector<C>::iterator iter = codecs_.begin();
292 iter != codecs_.end(); ++iter) {
293 if (iter->id == codec.id) {
294 *iter = codec;
295 return;
296 }
297 }
298 AddCodec(codec);
299 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200300 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800301 typename std::vector<C>::const_iterator codec;
302 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
303 AddCodec(*codec);
304 }
305 }
306
307 private:
308 std::vector<C> codecs_;
309};
310
311class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
312 public:
313 AudioContentDescription() {}
314
Steve Antonb1c1de12017-12-21 15:14:30 -0800315 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800316 return new AudioContentDescription(*this);
317 }
318 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800319 virtual AudioContentDescription* as_audio() { return this; }
320 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800321};
322
323class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
324 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800325 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800326 return new VideoContentDescription(*this);
327 }
328 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800329 virtual VideoContentDescription* as_video() { return this; }
330 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800331};
332
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200333class RtpDataContentDescription
334 : public MediaContentDescriptionImpl<RtpDataCodec> {
335 public:
336 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200337 RtpDataContentDescription* Copy() const override {
338 return new RtpDataContentDescription(*this);
339 }
340 MediaType type() const override { return MEDIA_TYPE_DATA; }
341 RtpDataContentDescription* as_rtp_data() override { return this; }
342 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200343};
344
345class SctpDataContentDescription : public MediaContentDescription {
346 public:
347 SctpDataContentDescription() {}
348 SctpDataContentDescription(const SctpDataContentDescription& o)
349 : MediaContentDescription(o),
350 use_sctpmap_(o.use_sctpmap_),
351 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200352 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200353 SctpDataContentDescription* Copy() const override {
354 return new SctpDataContentDescription(*this);
355 }
356 MediaType type() const override { return MEDIA_TYPE_DATA; }
357 SctpDataContentDescription* as_sctp() override { return this; }
358 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200359
360 bool has_codecs() const override { return false; }
361 void set_protocol(const std::string& protocol) override {
362 RTC_DCHECK(IsSctpProtocol(protocol));
363 protocol_ = protocol;
364 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800365
366 bool use_sctpmap() const { return use_sctpmap_; }
367 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200368 int port() const { return port_; }
369 void set_port(int port) { port_ = port; }
370 int max_message_size() const { return max_message_size_; }
371 void set_max_message_size(int max_message_size) {
372 max_message_size_ = max_message_size;
373 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800374
375 private:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200376 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
377 // Defaults should be constants imported from SCTP. Quick hack.
378 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200379 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
380 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800381};
382
Steve Anton5adfafd2017-12-20 16:34:00 -0800383// Protocol used for encoding media. This is the "top level" protocol that may
384// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
385enum class MediaProtocolType {
386 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
387 // https://tools.ietf.org/html/rfc3550
388 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
389 // https://tools.ietf.org/html/rfc4960
390};
391
392// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
393constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
394constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
395
396// Represents a session description section. Most information about the section
397// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200398// Owns the description.
399class ContentInfo {
400 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800401 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200402 ~ContentInfo();
403 // Copy
404 ContentInfo(const ContentInfo& o);
405 ContentInfo& operator=(const ContentInfo& o);
406 ContentInfo(ContentInfo&& o) = default;
407 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800408
409 // Alias for |name|.
410 std::string mid() const { return name; }
411 void set_mid(const std::string& mid) { this->name = mid; }
412
413 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200414 MediaContentDescription* media_description();
415 const MediaContentDescription* media_description() const;
416
417 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
418 description_ = std::move(desc);
419 // For backwards compatibility only.
420 description = description_.get();
Steve Anton5adfafd2017-12-20 16:34:00 -0800421 }
422
Steve Anton81712112018-01-05 11:27:54 -0800423 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800424 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800425 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800426 bool rejected = false;
427 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200428
429 private:
430 friend class SessionDescription;
431 std::unique_ptr<MediaContentDescription> description_;
432
433 public:
434 // Kept for backwards compatibility only.
Steve Antonb1c1de12017-12-21 15:14:30 -0800435 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800436};
437
438typedef std::vector<std::string> ContentNames;
439
440// This class provides a mechanism to aggregate different media contents into a
441// group. This group can also be shared with the peers in a pre-defined format.
442// GroupInfo should be populated only with the |content_name| of the
443// MediaDescription.
444class ContentGroup {
445 public:
446 explicit ContentGroup(const std::string& semantics);
447 ContentGroup(const ContentGroup&);
448 ContentGroup(ContentGroup&&);
449 ContentGroup& operator=(const ContentGroup&);
450 ContentGroup& operator=(ContentGroup&&);
451 ~ContentGroup();
452
453 const std::string& semantics() const { return semantics_; }
454 const ContentNames& content_names() const { return content_names_; }
455
456 const std::string* FirstContentName() const;
457 bool HasContentName(const std::string& content_name) const;
458 void AddContentName(const std::string& content_name);
459 bool RemoveContentName(const std::string& content_name);
460
461 private:
462 std::string semantics_;
463 ContentNames content_names_;
464};
465
466typedef std::vector<ContentInfo> ContentInfos;
467typedef std::vector<ContentGroup> ContentGroups;
468
469const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
470 const std::string& name);
471const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
472 const std::string& type);
473
Steve Antone831b8c2018-02-01 12:22:16 -0800474// Determines how the MSID will be signaled in the SDP. These can be used as
475// flags to indicate both or none.
476enum MsidSignaling {
477 // Signal MSID with one a=msid line in the media section.
478 kMsidSignalingMediaSection = 0x1,
479 // Signal MSID with a=ssrc: msid lines in the media section.
480 kMsidSignalingSsrcAttribute = 0x2
481};
482
Steve Anton4ab68ee2017-12-19 14:26:11 -0800483// Describes a collection of contents, each with its own name and
484// type. Analogous to a <jingle> or <session> stanza. Assumes that
485// contents are unique be name, but doesn't enforce that.
486class SessionDescription {
487 public:
488 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800489 ~SessionDescription();
490
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200491 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800492
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800493 struct MediaTransportSetting;
494
Steve Anton4ab68ee2017-12-19 14:26:11 -0800495 // Content accessors.
496 const ContentInfos& contents() const { return contents_; }
497 ContentInfos& contents() { return contents_; }
498 const ContentInfo* GetContentByName(const std::string& name) const;
499 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800500 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800501 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800502 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800503 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800504 const ContentInfo* FirstContent() const;
505
506 // Content mutators.
507 // Adds a content to this description. Takes ownership of ContentDescription*.
508 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800509 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200510 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800511 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800512 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800513 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200514 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800515 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800516 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800517 bool rejected,
518 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200519 std::unique_ptr<MediaContentDescription> description);
520 void AddContent(ContentInfo&& content);
521 RTC_DEPRECATED void AddContent(const std::string& name,
522 MediaProtocolType type,
523 MediaContentDescription* description) {
524 AddContent(name, type, absl::WrapUnique(description));
525 }
526 RTC_DEPRECATED void AddContent(const std::string& name,
527 MediaProtocolType type,
528 bool rejected,
529 MediaContentDescription* description) {
530 AddContent(name, type, rejected, absl::WrapUnique(description));
531 }
532 RTC_DEPRECATED void AddContent(const std::string& name,
533 MediaProtocolType type,
534 bool rejected,
535 bool bundle_only,
536 MediaContentDescription* description) {
537 AddContent(name, type, rejected, bundle_only,
538 absl::WrapUnique(description));
539 }
540
541 RTC_DEPRECATED void AddContent(ContentInfo* content) {
542 AddContent(std::move(*content));
543 }
Johannes Kron9ac3c912018-10-12 10:54:26 +0200544
Steve Anton4ab68ee2017-12-19 14:26:11 -0800545 bool RemoveContentByName(const std::string& name);
546
547 // Transport accessors.
548 const TransportInfos& transport_infos() const { return transport_infos_; }
549 TransportInfos& transport_infos() { return transport_infos_; }
550 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
551 TransportInfo* GetTransportInfoByName(const std::string& name);
552 const TransportDescription* GetTransportDescriptionByName(
553 const std::string& name) const {
554 const TransportInfo* tinfo = GetTransportInfoByName(name);
555 return tinfo ? &tinfo->description : NULL;
556 }
557
558 // Transport mutators.
559 void set_transport_infos(const TransportInfos& transport_infos) {
560 transport_infos_ = transport_infos;
561 }
562 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800563 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800564 bool RemoveTransportInfoByName(const std::string& name);
565
566 // Group accessors.
567 const ContentGroups& groups() const { return content_groups_; }
568 const ContentGroup* GetGroupByName(const std::string& name) const;
569 bool HasGroup(const std::string& name) const;
570
571 // Group mutators.
572 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
573 // Remove the first group with the same semantics specified by |name|.
574 void RemoveGroupByName(const std::string& name);
575
576 // Global attributes.
577 void set_msid_supported(bool supported) { msid_supported_ = supported; }
578 bool msid_supported() const { return msid_supported_; }
579
Steve Antone831b8c2018-02-01 12:22:16 -0800580 // Determines how the MSIDs were/will be signaled. Flag value composed of
581 // MsidSignaling bits (see enum above).
582 void set_msid_signaling(int msid_signaling) {
583 msid_signaling_ = msid_signaling;
584 }
585 int msid_signaling() const { return msid_signaling_; }
586
Johannes Kron0854eb62018-10-10 22:33:20 +0200587 // Determines if it's allowed to mix one- and two-byte rtp header extensions
588 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200589 void set_extmap_allow_mixed(bool supported) {
590 extmap_allow_mixed_ = supported;
591 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200592 supported ? MediaContentDescription::kSession
593 : MediaContentDescription::kNo;
594 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200595 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200596 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
597 MediaContentDescription::kMedia) {
598 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200599 media_level_setting);
600 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200601 }
602 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200603 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200604
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800605 // Adds the media transport setting.
606 // Media transport name uniquely identifies the type of media transport.
607 // The name cannot be empty, or repeated in the previously added transport
608 // settings.
609 void AddMediaTransportSetting(const std::string& media_transport_name,
610 const std::string& media_transport_setting) {
611 RTC_DCHECK(!media_transport_name.empty());
612 for (const auto& setting : media_transport_settings_) {
613 RTC_DCHECK(media_transport_name != setting.transport_name)
614 << "MediaTransportSetting was already registered, transport_name="
615 << setting.transport_name;
616 }
617 media_transport_settings_.push_back(
618 {media_transport_name, media_transport_setting});
619 }
620
621 // Gets the media transport settings, in order of preference.
622 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
623 return media_transport_settings_;
624 }
625
626 struct MediaTransportSetting {
627 std::string transport_name;
628 std::string transport_setting;
629 };
630
Steve Anton4ab68ee2017-12-19 14:26:11 -0800631 private:
632 SessionDescription(const SessionDescription&);
633
634 ContentInfos contents_;
635 TransportInfos transport_infos_;
636 ContentGroups content_groups_;
637 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800638 // Default to what Plan B would do.
639 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
640 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100641 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
642 // offer at session level. It's currently not included in offer by default
643 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
644 // correctly. If it's included in offer to us we will respond that we support
645 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200646 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800647
648 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800649};
650
Steve Antonb1c1de12017-12-21 15:14:30 -0800651// Indicates whether a session description was sent by the local client or
652// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800653enum ContentSource { CS_LOCAL, CS_REMOTE };
654
655} // namespace cricket
656
Steve Anton10542f22019-01-11 09:11:00 -0800657#endif // PC_SESSION_DESCRIPTION_H_