blob: 99e78d8d28de8bbe4b1c457122f9445a241f9006 [file] [log] [blame]
Steve Anton4ab68ee2017-12-19 14:26:11 -08001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_SESSION_DESCRIPTION_H_
12#define PC_SESSION_DESCRIPTION_H_
Steve Anton4ab68ee2017-12-19 14:26:11 -080013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020018#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080019#include <string>
Harald Alvestrand1716d392019-06-03 20:35:45 +020020#include <utility>
Steve Anton4ab68ee2017-12-19 14:26:11 -080021#include <vector>
22
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020023#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto_params.h"
25#include "api/media_types.h"
26#include "api/rtp_parameters.h"
27#include "api/rtp_transceiver_interface.h"
28#include "media/base/media_channel.h"
29#include "media/base/stream_params.h"
30#include "p2p/base/transport_description.h"
31#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020032#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020034#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080035#include "rtc_base/socket_address.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080036
37namespace cricket {
38
Steve Antonafd8e8c2017-12-19 16:35:35 -080039typedef std::vector<AudioCodec> AudioCodecs;
40typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020041typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080042typedef std::vector<CryptoParams> CryptoParamsVec;
43typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
44
45// RTC4585 RTP/AVPF
46extern const char kMediaProtocolAvpf[];
47// RFC5124 RTP/SAVPF
48extern const char kMediaProtocolSavpf[];
49
50extern const char kMediaProtocolDtlsSavpf[];
51
Steve Antonafd8e8c2017-12-19 16:35:35 -080052// 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
Sebastian Jansson97321b62019-07-24 14:01:18 +0200116 // Indicates support for the remote network estimate packet type. This
117 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200118 virtual bool remote_estimate() const { return remote_estimate_; }
119 virtual void set_remote_estimate(bool remote_estimate) {
120 remote_estimate_ = remote_estimate;
121 }
122
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200123 virtual int bandwidth() const { return bandwidth_; }
124 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800125
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200126 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
127 virtual void AddCrypto(const CryptoParams& params) {
128 cryptos_.push_back(params);
129 }
130 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800131 cryptos_ = cryptos;
132 }
133
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200134 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800135 return rtp_header_extensions_;
136 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200137 virtual void set_rtp_header_extensions(
138 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800139 rtp_header_extensions_ = extensions;
140 rtp_header_extensions_set_ = true;
141 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200142 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800143 rtp_header_extensions_.push_back(ext);
144 rtp_header_extensions_set_ = true;
145 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800147 webrtc::RtpExtension webrtc_extension;
148 webrtc_extension.uri = ext.uri;
149 webrtc_extension.id = ext.id;
150 rtp_header_extensions_.push_back(webrtc_extension);
151 rtp_header_extensions_set_ = true;
152 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200153 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800154 rtp_header_extensions_.clear();
155 rtp_header_extensions_set_ = true;
156 }
157 // We can't always tell if an empty list of header extensions is
158 // because the other side doesn't support them, or just isn't hooked up to
159 // signal them. For now we assume an empty list means no signaling, but
160 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
161 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200162 virtual bool rtp_header_extensions_set() const {
163 return rtp_header_extensions_set_;
164 }
165 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800166 // TODO(pthatcher): Remove this by giving mediamessage.cc access
167 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200168 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
169 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800170 send_streams_.push_back(stream);
171 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800172 // Legacy streams have an ssrc, but nothing else.
173 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200174 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 }
176 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
177 StreamParams sp = StreamParams::CreateLegacy(ssrc);
178 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200179 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800180 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800181
Steve Antonafd8e8c2017-12-19 16:35:35 -0800182 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200183 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800184 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
185 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800186 if (it->cname.empty())
187 it->cname = cname;
188 }
189 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200190 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800191 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800192 return 0;
193 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800195 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200196 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800197 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800198 return false;
199 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800200 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800201 }
202
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200203 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
204 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800205
206 // https://tools.ietf.org/html/rfc4566#section-5.7
207 // May be present at the media or session level of SDP. If present at both
208 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200209 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800210 connection_address_ = address;
211 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200212 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800213 return connection_address_;
214 }
215
Johannes Kron0854eb62018-10-10 22:33:20 +0200216 // Determines if it's allowed to mix one- and two-byte rtp header extensions
217 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200218 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200219 virtual void set_extmap_allow_mixed_enum(
220 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200221 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200222 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200223 // Do not downgrade from session level to media level.
224 return;
225 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200226 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200227 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200228 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200229 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200230 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200231 virtual bool extmap_allow_mixed() const {
232 return extmap_allow_mixed_enum_ != kNo;
233 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200234
Amit Hilbucha2012042018-12-03 11:35:05 -0800235 // Simulcast functionality.
236 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
237 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
238 virtual const SimulcastDescription& simulcast_description() const {
239 return simulcast_;
240 }
241 virtual void set_simulcast_description(
242 const SimulcastDescription& simulcast) {
243 simulcast_ = simulcast;
244 }
Florent Castellib60141b2019-07-03 12:47:54 +0200245 virtual const std::vector<RidDescription>& receive_rids() const {
246 return receive_rids_;
247 }
248 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
249 receive_rids_ = rids;
250 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800251
Steve Antonafd8e8c2017-12-19 16:35:35 -0800252 protected:
253 bool rtcp_mux_ = false;
254 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200255 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800256 int bandwidth_ = kAutoBandwidth;
257 std::string protocol_;
258 std::vector<CryptoParams> cryptos_;
259 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
260 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800261 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800262 bool conference_mode_ = false;
263 webrtc::RtpTransceiverDirection direction_ =
264 webrtc::RtpTransceiverDirection::kSendRecv;
265 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200266 // Mixed one- and two-byte header not included in offer on media level or
267 // session level, but we will respond that we support it. The plan is to add
268 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200269 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800270
271 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200272 std::vector<RidDescription> receive_rids_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800273};
274
Steve Anton5adfafd2017-12-20 16:34:00 -0800275// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
276// updated.
277using ContentDescription = MediaContentDescription;
278
Steve Antonafd8e8c2017-12-19 16:35:35 -0800279template <class C>
280class MediaContentDescriptionImpl : public MediaContentDescription {
281 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200282 void set_protocol(const std::string& protocol) override {
283 RTC_DCHECK(IsRtpProtocol(protocol));
284 protocol_ = protocol;
285 }
286
Steve Antonafd8e8c2017-12-19 16:35:35 -0800287 typedef C CodecType;
288
289 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200290 virtual const std::vector<C>& codecs() const { return codecs_; }
291 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
292 bool has_codecs() const override { return !codecs_.empty(); }
293 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800294 bool found = false;
295 for (typename std::vector<C>::iterator iter = codecs_.begin();
296 iter != codecs_.end(); ++iter) {
297 if (iter->id == id) {
298 found = true;
299 break;
300 }
301 }
302 return found;
303 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200304 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
305 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800306 for (typename std::vector<C>::iterator iter = codecs_.begin();
307 iter != codecs_.end(); ++iter) {
308 if (iter->id == codec.id) {
309 *iter = codec;
310 return;
311 }
312 }
313 AddCodec(codec);
314 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200315 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800316 typename std::vector<C>::const_iterator codec;
317 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
318 AddCodec(*codec);
319 }
320 }
321
322 private:
323 std::vector<C> codecs_;
324};
325
326class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
327 public:
328 AudioContentDescription() {}
329
Steve Antonb1c1de12017-12-21 15:14:30 -0800330 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800331 return new AudioContentDescription(*this);
332 }
333 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; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800336};
337
338class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
339 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800340 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800341 return new VideoContentDescription(*this);
342 }
343 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800344 virtual VideoContentDescription* as_video() { return this; }
345 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800346};
347
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200348class RtpDataContentDescription
349 : public MediaContentDescriptionImpl<RtpDataCodec> {
350 public:
351 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200352 RtpDataContentDescription* Copy() const override {
353 return new RtpDataContentDescription(*this);
354 }
355 MediaType type() const override { return MEDIA_TYPE_DATA; }
356 RtpDataContentDescription* as_rtp_data() override { return this; }
357 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200358};
359
360class SctpDataContentDescription : public MediaContentDescription {
361 public:
362 SctpDataContentDescription() {}
363 SctpDataContentDescription(const SctpDataContentDescription& o)
364 : MediaContentDescription(o),
365 use_sctpmap_(o.use_sctpmap_),
366 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200367 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200368 SctpDataContentDescription* Copy() const override {
369 return new SctpDataContentDescription(*this);
370 }
371 MediaType type() const override { return MEDIA_TYPE_DATA; }
372 SctpDataContentDescription* as_sctp() override { return this; }
373 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200374
375 bool has_codecs() const override { return false; }
376 void set_protocol(const std::string& protocol) override {
377 RTC_DCHECK(IsSctpProtocol(protocol));
378 protocol_ = protocol;
379 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800380
381 bool use_sctpmap() const { return use_sctpmap_; }
382 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200383 int port() const { return port_; }
384 void set_port(int port) { port_ = port; }
385 int max_message_size() const { return max_message_size_; }
386 void set_max_message_size(int max_message_size) {
387 max_message_size_ = max_message_size;
388 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800389
390 private:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200391 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
392 // Defaults should be constants imported from SCTP. Quick hack.
393 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200394 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
395 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800396};
397
Steve Anton5adfafd2017-12-20 16:34:00 -0800398// Protocol used for encoding media. This is the "top level" protocol that may
399// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
400enum class MediaProtocolType {
401 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
402 // https://tools.ietf.org/html/rfc3550
403 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
404 // https://tools.ietf.org/html/rfc4960
405};
406
407// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
408constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
409constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
410
411// Represents a session description section. Most information about the section
412// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200413// Owns the description.
414class ContentInfo {
415 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800416 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200417 ~ContentInfo();
418 // Copy
419 ContentInfo(const ContentInfo& o);
420 ContentInfo& operator=(const ContentInfo& o);
421 ContentInfo(ContentInfo&& o) = default;
422 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800423
424 // Alias for |name|.
425 std::string mid() const { return name; }
426 void set_mid(const std::string& mid) { this->name = mid; }
427
428 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200429 MediaContentDescription* media_description();
430 const MediaContentDescription* media_description() const;
431
432 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
433 description_ = std::move(desc);
434 // For backwards compatibility only.
435 description = description_.get();
Steve Anton5adfafd2017-12-20 16:34:00 -0800436 }
437
Steve Anton81712112018-01-05 11:27:54 -0800438 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800439 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800440 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800441 bool rejected = false;
442 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200443
444 private:
445 friend class SessionDescription;
446 std::unique_ptr<MediaContentDescription> description_;
447
448 public:
449 // Kept for backwards compatibility only.
Steve Antonb1c1de12017-12-21 15:14:30 -0800450 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800451};
452
453typedef std::vector<std::string> ContentNames;
454
455// This class provides a mechanism to aggregate different media contents into a
456// group. This group can also be shared with the peers in a pre-defined format.
457// GroupInfo should be populated only with the |content_name| of the
458// MediaDescription.
459class ContentGroup {
460 public:
461 explicit ContentGroup(const std::string& semantics);
462 ContentGroup(const ContentGroup&);
463 ContentGroup(ContentGroup&&);
464 ContentGroup& operator=(const ContentGroup&);
465 ContentGroup& operator=(ContentGroup&&);
466 ~ContentGroup();
467
468 const std::string& semantics() const { return semantics_; }
469 const ContentNames& content_names() const { return content_names_; }
470
471 const std::string* FirstContentName() const;
472 bool HasContentName(const std::string& content_name) const;
473 void AddContentName(const std::string& content_name);
474 bool RemoveContentName(const std::string& content_name);
475
476 private:
477 std::string semantics_;
478 ContentNames content_names_;
479};
480
481typedef std::vector<ContentInfo> ContentInfos;
482typedef std::vector<ContentGroup> ContentGroups;
483
484const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
485 const std::string& name);
486const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
487 const std::string& type);
488
Steve Antone831b8c2018-02-01 12:22:16 -0800489// Determines how the MSID will be signaled in the SDP. These can be used as
490// flags to indicate both or none.
491enum MsidSignaling {
492 // Signal MSID with one a=msid line in the media section.
493 kMsidSignalingMediaSection = 0x1,
494 // Signal MSID with a=ssrc: msid lines in the media section.
495 kMsidSignalingSsrcAttribute = 0x2
496};
497
Steve Anton4ab68ee2017-12-19 14:26:11 -0800498// Describes a collection of contents, each with its own name and
499// type. Analogous to a <jingle> or <session> stanza. Assumes that
500// contents are unique be name, but doesn't enforce that.
501class SessionDescription {
502 public:
503 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800504 ~SessionDescription();
505
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200506 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800507
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800508 struct MediaTransportSetting;
509
Steve Anton4ab68ee2017-12-19 14:26:11 -0800510 // Content accessors.
511 const ContentInfos& contents() const { return contents_; }
512 ContentInfos& contents() { return contents_; }
513 const ContentInfo* GetContentByName(const std::string& name) const;
514 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800515 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800516 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800517 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800518 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800519 const ContentInfo* FirstContent() const;
520
521 // Content mutators.
522 // Adds a content to this description. Takes ownership of ContentDescription*.
523 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800524 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200525 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800526 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800527 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800528 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200529 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800530 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800531 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800532 bool rejected,
533 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200534 std::unique_ptr<MediaContentDescription> description);
535 void AddContent(ContentInfo&& content);
536 RTC_DEPRECATED void AddContent(const std::string& name,
537 MediaProtocolType type,
538 MediaContentDescription* description) {
539 AddContent(name, type, absl::WrapUnique(description));
540 }
541 RTC_DEPRECATED void AddContent(const std::string& name,
542 MediaProtocolType type,
543 bool rejected,
544 MediaContentDescription* description) {
545 AddContent(name, type, rejected, absl::WrapUnique(description));
546 }
547 RTC_DEPRECATED void AddContent(const std::string& name,
548 MediaProtocolType type,
549 bool rejected,
550 bool bundle_only,
551 MediaContentDescription* description) {
552 AddContent(name, type, rejected, bundle_only,
553 absl::WrapUnique(description));
554 }
555
556 RTC_DEPRECATED void AddContent(ContentInfo* content) {
557 AddContent(std::move(*content));
558 }
Johannes Kron9ac3c912018-10-12 10:54:26 +0200559
Steve Anton4ab68ee2017-12-19 14:26:11 -0800560 bool RemoveContentByName(const std::string& name);
561
562 // Transport accessors.
563 const TransportInfos& transport_infos() const { return transport_infos_; }
564 TransportInfos& transport_infos() { return transport_infos_; }
565 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
566 TransportInfo* GetTransportInfoByName(const std::string& name);
567 const TransportDescription* GetTransportDescriptionByName(
568 const std::string& name) const {
569 const TransportInfo* tinfo = GetTransportInfoByName(name);
570 return tinfo ? &tinfo->description : NULL;
571 }
572
573 // Transport mutators.
574 void set_transport_infos(const TransportInfos& transport_infos) {
575 transport_infos_ = transport_infos;
576 }
577 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800578 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800579 bool RemoveTransportInfoByName(const std::string& name);
580
581 // Group accessors.
582 const ContentGroups& groups() const { return content_groups_; }
583 const ContentGroup* GetGroupByName(const std::string& name) const;
584 bool HasGroup(const std::string& name) const;
585
586 // Group mutators.
587 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
588 // Remove the first group with the same semantics specified by |name|.
589 void RemoveGroupByName(const std::string& name);
590
591 // Global attributes.
592 void set_msid_supported(bool supported) { msid_supported_ = supported; }
593 bool msid_supported() const { return msid_supported_; }
594
Steve Antone831b8c2018-02-01 12:22:16 -0800595 // Determines how the MSIDs were/will be signaled. Flag value composed of
596 // MsidSignaling bits (see enum above).
597 void set_msid_signaling(int msid_signaling) {
598 msid_signaling_ = msid_signaling;
599 }
600 int msid_signaling() const { return msid_signaling_; }
601
Johannes Kron0854eb62018-10-10 22:33:20 +0200602 // Determines if it's allowed to mix one- and two-byte rtp header extensions
603 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200604 void set_extmap_allow_mixed(bool supported) {
605 extmap_allow_mixed_ = supported;
606 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200607 supported ? MediaContentDescription::kSession
608 : MediaContentDescription::kNo;
609 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200610 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200611 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
612 MediaContentDescription::kMedia) {
613 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200614 media_level_setting);
615 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200616 }
617 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200618 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200619
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800620 // Adds the media transport setting.
621 // Media transport name uniquely identifies the type of media transport.
622 // The name cannot be empty, or repeated in the previously added transport
623 // settings.
624 void AddMediaTransportSetting(const std::string& media_transport_name,
625 const std::string& media_transport_setting) {
626 RTC_DCHECK(!media_transport_name.empty());
627 for (const auto& setting : media_transport_settings_) {
628 RTC_DCHECK(media_transport_name != setting.transport_name)
629 << "MediaTransportSetting was already registered, transport_name="
630 << setting.transport_name;
631 }
632 media_transport_settings_.push_back(
633 {media_transport_name, media_transport_setting});
634 }
635
636 // Gets the media transport settings, in order of preference.
637 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
638 return media_transport_settings_;
639 }
640
641 struct MediaTransportSetting {
642 std::string transport_name;
643 std::string transport_setting;
644 };
645
Steve Anton4ab68ee2017-12-19 14:26:11 -0800646 private:
647 SessionDescription(const SessionDescription&);
648
649 ContentInfos contents_;
650 TransportInfos transport_infos_;
651 ContentGroups content_groups_;
652 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800653 // Default to what Plan B would do.
654 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
655 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100656 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
657 // offer at session level. It's currently not included in offer by default
658 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
659 // correctly. If it's included in offer to us we will respond that we support
660 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200661 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800662
663 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800664};
665
Steve Antonb1c1de12017-12-21 15:14:30 -0800666// Indicates whether a session description was sent by the local client or
667// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800668enum ContentSource { CS_LOCAL, CS_REMOTE };
669
670} // namespace cricket
671
Steve Anton10542f22019-01-11 09:11:00 -0800672#endif // PC_SESSION_DESCRIPTION_H_