blob: eb9401f0ba2a230c8429d1de89d28ea945b9dc98 [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>
19#include <vector>
20
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020021#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/crypto_params.h"
23#include "api/media_types.h"
24#include "api/rtp_parameters.h"
25#include "api/rtp_transceiver_interface.h"
26#include "media/base/media_channel.h"
27#include "media/base/stream_params.h"
28#include "p2p/base/transport_description.h"
29#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020030#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020032#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "rtc_base/socket_address.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080034
35namespace cricket {
36
Steve Antonafd8e8c2017-12-19 16:35:35 -080037typedef std::vector<AudioCodec> AudioCodecs;
38typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020039typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080040typedef std::vector<CryptoParams> CryptoParamsVec;
41typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
42
43// RTC4585 RTP/AVPF
44extern const char kMediaProtocolAvpf[];
45// RFC5124 RTP/SAVPF
46extern const char kMediaProtocolSavpf[];
47
48extern const char kMediaProtocolDtlsSavpf[];
49
Steve Antonafd8e8c2017-12-19 16:35:35 -080050
51// Options to control how session descriptions are generated.
52const int kAutoBandwidth = -1;
53
Steve Anton5adfafd2017-12-20 16:34:00 -080054class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070055class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020056class DataContentDescription;
57class 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 // Backwards compatible shim: Return a shim object that allows
80 // callers to ignore the distinction between RtpDataContentDescription
81 // and SctpDataContentDescription objects.
Harald Alvestranda33a8602019-05-28 11:33:50 +020082 RTC_DEPRECATED virtual DataContentDescription* as_data() { return nullptr; }
83 RTC_DEPRECATED virtual const DataContentDescription* as_data() const {
84 return nullptr;
85 }
86 virtual DataContentDescription* deprecated_as_data() { return nullptr; }
Steve Anton5adfafd2017-12-20 16:34:00 -080087
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020088 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
89 virtual const RtpDataContentDescription* as_rtp_data() const {
90 return nullptr;
91 }
92
93 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
94 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
95
Steve Antonafd8e8c2017-12-19 16:35:35 -080096 virtual bool has_codecs() const = 0;
97
Steve Anton5adfafd2017-12-20 16:34:00 -080098 virtual MediaContentDescription* Copy() const = 0;
99
Steve Antonafd8e8c2017-12-19 16:35:35 -0800100 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
101 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200102 virtual std::string protocol() const { return protocol_; }
103 virtual void set_protocol(const std::string& protocol) {
104 protocol_ = protocol;
105 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800106
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200107 virtual webrtc::RtpTransceiverDirection direction() const {
108 return direction_;
109 }
110 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800111 direction_ = direction;
112 }
113
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200114 virtual bool rtcp_mux() const { return rtcp_mux_; }
115 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800116
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200117 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
118 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800119 rtcp_reduced_size_ = reduced_size;
120 }
121
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200122 virtual int bandwidth() const { return bandwidth_; }
123 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800124
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200125 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
126 virtual void AddCrypto(const CryptoParams& params) {
127 cryptos_.push_back(params);
128 }
129 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800130 cryptos_ = cryptos;
131 }
132
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200133 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800134 return rtp_header_extensions_;
135 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200136 virtual void set_rtp_header_extensions(
137 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800138 rtp_header_extensions_ = extensions;
139 rtp_header_extensions_set_ = true;
140 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200141 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800142 rtp_header_extensions_.push_back(ext);
143 rtp_header_extensions_set_ = true;
144 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200145 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800146 webrtc::RtpExtension webrtc_extension;
147 webrtc_extension.uri = ext.uri;
148 webrtc_extension.id = ext.id;
149 rtp_header_extensions_.push_back(webrtc_extension);
150 rtp_header_extensions_set_ = true;
151 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200152 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800153 rtp_header_extensions_.clear();
154 rtp_header_extensions_set_ = true;
155 }
156 // We can't always tell if an empty list of header extensions is
157 // because the other side doesn't support them, or just isn't hooked up to
158 // signal them. For now we assume an empty list means no signaling, but
159 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
160 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200161 virtual bool rtp_header_extensions_set() const {
162 return rtp_header_extensions_set_;
163 }
164 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800165 // TODO(pthatcher): Remove this by giving mediamessage.cc access
166 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200167 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
168 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800169 send_streams_.push_back(stream);
170 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800171 // Legacy streams have an ssrc, but nothing else.
172 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200173 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800174 }
175 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
176 StreamParams sp = StreamParams::CreateLegacy(ssrc);
177 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200178 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800179 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800180
Steve Antonafd8e8c2017-12-19 16:35:35 -0800181 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200182 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800183 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
184 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 if (it->cname.empty())
186 it->cname = cname;
187 }
188 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200189 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800190 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800191 return 0;
192 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800193 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800194 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200195 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800196 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800197 return false;
198 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800199 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800200 }
201
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200202 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
203 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800204
205 // https://tools.ietf.org/html/rfc4566#section-5.7
206 // May be present at the media or session level of SDP. If present at both
207 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200208 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800209 connection_address_ = address;
210 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200211 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800212 return connection_address_;
213 }
214
Johannes Kron0854eb62018-10-10 22:33:20 +0200215 // Determines if it's allowed to mix one- and two-byte rtp header extensions
216 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200217 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200218 virtual void set_extmap_allow_mixed_enum(
219 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200220 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200221 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200222 // Do not downgrade from session level to media level.
223 return;
224 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200225 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200226 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200227 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200228 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200229 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200230 virtual bool extmap_allow_mixed() const {
231 return extmap_allow_mixed_enum_ != kNo;
232 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200233
Amit Hilbucha2012042018-12-03 11:35:05 -0800234 // Simulcast functionality.
235 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
236 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
237 virtual const SimulcastDescription& simulcast_description() const {
238 return simulcast_;
239 }
240 virtual void set_simulcast_description(
241 const SimulcastDescription& simulcast) {
242 simulcast_ = simulcast;
243 }
244
Steve Antonafd8e8c2017-12-19 16:35:35 -0800245 protected:
246 bool rtcp_mux_ = false;
247 bool rtcp_reduced_size_ = false;
248 int bandwidth_ = kAutoBandwidth;
249 std::string protocol_;
250 std::vector<CryptoParams> cryptos_;
251 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
252 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800253 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800254 bool conference_mode_ = false;
255 webrtc::RtpTransceiverDirection direction_ =
256 webrtc::RtpTransceiverDirection::kSendRecv;
257 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200258 // Mixed one- and two-byte header not included in offer on media level or
259 // session level, but we will respond that we support it. The plan is to add
260 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200261 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800262
263 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800264};
265
Steve Anton5adfafd2017-12-20 16:34:00 -0800266// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
267// updated.
268using ContentDescription = MediaContentDescription;
269
Steve Antonafd8e8c2017-12-19 16:35:35 -0800270template <class C>
271class MediaContentDescriptionImpl : public MediaContentDescription {
272 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200273 void set_protocol(const std::string& protocol) override {
274 RTC_DCHECK(IsRtpProtocol(protocol));
275 protocol_ = protocol;
276 }
277
Steve Antonafd8e8c2017-12-19 16:35:35 -0800278 typedef C CodecType;
279
280 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200281 virtual const std::vector<C>& codecs() const { return codecs_; }
282 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
283 bool has_codecs() const override { return !codecs_.empty(); }
284 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800285 bool found = false;
286 for (typename std::vector<C>::iterator iter = codecs_.begin();
287 iter != codecs_.end(); ++iter) {
288 if (iter->id == id) {
289 found = true;
290 break;
291 }
292 }
293 return found;
294 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200295 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
296 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800297 for (typename std::vector<C>::iterator iter = codecs_.begin();
298 iter != codecs_.end(); ++iter) {
299 if (iter->id == codec.id) {
300 *iter = codec;
301 return;
302 }
303 }
304 AddCodec(codec);
305 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200306 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800307 typename std::vector<C>::const_iterator codec;
308 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
309 AddCodec(*codec);
310 }
311 }
312
313 private:
314 std::vector<C> codecs_;
315};
316
317class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
318 public:
319 AudioContentDescription() {}
320
Steve Antonb1c1de12017-12-21 15:14:30 -0800321 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800322 return new AudioContentDescription(*this);
323 }
324 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800325 virtual AudioContentDescription* as_audio() { return this; }
326 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800327};
328
329class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
330 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800331 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800332 return new VideoContentDescription(*this);
333 }
334 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800335 virtual VideoContentDescription* as_video() { return this; }
336 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800337};
338
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200339// The DataContentDescription is a shim over the RtpDataContentDescription
340// and SctpDataContentDescription classes that is used for external callers
341// into this internal API.
342// It is a templated derivation of MediaContentDescriptionImpl because
343// that's what the external caller expects it to be.
344// TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it
345// once external callers have been updated.
Steve Antonafd8e8c2017-12-19 16:35:35 -0800346class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
347 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200348 DataContentDescription();
349 MediaType type() const override { return MEDIA_TYPE_DATA; }
Harald Alvestranda33a8602019-05-28 11:33:50 +0200350 RTC_DEPRECATED DataContentDescription* as_data() override { return this; }
351 RTC_DEPRECATED const DataContentDescription* as_data() const override {
352 return this;
353 }
354 DataContentDescription* deprecated_as_data() override { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800355
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200356 // Override all methods defined in MediaContentDescription.
357 bool has_codecs() const override;
358 DataContentDescription* Copy() const override {
359 return new DataContentDescription(this);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800360 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200361 std::string protocol() const override;
362 void set_protocol(const std::string& protocol) override;
363 webrtc::RtpTransceiverDirection direction() const override;
364 void set_direction(webrtc::RtpTransceiverDirection direction) override;
365 bool rtcp_mux() const override;
366 void set_rtcp_mux(bool mux) override;
367 bool rtcp_reduced_size() const override;
368 void set_rtcp_reduced_size(bool) override;
369 int bandwidth() const override;
370 void set_bandwidth(int bandwidth) override;
371 const std::vector<CryptoParams>& cryptos() const override;
372 void AddCrypto(const CryptoParams& params) override;
373 void set_cryptos(const std::vector<CryptoParams>& cryptos) override;
374 const RtpHeaderExtensions& rtp_header_extensions() const override;
375 void set_rtp_header_extensions(
376 const RtpHeaderExtensions& extensions) override;
377 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) override;
378 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) override;
379 void ClearRtpHeaderExtensions() override;
380 bool rtp_header_extensions_set() const override;
381 const StreamParamsVec& streams() const override;
382 StreamParamsVec& mutable_streams() override;
383 void AddStream(const StreamParams& stream) override;
384 void SetCnameIfEmpty(const std::string& cname) override;
385 uint32_t first_ssrc() const override;
386 bool has_ssrcs() const override;
387 void set_conference_mode(bool enable) override;
388 bool conference_mode() const override;
389 void set_connection_address(const rtc::SocketAddress& address) override;
390 const rtc::SocketAddress& connection_address() const override;
391 void set_extmap_allow_mixed_enum(ExtmapAllowMixed) override;
392 ExtmapAllowMixed extmap_allow_mixed_enum() const override;
393 bool HasSimulcast() const override;
394 SimulcastDescription& simulcast_description() override;
395 const SimulcastDescription& simulcast_description() const override;
396 void set_simulcast_description(
397 const SimulcastDescription& simulcast) override;
398
399 // Override all methods defined in MediaContentDescriptionImpl.
400 const std::vector<CodecType>& codecs() const override;
401 void set_codecs(const std::vector<CodecType>& codecs) override;
402 bool HasCodec(int id) override;
403 void AddCodec(const CodecType& codec) override;
404 void AddOrReplaceCodec(const CodecType& codec) override;
405 void AddCodecs(const std::vector<CodecType>& codec) override;
406
407 private:
408 typedef MediaContentDescriptionImpl<DataCodec> Super;
409 // Friend classes are allowed to create proxies for themselves.
410 friend class RtpDataContentDescription; // for constructors
411 friend class SctpDataContentDescription;
412 friend class SessionDescription; // for Unshim()
413 // Copy constructor. A copy results in an object that owns its
414 // real description, which is a copy of the original description
415 // (whether that was owned or not).
416 explicit DataContentDescription(const DataContentDescription* o);
417
418 explicit DataContentDescription(RtpDataContentDescription*);
419 explicit DataContentDescription(SctpDataContentDescription*);
420
421 // Exposed for internal use - new clients should not use this class.
422 RtpDataContentDescription* as_rtp_data() override;
423 SctpDataContentDescription* as_sctp() override;
424
425 // Create a shimmed object, owned by the shim.
426 void CreateShimTarget(bool is_sctp);
427
428 // Return the shimmed object, passing ownership if owned, and set
429 // |should_delete| to true if it was the owner. If |should_delete|
430 // is true on return, the caller should immediately delete the
431 // DataContentDescription object.
432 MediaContentDescription* Unshim(bool* should_delete);
433
434 // Returns whether SCTP is in use. False when it's not decided.
435 bool IsSctp() const;
436 // Check function for use when caller obviously assumes RTP.
437 void EnsureIsRtp();
438
439 MediaContentDescription* real_description_ = nullptr;
440 std::unique_ptr<MediaContentDescription> owned_description_;
441};
442
443class RtpDataContentDescription
444 : public MediaContentDescriptionImpl<RtpDataCodec> {
445 public:
446 RtpDataContentDescription() {}
447 RtpDataContentDescription(const RtpDataContentDescription& o)
448 : MediaContentDescriptionImpl<RtpDataCodec>(o), shim_(nullptr) {}
449 RtpDataContentDescription& operator=(const RtpDataContentDescription& o) {
450 this->MediaContentDescriptionImpl<RtpDataCodec>::operator=(o);
451 // Do not copy the shim.
452 return *this;
453 }
454
455 RtpDataContentDescription* Copy() const override {
456 return new RtpDataContentDescription(*this);
457 }
458 MediaType type() const override { return MEDIA_TYPE_DATA; }
459 RtpDataContentDescription* as_rtp_data() override { return this; }
460 const RtpDataContentDescription* as_rtp_data() const override { return this; }
461 // Shim support
Harald Alvestranda33a8602019-05-28 11:33:50 +0200462 RTC_DEPRECATED DataContentDescription* as_data() override;
463 RTC_DEPRECATED const DataContentDescription* as_data() const override;
464 DataContentDescription* deprecated_as_data() override;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200465
466 private:
467 std::unique_ptr<DataContentDescription> shim_;
468};
469
470class SctpDataContentDescription : public MediaContentDescription {
471 public:
472 SctpDataContentDescription() {}
473 SctpDataContentDescription(const SctpDataContentDescription& o)
474 : MediaContentDescription(o),
475 use_sctpmap_(o.use_sctpmap_),
476 port_(o.port_),
477 max_message_size_(o.max_message_size_),
478 shim_(nullptr) {}
479 SctpDataContentDescription* Copy() const override {
480 return new SctpDataContentDescription(*this);
481 }
482 MediaType type() const override { return MEDIA_TYPE_DATA; }
483 SctpDataContentDescription* as_sctp() override { return this; }
484 const SctpDataContentDescription* as_sctp() const override { return this; }
485 // Shim support
Harald Alvestranda33a8602019-05-28 11:33:50 +0200486 RTC_DEPRECATED DataContentDescription* as_data() override;
487 RTC_DEPRECATED const DataContentDescription* as_data() const override;
488 DataContentDescription* deprecated_as_data() override;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200489
490 bool has_codecs() const override { return false; }
491 void set_protocol(const std::string& protocol) override {
492 RTC_DCHECK(IsSctpProtocol(protocol));
493 protocol_ = protocol;
494 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800495
496 bool use_sctpmap() const { return use_sctpmap_; }
497 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200498 int port() const { return port_; }
499 void set_port(int port) { port_ = port; }
500 int max_message_size() const { return max_message_size_; }
501 void set_max_message_size(int max_message_size) {
502 max_message_size_ = max_message_size;
503 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800504
505 private:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200506 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
507 // Defaults should be constants imported from SCTP. Quick hack.
508 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200509 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
510 int max_message_size_ = 64 * 1024;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200511 std::unique_ptr<DataContentDescription> shim_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800512};
513
Steve Anton5adfafd2017-12-20 16:34:00 -0800514// Protocol used for encoding media. This is the "top level" protocol that may
515// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
516enum class MediaProtocolType {
517 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
518 // https://tools.ietf.org/html/rfc3550
519 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
520 // https://tools.ietf.org/html/rfc4960
521};
522
523// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
524constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
525constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
526
527// Represents a session description section. Most information about the section
528// is stored in the description, which is a subclass of MediaContentDescription.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800529struct ContentInfo {
Steve Antonb1c1de12017-12-21 15:14:30 -0800530 friend class SessionDescription;
531
Steve Anton5adfafd2017-12-20 16:34:00 -0800532 explicit ContentInfo(MediaProtocolType type) : type(type) {}
533
534 // Alias for |name|.
535 std::string mid() const { return name; }
536 void set_mid(const std::string& mid) { this->name = mid; }
537
538 // Alias for |description|.
539 MediaContentDescription* media_description() { return description; }
540 const MediaContentDescription* media_description() const {
541 return description;
542 }
Steve Anton81712112018-01-05 11:27:54 -0800543 void set_media_description(MediaContentDescription* desc) {
544 description = desc;
Steve Anton5adfafd2017-12-20 16:34:00 -0800545 }
546
Steve Anton81712112018-01-05 11:27:54 -0800547 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800548 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800549 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800550 bool rejected = false;
551 bool bundle_only = false;
Steve Anton81712112018-01-05 11:27:54 -0800552 // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this
553 // private.
Steve Antonb1c1de12017-12-21 15:14:30 -0800554 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800555};
556
557typedef std::vector<std::string> ContentNames;
558
559// This class provides a mechanism to aggregate different media contents into a
560// group. This group can also be shared with the peers in a pre-defined format.
561// GroupInfo should be populated only with the |content_name| of the
562// MediaDescription.
563class ContentGroup {
564 public:
565 explicit ContentGroup(const std::string& semantics);
566 ContentGroup(const ContentGroup&);
567 ContentGroup(ContentGroup&&);
568 ContentGroup& operator=(const ContentGroup&);
569 ContentGroup& operator=(ContentGroup&&);
570 ~ContentGroup();
571
572 const std::string& semantics() const { return semantics_; }
573 const ContentNames& content_names() const { return content_names_; }
574
575 const std::string* FirstContentName() const;
576 bool HasContentName(const std::string& content_name) const;
577 void AddContentName(const std::string& content_name);
578 bool RemoveContentName(const std::string& content_name);
579
580 private:
581 std::string semantics_;
582 ContentNames content_names_;
583};
584
585typedef std::vector<ContentInfo> ContentInfos;
586typedef std::vector<ContentGroup> ContentGroups;
587
588const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
589 const std::string& name);
590const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
591 const std::string& type);
592
Steve Antone831b8c2018-02-01 12:22:16 -0800593// Determines how the MSID will be signaled in the SDP. These can be used as
594// flags to indicate both or none.
595enum MsidSignaling {
596 // Signal MSID with one a=msid line in the media section.
597 kMsidSignalingMediaSection = 0x1,
598 // Signal MSID with a=ssrc: msid lines in the media section.
599 kMsidSignalingSsrcAttribute = 0x2
600};
601
Steve Anton4ab68ee2017-12-19 14:26:11 -0800602// Describes a collection of contents, each with its own name and
603// type. Analogous to a <jingle> or <session> stanza. Assumes that
604// contents are unique be name, but doesn't enforce that.
605class SessionDescription {
606 public:
607 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800608 ~SessionDescription();
609
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200610 std::unique_ptr<SessionDescription> Clone() const;
Harald Alvestrand8da35a62019-05-10 09:31:04 +0200611 // Older API - deprecated. Still expects caller to take ownership.
612 // Replace with Clone().
613 RTC_DEPRECATED SessionDescription* Copy() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800614
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800615 struct MediaTransportSetting;
616
Steve Anton4ab68ee2017-12-19 14:26:11 -0800617 // Content accessors.
618 const ContentInfos& contents() const { return contents_; }
619 ContentInfos& contents() { return contents_; }
620 const ContentInfo* GetContentByName(const std::string& name) const;
621 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800622 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800623 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800624 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800625 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800626 const ContentInfo* FirstContent() const;
627
628 // Content mutators.
629 // Adds a content to this description. Takes ownership of ContentDescription*.
630 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800631 MediaProtocolType type,
Steve Antonb1c1de12017-12-21 15:14:30 -0800632 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800633 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800634 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800635 bool rejected,
Steve Antonb1c1de12017-12-21 15:14:30 -0800636 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800637 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800638 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800639 bool rejected,
640 bool bundle_only,
Steve Antonb1c1de12017-12-21 15:14:30 -0800641 MediaContentDescription* description);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200642 void AddContent(ContentInfo* content);
643
Steve Anton4ab68ee2017-12-19 14:26:11 -0800644 bool RemoveContentByName(const std::string& name);
645
646 // Transport accessors.
647 const TransportInfos& transport_infos() const { return transport_infos_; }
648 TransportInfos& transport_infos() { return transport_infos_; }
649 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
650 TransportInfo* GetTransportInfoByName(const std::string& name);
651 const TransportDescription* GetTransportDescriptionByName(
652 const std::string& name) const {
653 const TransportInfo* tinfo = GetTransportInfoByName(name);
654 return tinfo ? &tinfo->description : NULL;
655 }
656
657 // Transport mutators.
658 void set_transport_infos(const TransportInfos& transport_infos) {
659 transport_infos_ = transport_infos;
660 }
661 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800662 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800663 bool RemoveTransportInfoByName(const std::string& name);
664
665 // Group accessors.
666 const ContentGroups& groups() const { return content_groups_; }
667 const ContentGroup* GetGroupByName(const std::string& name) const;
668 bool HasGroup(const std::string& name) const;
669
670 // Group mutators.
671 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
672 // Remove the first group with the same semantics specified by |name|.
673 void RemoveGroupByName(const std::string& name);
674
675 // Global attributes.
676 void set_msid_supported(bool supported) { msid_supported_ = supported; }
677 bool msid_supported() const { return msid_supported_; }
678
Steve Antone831b8c2018-02-01 12:22:16 -0800679 // Determines how the MSIDs were/will be signaled. Flag value composed of
680 // MsidSignaling bits (see enum above).
681 void set_msid_signaling(int msid_signaling) {
682 msid_signaling_ = msid_signaling;
683 }
684 int msid_signaling() const { return msid_signaling_; }
685
Johannes Kron0854eb62018-10-10 22:33:20 +0200686 // Determines if it's allowed to mix one- and two-byte rtp header extensions
687 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200688 void set_extmap_allow_mixed(bool supported) {
689 extmap_allow_mixed_ = supported;
690 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200691 supported ? MediaContentDescription::kSession
692 : MediaContentDescription::kNo;
693 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200694 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200695 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
696 MediaContentDescription::kMedia) {
697 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200698 media_level_setting);
699 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200700 }
701 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200702 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200703
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800704 // Adds the media transport setting.
705 // Media transport name uniquely identifies the type of media transport.
706 // The name cannot be empty, or repeated in the previously added transport
707 // settings.
708 void AddMediaTransportSetting(const std::string& media_transport_name,
709 const std::string& media_transport_setting) {
710 RTC_DCHECK(!media_transport_name.empty());
711 for (const auto& setting : media_transport_settings_) {
712 RTC_DCHECK(media_transport_name != setting.transport_name)
713 << "MediaTransportSetting was already registered, transport_name="
714 << setting.transport_name;
715 }
716 media_transport_settings_.push_back(
717 {media_transport_name, media_transport_setting});
718 }
719
720 // Gets the media transport settings, in order of preference.
721 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
722 return media_transport_settings_;
723 }
724
725 struct MediaTransportSetting {
726 std::string transport_name;
727 std::string transport_setting;
728 };
729
Steve Anton4ab68ee2017-12-19 14:26:11 -0800730 private:
731 SessionDescription(const SessionDescription&);
732
733 ContentInfos contents_;
734 TransportInfos transport_infos_;
735 ContentGroups content_groups_;
736 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800737 // Default to what Plan B would do.
738 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
739 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100740 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
741 // offer at session level. It's currently not included in offer by default
742 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
743 // correctly. If it's included in offer to us we will respond that we support
744 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200745 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800746
747 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800748};
749
Steve Antonb1c1de12017-12-21 15:14:30 -0800750// Indicates whether a session description was sent by the local client or
751// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800752enum ContentSource { CS_LOCAL, CS_REMOTE };
753
754} // namespace cricket
755
Steve Anton10542f22019-01-11 09:11:00 -0800756#endif // PC_SESSION_DESCRIPTION_H_