blob: 0ff90a5340737f7be1874a29b7c231848c76d0c3 [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 DataContentDescription;
58class RtpDataContentDescription;
59class SctpDataContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080060
Steve Anton5adfafd2017-12-20 16:34:00 -080061// Describes a session description media section. There are subclasses for each
62// media type (audio, video, data) that will have additional information.
63class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080064 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080065 MediaContentDescription() = default;
66 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080067
68 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080069
70 // Try to cast this media description to an AudioContentDescription. Returns
71 // nullptr if the cast fails.
72 virtual AudioContentDescription* as_audio() { return nullptr; }
73 virtual const AudioContentDescription* as_audio() const { return nullptr; }
74
75 // Try to cast this media description to a VideoContentDescription. Returns
76 // nullptr if the cast fails.
77 virtual VideoContentDescription* as_video() { return nullptr; }
78 virtual const VideoContentDescription* as_video() const { return nullptr; }
79
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020080 // Backwards compatible shim: Return a shim object that allows
81 // callers to ignore the distinction between RtpDataContentDescription
82 // and SctpDataContentDescription objects.
Harald Alvestranda33a8602019-05-28 11:33:50 +020083 RTC_DEPRECATED virtual DataContentDescription* as_data() { return nullptr; }
84 RTC_DEPRECATED virtual const DataContentDescription* as_data() const {
85 return nullptr;
86 }
87 virtual DataContentDescription* deprecated_as_data() { return nullptr; }
Steve Anton5adfafd2017-12-20 16:34:00 -080088
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020089 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
90 virtual const RtpDataContentDescription* as_rtp_data() const {
91 return nullptr;
92 }
93
94 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
95 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
96
Steve Antonafd8e8c2017-12-19 16:35:35 -080097 virtual bool has_codecs() const = 0;
98
Steve Anton5adfafd2017-12-20 16:34:00 -080099 virtual MediaContentDescription* Copy() const = 0;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200100 virtual std::unique_ptr<MediaContentDescription> Clone() const {
101 return absl::WrapUnique(Copy());
102 }
Steve Anton5adfafd2017-12-20 16:34:00 -0800103
Steve Antonafd8e8c2017-12-19 16:35:35 -0800104 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
105 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200106 virtual std::string protocol() const { return protocol_; }
107 virtual void set_protocol(const std::string& protocol) {
108 protocol_ = protocol;
109 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800110
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200111 virtual webrtc::RtpTransceiverDirection direction() const {
112 return direction_;
113 }
114 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800115 direction_ = direction;
116 }
117
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200118 virtual bool rtcp_mux() const { return rtcp_mux_; }
119 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800120
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200121 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
122 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800123 rtcp_reduced_size_ = reduced_size;
124 }
125
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200126 virtual int bandwidth() const { return bandwidth_; }
127 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800128
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200129 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
130 virtual void AddCrypto(const CryptoParams& params) {
131 cryptos_.push_back(params);
132 }
133 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800134 cryptos_ = cryptos;
135 }
136
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200137 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800138 return rtp_header_extensions_;
139 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200140 virtual void set_rtp_header_extensions(
141 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800142 rtp_header_extensions_ = extensions;
143 rtp_header_extensions_set_ = true;
144 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200145 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800146 rtp_header_extensions_.push_back(ext);
147 rtp_header_extensions_set_ = true;
148 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200149 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800150 webrtc::RtpExtension webrtc_extension;
151 webrtc_extension.uri = ext.uri;
152 webrtc_extension.id = ext.id;
153 rtp_header_extensions_.push_back(webrtc_extension);
154 rtp_header_extensions_set_ = true;
155 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200156 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800157 rtp_header_extensions_.clear();
158 rtp_header_extensions_set_ = true;
159 }
160 // We can't always tell if an empty list of header extensions is
161 // because the other side doesn't support them, or just isn't hooked up to
162 // signal them. For now we assume an empty list means no signaling, but
163 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
164 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200165 virtual bool rtp_header_extensions_set() const {
166 return rtp_header_extensions_set_;
167 }
168 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800169 // TODO(pthatcher): Remove this by giving mediamessage.cc access
170 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200171 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
172 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800173 send_streams_.push_back(stream);
174 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 // Legacy streams have an ssrc, but nothing else.
176 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200177 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800178 }
179 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
180 StreamParams sp = StreamParams::CreateLegacy(ssrc);
181 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200182 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800183 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800184
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200186 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800187 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
188 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800189 if (it->cname.empty())
190 it->cname = cname;
191 }
192 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200193 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800195 return 0;
196 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800197 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800198 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200199 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800200 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800201 return false;
202 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800203 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800204 }
205
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200206 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
207 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800208
209 // https://tools.ietf.org/html/rfc4566#section-5.7
210 // May be present at the media or session level of SDP. If present at both
211 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200212 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800213 connection_address_ = address;
214 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200215 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800216 return connection_address_;
217 }
218
Johannes Kron0854eb62018-10-10 22:33:20 +0200219 // Determines if it's allowed to mix one- and two-byte rtp header extensions
220 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200221 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200222 virtual void set_extmap_allow_mixed_enum(
223 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200224 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200225 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200226 // Do not downgrade from session level to media level.
227 return;
228 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200229 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200230 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200231 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200232 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200233 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200234 virtual bool extmap_allow_mixed() const {
235 return extmap_allow_mixed_enum_ != kNo;
236 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200237
Amit Hilbucha2012042018-12-03 11:35:05 -0800238 // Simulcast functionality.
239 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
240 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
241 virtual const SimulcastDescription& simulcast_description() const {
242 return simulcast_;
243 }
244 virtual void set_simulcast_description(
245 const SimulcastDescription& simulcast) {
246 simulcast_ = simulcast;
247 }
248
Steve Antonafd8e8c2017-12-19 16:35:35 -0800249 protected:
250 bool rtcp_mux_ = false;
251 bool rtcp_reduced_size_ = false;
252 int bandwidth_ = kAutoBandwidth;
253 std::string protocol_;
254 std::vector<CryptoParams> cryptos_;
255 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
256 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800257 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800258 bool conference_mode_ = false;
259 webrtc::RtpTransceiverDirection direction_ =
260 webrtc::RtpTransceiverDirection::kSendRecv;
261 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200262 // Mixed one- and two-byte header not included in offer on media level or
263 // session level, but we will respond that we support it. The plan is to add
264 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200265 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800266
267 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800268};
269
Steve Anton5adfafd2017-12-20 16:34:00 -0800270// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
271// updated.
272using ContentDescription = MediaContentDescription;
273
Steve Antonafd8e8c2017-12-19 16:35:35 -0800274template <class C>
275class MediaContentDescriptionImpl : public MediaContentDescription {
276 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200277 void set_protocol(const std::string& protocol) override {
278 RTC_DCHECK(IsRtpProtocol(protocol));
279 protocol_ = protocol;
280 }
281
Steve Antonafd8e8c2017-12-19 16:35:35 -0800282 typedef C CodecType;
283
284 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200285 virtual const std::vector<C>& codecs() const { return codecs_; }
286 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
287 bool has_codecs() const override { return !codecs_.empty(); }
288 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800289 bool found = false;
290 for (typename std::vector<C>::iterator iter = codecs_.begin();
291 iter != codecs_.end(); ++iter) {
292 if (iter->id == id) {
293 found = true;
294 break;
295 }
296 }
297 return found;
298 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200299 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
300 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800301 for (typename std::vector<C>::iterator iter = codecs_.begin();
302 iter != codecs_.end(); ++iter) {
303 if (iter->id == codec.id) {
304 *iter = codec;
305 return;
306 }
307 }
308 AddCodec(codec);
309 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200310 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800311 typename std::vector<C>::const_iterator codec;
312 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
313 AddCodec(*codec);
314 }
315 }
316
317 private:
318 std::vector<C> codecs_;
319};
320
321class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
322 public:
323 AudioContentDescription() {}
324
Steve Antonb1c1de12017-12-21 15:14:30 -0800325 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800326 return new AudioContentDescription(*this);
327 }
328 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800329 virtual AudioContentDescription* as_audio() { return this; }
330 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800331};
332
333class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
334 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800335 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800336 return new VideoContentDescription(*this);
337 }
338 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800339 virtual VideoContentDescription* as_video() { return this; }
340 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800341};
342
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200343// The DataContentDescription is a shim over the RtpDataContentDescription
344// and SctpDataContentDescription classes that is used for external callers
345// into this internal API.
346// It is a templated derivation of MediaContentDescriptionImpl because
347// that's what the external caller expects it to be.
348// TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it
349// once external callers have been updated.
Steve Antonafd8e8c2017-12-19 16:35:35 -0800350class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
351 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200352 DataContentDescription();
353 MediaType type() const override { return MEDIA_TYPE_DATA; }
Harald Alvestranda33a8602019-05-28 11:33:50 +0200354 RTC_DEPRECATED DataContentDescription* as_data() override { return this; }
355 RTC_DEPRECATED const DataContentDescription* as_data() const override {
356 return this;
357 }
358 DataContentDescription* deprecated_as_data() override { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800359
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200360 // Override all methods defined in MediaContentDescription.
361 bool has_codecs() const override;
362 DataContentDescription* Copy() const override {
363 return new DataContentDescription(this);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800364 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200365 std::string protocol() const override;
366 void set_protocol(const std::string& protocol) override;
367 webrtc::RtpTransceiverDirection direction() const override;
368 void set_direction(webrtc::RtpTransceiverDirection direction) override;
369 bool rtcp_mux() const override;
370 void set_rtcp_mux(bool mux) override;
371 bool rtcp_reduced_size() const override;
372 void set_rtcp_reduced_size(bool) override;
373 int bandwidth() const override;
374 void set_bandwidth(int bandwidth) override;
375 const std::vector<CryptoParams>& cryptos() const override;
376 void AddCrypto(const CryptoParams& params) override;
377 void set_cryptos(const std::vector<CryptoParams>& cryptos) override;
378 const RtpHeaderExtensions& rtp_header_extensions() const override;
379 void set_rtp_header_extensions(
380 const RtpHeaderExtensions& extensions) override;
381 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) override;
382 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) override;
383 void ClearRtpHeaderExtensions() override;
384 bool rtp_header_extensions_set() const override;
385 const StreamParamsVec& streams() const override;
386 StreamParamsVec& mutable_streams() override;
387 void AddStream(const StreamParams& stream) override;
388 void SetCnameIfEmpty(const std::string& cname) override;
389 uint32_t first_ssrc() const override;
390 bool has_ssrcs() const override;
391 void set_conference_mode(bool enable) override;
392 bool conference_mode() const override;
393 void set_connection_address(const rtc::SocketAddress& address) override;
394 const rtc::SocketAddress& connection_address() const override;
395 void set_extmap_allow_mixed_enum(ExtmapAllowMixed) override;
396 ExtmapAllowMixed extmap_allow_mixed_enum() const override;
397 bool HasSimulcast() const override;
398 SimulcastDescription& simulcast_description() override;
399 const SimulcastDescription& simulcast_description() const override;
400 void set_simulcast_description(
401 const SimulcastDescription& simulcast) override;
402
403 // Override all methods defined in MediaContentDescriptionImpl.
404 const std::vector<CodecType>& codecs() const override;
405 void set_codecs(const std::vector<CodecType>& codecs) override;
406 bool HasCodec(int id) override;
407 void AddCodec(const CodecType& codec) override;
408 void AddOrReplaceCodec(const CodecType& codec) override;
409 void AddCodecs(const std::vector<CodecType>& codec) override;
410
411 private:
412 typedef MediaContentDescriptionImpl<DataCodec> Super;
413 // Friend classes are allowed to create proxies for themselves.
414 friend class RtpDataContentDescription; // for constructors
415 friend class SctpDataContentDescription;
416 friend class SessionDescription; // for Unshim()
417 // Copy constructor. A copy results in an object that owns its
418 // real description, which is a copy of the original description
419 // (whether that was owned or not).
420 explicit DataContentDescription(const DataContentDescription* o);
421
422 explicit DataContentDescription(RtpDataContentDescription*);
423 explicit DataContentDescription(SctpDataContentDescription*);
424
425 // Exposed for internal use - new clients should not use this class.
426 RtpDataContentDescription* as_rtp_data() override;
427 SctpDataContentDescription* as_sctp() override;
428
429 // Create a shimmed object, owned by the shim.
430 void CreateShimTarget(bool is_sctp);
431
432 // Return the shimmed object, passing ownership if owned, and set
433 // |should_delete| to true if it was the owner. If |should_delete|
434 // is true on return, the caller should immediately delete the
435 // DataContentDescription object.
436 MediaContentDescription* Unshim(bool* should_delete);
437
438 // Returns whether SCTP is in use. False when it's not decided.
439 bool IsSctp() const;
440 // Check function for use when caller obviously assumes RTP.
441 void EnsureIsRtp();
442
443 MediaContentDescription* real_description_ = nullptr;
444 std::unique_ptr<MediaContentDescription> owned_description_;
445};
446
447class RtpDataContentDescription
448 : public MediaContentDescriptionImpl<RtpDataCodec> {
449 public:
450 RtpDataContentDescription() {}
451 RtpDataContentDescription(const RtpDataContentDescription& o)
452 : MediaContentDescriptionImpl<RtpDataCodec>(o), shim_(nullptr) {}
453 RtpDataContentDescription& operator=(const RtpDataContentDescription& o) {
454 this->MediaContentDescriptionImpl<RtpDataCodec>::operator=(o);
455 // Do not copy the shim.
456 return *this;
457 }
458
459 RtpDataContentDescription* Copy() const override {
460 return new RtpDataContentDescription(*this);
461 }
462 MediaType type() const override { return MEDIA_TYPE_DATA; }
463 RtpDataContentDescription* as_rtp_data() override { return this; }
464 const RtpDataContentDescription* as_rtp_data() const override { return this; }
465 // Shim support
Harald Alvestranda33a8602019-05-28 11:33:50 +0200466 RTC_DEPRECATED DataContentDescription* as_data() override;
467 RTC_DEPRECATED const DataContentDescription* as_data() const override;
468 DataContentDescription* deprecated_as_data() override;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200469
470 private:
471 std::unique_ptr<DataContentDescription> shim_;
472};
473
474class SctpDataContentDescription : public MediaContentDescription {
475 public:
476 SctpDataContentDescription() {}
477 SctpDataContentDescription(const SctpDataContentDescription& o)
478 : MediaContentDescription(o),
479 use_sctpmap_(o.use_sctpmap_),
480 port_(o.port_),
481 max_message_size_(o.max_message_size_),
482 shim_(nullptr) {}
483 SctpDataContentDescription* Copy() const override {
484 return new SctpDataContentDescription(*this);
485 }
486 MediaType type() const override { return MEDIA_TYPE_DATA; }
487 SctpDataContentDescription* as_sctp() override { return this; }
488 const SctpDataContentDescription* as_sctp() const override { return this; }
489 // Shim support
Harald Alvestranda33a8602019-05-28 11:33:50 +0200490 RTC_DEPRECATED DataContentDescription* as_data() override;
491 RTC_DEPRECATED const DataContentDescription* as_data() const override;
492 DataContentDescription* deprecated_as_data() override;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200493
494 bool has_codecs() const override { return false; }
495 void set_protocol(const std::string& protocol) override {
496 RTC_DCHECK(IsSctpProtocol(protocol));
497 protocol_ = protocol;
498 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800499
500 bool use_sctpmap() const { return use_sctpmap_; }
501 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200502 int port() const { return port_; }
503 void set_port(int port) { port_ = port; }
504 int max_message_size() const { return max_message_size_; }
505 void set_max_message_size(int max_message_size) {
506 max_message_size_ = max_message_size;
507 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800508
509 private:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200510 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
511 // Defaults should be constants imported from SCTP. Quick hack.
512 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200513 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
514 int max_message_size_ = 64 * 1024;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200515 std::unique_ptr<DataContentDescription> shim_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800516};
517
Steve Anton5adfafd2017-12-20 16:34:00 -0800518// Protocol used for encoding media. This is the "top level" protocol that may
519// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
520enum class MediaProtocolType {
521 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
522 // https://tools.ietf.org/html/rfc3550
523 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
524 // https://tools.ietf.org/html/rfc4960
525};
526
527// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
528constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
529constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
530
531// Represents a session description section. Most information about the section
532// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200533// Owns the description.
534class ContentInfo {
535 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800536 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200537 ~ContentInfo();
538 // Copy
539 ContentInfo(const ContentInfo& o);
540 ContentInfo& operator=(const ContentInfo& o);
541 ContentInfo(ContentInfo&& o) = default;
542 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800543
544 // Alias for |name|.
545 std::string mid() const { return name; }
546 void set_mid(const std::string& mid) { this->name = mid; }
547
548 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200549 MediaContentDescription* media_description();
550 const MediaContentDescription* media_description() const;
551
552 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
553 description_ = std::move(desc);
554 // For backwards compatibility only.
555 description = description_.get();
Steve Anton5adfafd2017-12-20 16:34:00 -0800556 }
557
Steve Anton81712112018-01-05 11:27:54 -0800558 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800559 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800560 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800561 bool rejected = false;
562 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200563
564 private:
565 friend class SessionDescription;
566 std::unique_ptr<MediaContentDescription> description_;
567
568 public:
569 // Kept for backwards compatibility only.
Steve Antonb1c1de12017-12-21 15:14:30 -0800570 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800571};
572
573typedef std::vector<std::string> ContentNames;
574
575// This class provides a mechanism to aggregate different media contents into a
576// group. This group can also be shared with the peers in a pre-defined format.
577// GroupInfo should be populated only with the |content_name| of the
578// MediaDescription.
579class ContentGroup {
580 public:
581 explicit ContentGroup(const std::string& semantics);
582 ContentGroup(const ContentGroup&);
583 ContentGroup(ContentGroup&&);
584 ContentGroup& operator=(const ContentGroup&);
585 ContentGroup& operator=(ContentGroup&&);
586 ~ContentGroup();
587
588 const std::string& semantics() const { return semantics_; }
589 const ContentNames& content_names() const { return content_names_; }
590
591 const std::string* FirstContentName() const;
592 bool HasContentName(const std::string& content_name) const;
593 void AddContentName(const std::string& content_name);
594 bool RemoveContentName(const std::string& content_name);
595
596 private:
597 std::string semantics_;
598 ContentNames content_names_;
599};
600
601typedef std::vector<ContentInfo> ContentInfos;
602typedef std::vector<ContentGroup> ContentGroups;
603
604const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
605 const std::string& name);
606const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
607 const std::string& type);
608
Steve Antone831b8c2018-02-01 12:22:16 -0800609// Determines how the MSID will be signaled in the SDP. These can be used as
610// flags to indicate both or none.
611enum MsidSignaling {
612 // Signal MSID with one a=msid line in the media section.
613 kMsidSignalingMediaSection = 0x1,
614 // Signal MSID with a=ssrc: msid lines in the media section.
615 kMsidSignalingSsrcAttribute = 0x2
616};
617
Steve Anton4ab68ee2017-12-19 14:26:11 -0800618// Describes a collection of contents, each with its own name and
619// type. Analogous to a <jingle> or <session> stanza. Assumes that
620// contents are unique be name, but doesn't enforce that.
621class SessionDescription {
622 public:
623 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800624 ~SessionDescription();
625
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200626 std::unique_ptr<SessionDescription> Clone() const;
Harald Alvestrand8da35a62019-05-10 09:31:04 +0200627 // Older API - deprecated. Still expects caller to take ownership.
628 // Replace with Clone().
629 RTC_DEPRECATED SessionDescription* Copy() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800630
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800631 struct MediaTransportSetting;
632
Steve Anton4ab68ee2017-12-19 14:26:11 -0800633 // Content accessors.
634 const ContentInfos& contents() const { return contents_; }
635 ContentInfos& contents() { return contents_; }
636 const ContentInfo* GetContentByName(const std::string& name) const;
637 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800638 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800639 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800640 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800641 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800642 const ContentInfo* FirstContent() const;
643
644 // Content mutators.
645 // Adds a content to this description. Takes ownership of ContentDescription*.
646 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800647 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200648 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800649 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800650 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800651 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200652 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800653 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800654 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800655 bool rejected,
656 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200657 std::unique_ptr<MediaContentDescription> description);
658 void AddContent(ContentInfo&& content);
659 RTC_DEPRECATED void AddContent(const std::string& name,
660 MediaProtocolType type,
661 MediaContentDescription* description) {
662 AddContent(name, type, absl::WrapUnique(description));
663 }
664 RTC_DEPRECATED void AddContent(const std::string& name,
665 MediaProtocolType type,
666 bool rejected,
667 MediaContentDescription* description) {
668 AddContent(name, type, rejected, absl::WrapUnique(description));
669 }
670 RTC_DEPRECATED void AddContent(const std::string& name,
671 MediaProtocolType type,
672 bool rejected,
673 bool bundle_only,
674 MediaContentDescription* description) {
675 AddContent(name, type, rejected, bundle_only,
676 absl::WrapUnique(description));
677 }
678
679 RTC_DEPRECATED void AddContent(ContentInfo* content) {
680 AddContent(std::move(*content));
681 }
Johannes Kron9ac3c912018-10-12 10:54:26 +0200682
Steve Anton4ab68ee2017-12-19 14:26:11 -0800683 bool RemoveContentByName(const std::string& name);
684
685 // Transport accessors.
686 const TransportInfos& transport_infos() const { return transport_infos_; }
687 TransportInfos& transport_infos() { return transport_infos_; }
688 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
689 TransportInfo* GetTransportInfoByName(const std::string& name);
690 const TransportDescription* GetTransportDescriptionByName(
691 const std::string& name) const {
692 const TransportInfo* tinfo = GetTransportInfoByName(name);
693 return tinfo ? &tinfo->description : NULL;
694 }
695
696 // Transport mutators.
697 void set_transport_infos(const TransportInfos& transport_infos) {
698 transport_infos_ = transport_infos;
699 }
700 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800701 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800702 bool RemoveTransportInfoByName(const std::string& name);
703
704 // Group accessors.
705 const ContentGroups& groups() const { return content_groups_; }
706 const ContentGroup* GetGroupByName(const std::string& name) const;
707 bool HasGroup(const std::string& name) const;
708
709 // Group mutators.
710 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
711 // Remove the first group with the same semantics specified by |name|.
712 void RemoveGroupByName(const std::string& name);
713
714 // Global attributes.
715 void set_msid_supported(bool supported) { msid_supported_ = supported; }
716 bool msid_supported() const { return msid_supported_; }
717
Steve Antone831b8c2018-02-01 12:22:16 -0800718 // Determines how the MSIDs were/will be signaled. Flag value composed of
719 // MsidSignaling bits (see enum above).
720 void set_msid_signaling(int msid_signaling) {
721 msid_signaling_ = msid_signaling;
722 }
723 int msid_signaling() const { return msid_signaling_; }
724
Johannes Kron0854eb62018-10-10 22:33:20 +0200725 // Determines if it's allowed to mix one- and two-byte rtp header extensions
726 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200727 void set_extmap_allow_mixed(bool supported) {
728 extmap_allow_mixed_ = supported;
729 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200730 supported ? MediaContentDescription::kSession
731 : MediaContentDescription::kNo;
732 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200733 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200734 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
735 MediaContentDescription::kMedia) {
736 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200737 media_level_setting);
738 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200739 }
740 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200741 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200742
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800743 // Adds the media transport setting.
744 // Media transport name uniquely identifies the type of media transport.
745 // The name cannot be empty, or repeated in the previously added transport
746 // settings.
747 void AddMediaTransportSetting(const std::string& media_transport_name,
748 const std::string& media_transport_setting) {
749 RTC_DCHECK(!media_transport_name.empty());
750 for (const auto& setting : media_transport_settings_) {
751 RTC_DCHECK(media_transport_name != setting.transport_name)
752 << "MediaTransportSetting was already registered, transport_name="
753 << setting.transport_name;
754 }
755 media_transport_settings_.push_back(
756 {media_transport_name, media_transport_setting});
757 }
758
759 // Gets the media transport settings, in order of preference.
760 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
761 return media_transport_settings_;
762 }
763
764 struct MediaTransportSetting {
765 std::string transport_name;
766 std::string transport_setting;
767 };
768
Steve Anton4ab68ee2017-12-19 14:26:11 -0800769 private:
770 SessionDescription(const SessionDescription&);
771
772 ContentInfos contents_;
773 TransportInfos transport_infos_;
774 ContentGroups content_groups_;
775 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800776 // Default to what Plan B would do.
777 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
778 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100779 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
780 // offer at session level. It's currently not included in offer by default
781 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
782 // correctly. If it's included in offer to us we will respond that we support
783 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200784 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800785
786 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800787};
788
Steve Antonb1c1de12017-12-21 15:14:30 -0800789// Indicates whether a session description was sent by the local client or
790// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800791enum ContentSource { CS_LOCAL, CS_REMOTE };
792
793} // namespace cricket
794
Steve Anton10542f22019-01-11 09:11:00 -0800795#endif // PC_SESSION_DESCRIPTION_H_