Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_SESSION_DESCRIPTION_H_ |
| 12 | #define PC_SESSION_DESCRIPTION_H_ |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 | #include <iosfwd> |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 17 | #include <memory> |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 18 | #include <string> |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 19 | #include <utility> |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 22 | #include "absl/memory/memory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 31 | #include "pc/media_protocol_names.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "pc/simulcast_description.h" |
Harald Alvestrand | 8da35a6 | 2019-05-10 09:31:04 +0200 | [diff] [blame] | 33 | #include "rtc_base/deprecation.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 34 | #include "rtc_base/socket_address.h" |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 35 | |
| 36 | namespace cricket { |
| 37 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 38 | typedef std::vector<AudioCodec> AudioCodecs; |
| 39 | typedef std::vector<VideoCodec> VideoCodecs; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 40 | typedef std::vector<RtpDataCodec> RtpDataCodecs; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 41 | typedef std::vector<CryptoParams> CryptoParamsVec; |
| 42 | typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions; |
| 43 | |
| 44 | // RTC4585 RTP/AVPF |
| 45 | extern const char kMediaProtocolAvpf[]; |
| 46 | // RFC5124 RTP/SAVPF |
| 47 | extern const char kMediaProtocolSavpf[]; |
| 48 | |
| 49 | extern const char kMediaProtocolDtlsSavpf[]; |
| 50 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 51 | |
| 52 | // Options to control how session descriptions are generated. |
| 53 | const int kAutoBandwidth = -1; |
| 54 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 55 | class AudioContentDescription; |
Steve Anton | 46afbf9 | 2019-05-10 11:15:18 -0700 | [diff] [blame] | 56 | class VideoContentDescription; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 57 | class DataContentDescription; |
| 58 | class RtpDataContentDescription; |
| 59 | class SctpDataContentDescription; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 60 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 61 | // Describes a session description media section. There are subclasses for each |
| 62 | // media type (audio, video, data) that will have additional information. |
| 63 | class MediaContentDescription { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 64 | public: |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 65 | MediaContentDescription() = default; |
| 66 | virtual ~MediaContentDescription() = default; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 67 | |
| 68 | virtual MediaType type() const = 0; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 69 | |
| 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 80 | // Backwards compatible shim: Return a shim object that allows |
| 81 | // callers to ignore the distinction between RtpDataContentDescription |
| 82 | // and SctpDataContentDescription objects. |
Harald Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 83 | 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 Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 88 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 89 | 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 97 | virtual bool has_codecs() const = 0; |
| 98 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 99 | virtual MediaContentDescription* Copy() const = 0; |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 100 | virtual std::unique_ptr<MediaContentDescription> Clone() const { |
| 101 | return absl::WrapUnique(Copy()); |
| 102 | } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 103 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 104 | // |protocol| is the expected media transport protocol, such as RTP/AVPF, |
| 105 | // RTP/SAVPF or SCTP/DTLS. |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 106 | virtual std::string protocol() const { return protocol_; } |
| 107 | virtual void set_protocol(const std::string& protocol) { |
| 108 | protocol_ = protocol; |
| 109 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 110 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 111 | virtual webrtc::RtpTransceiverDirection direction() const { |
| 112 | return direction_; |
| 113 | } |
| 114 | virtual void set_direction(webrtc::RtpTransceiverDirection direction) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 115 | direction_ = direction; |
| 116 | } |
| 117 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 118 | virtual bool rtcp_mux() const { return rtcp_mux_; } |
| 119 | virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 120 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 121 | virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; } |
| 122 | virtual void set_rtcp_reduced_size(bool reduced_size) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 123 | rtcp_reduced_size_ = reduced_size; |
| 124 | } |
| 125 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 126 | virtual int bandwidth() const { return bandwidth_; } |
| 127 | virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 128 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 129 | 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 134 | cryptos_ = cryptos; |
| 135 | } |
| 136 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 137 | virtual const RtpHeaderExtensions& rtp_header_extensions() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 138 | return rtp_header_extensions_; |
| 139 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 140 | virtual void set_rtp_header_extensions( |
| 141 | const RtpHeaderExtensions& extensions) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 142 | rtp_header_extensions_ = extensions; |
| 143 | rtp_header_extensions_set_ = true; |
| 144 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 145 | virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 146 | rtp_header_extensions_.push_back(ext); |
| 147 | rtp_header_extensions_set_ = true; |
| 148 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 149 | virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 150 | 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 156 | virtual void ClearRtpHeaderExtensions() { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 157 | 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 165 | virtual bool rtp_header_extensions_set() const { |
| 166 | return rtp_header_extensions_set_; |
| 167 | } |
| 168 | virtual const StreamParamsVec& streams() const { return send_streams_; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 169 | // TODO(pthatcher): Remove this by giving mediamessage.cc access |
| 170 | // to MediaContentDescription |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 171 | virtual StreamParamsVec& mutable_streams() { return send_streams_; } |
| 172 | virtual void AddStream(const StreamParams& stream) { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 173 | send_streams_.push_back(stream); |
| 174 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 175 | // Legacy streams have an ssrc, but nothing else. |
| 176 | void AddLegacyStream(uint32_t ssrc) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 177 | AddStream(StreamParams::CreateLegacy(ssrc)); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 178 | } |
| 179 | void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
| 180 | StreamParams sp = StreamParams::CreateLegacy(ssrc); |
| 181 | sp.AddFidSsrc(ssrc, fid_ssrc); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 182 | AddStream(sp); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 183 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 184 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 185 | // Sets the CNAME of all StreamParams if it have not been set. |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 186 | virtual void SetCnameIfEmpty(const std::string& cname) { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 187 | for (cricket::StreamParamsVec::iterator it = send_streams_.begin(); |
| 188 | it != send_streams_.end(); ++it) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 189 | if (it->cname.empty()) |
| 190 | it->cname = cname; |
| 191 | } |
| 192 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 193 | virtual uint32_t first_ssrc() const { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 194 | if (send_streams_.empty()) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 195 | return 0; |
| 196 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 197 | return send_streams_[0].first_ssrc(); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 198 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 199 | virtual bool has_ssrcs() const { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 200 | if (send_streams_.empty()) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 201 | return false; |
| 202 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 203 | return send_streams_[0].has_ssrcs(); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 206 | virtual void set_conference_mode(bool enable) { conference_mode_ = enable; } |
| 207 | virtual bool conference_mode() const { return conference_mode_; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 208 | |
| 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 212 | virtual void set_connection_address(const rtc::SocketAddress& address) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 213 | connection_address_ = address; |
| 214 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 215 | virtual const rtc::SocketAddress& connection_address() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 216 | return connection_address_; |
| 217 | } |
| 218 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 219 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 220 | // within the same rtp stream. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 221 | enum ExtmapAllowMixed { kNo, kSession, kMedia }; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 222 | virtual void set_extmap_allow_mixed_enum( |
| 223 | ExtmapAllowMixed new_extmap_allow_mixed) { |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 224 | if (new_extmap_allow_mixed == kMedia && |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 225 | extmap_allow_mixed_enum_ == kSession) { |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 226 | // Do not downgrade from session level to media level. |
| 227 | return; |
| 228 | } |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 229 | extmap_allow_mixed_enum_ = new_extmap_allow_mixed; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 230 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 231 | virtual ExtmapAllowMixed extmap_allow_mixed_enum() const { |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 232 | return extmap_allow_mixed_enum_; |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 233 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 234 | virtual bool extmap_allow_mixed() const { |
| 235 | return extmap_allow_mixed_enum_ != kNo; |
| 236 | } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 237 | |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 238 | // 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 249 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 257 | StreamParamsVec send_streams_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 258 | bool conference_mode_ = false; |
| 259 | webrtc::RtpTransceiverDirection direction_ = |
| 260 | webrtc::RtpTransceiverDirection::kSendRecv; |
| 261 | rtc::SocketAddress connection_address_; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 262 | // 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 Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 265 | ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo; |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 266 | |
| 267 | SimulcastDescription simulcast_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 268 | }; |
| 269 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 270 | // TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have |
| 271 | // updated. |
| 272 | using ContentDescription = MediaContentDescription; |
| 273 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 274 | template <class C> |
| 275 | class MediaContentDescriptionImpl : public MediaContentDescription { |
| 276 | public: |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 277 | void set_protocol(const std::string& protocol) override { |
| 278 | RTC_DCHECK(IsRtpProtocol(protocol)); |
| 279 | protocol_ = protocol; |
| 280 | } |
| 281 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 282 | typedef C CodecType; |
| 283 | |
| 284 | // Codecs should be in preference order (most preferred codec first). |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 285 | 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 289 | 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 299 | virtual void AddCodec(const C& codec) { codecs_.push_back(codec); } |
| 300 | virtual void AddOrReplaceCodec(const C& codec) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 301 | 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 Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 310 | virtual void AddCodecs(const std::vector<C>& codecs) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 311 | 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 | |
| 321 | class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> { |
| 322 | public: |
| 323 | AudioContentDescription() {} |
| 324 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 325 | virtual AudioContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 326 | return new AudioContentDescription(*this); |
| 327 | } |
| 328 | virtual MediaType type() const { return MEDIA_TYPE_AUDIO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 329 | virtual AudioContentDescription* as_audio() { return this; } |
| 330 | virtual const AudioContentDescription* as_audio() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> { |
| 334 | public: |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 335 | virtual VideoContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 336 | return new VideoContentDescription(*this); |
| 337 | } |
| 338 | virtual MediaType type() const { return MEDIA_TYPE_VIDEO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 339 | virtual VideoContentDescription* as_video() { return this; } |
| 340 | virtual const VideoContentDescription* as_video() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 343 | // 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 350 | class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> { |
| 351 | public: |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 352 | DataContentDescription(); |
| 353 | MediaType type() const override { return MEDIA_TYPE_DATA; } |
Harald Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 354 | 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 359 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 360 | // Override all methods defined in MediaContentDescription. |
| 361 | bool has_codecs() const override; |
| 362 | DataContentDescription* Copy() const override { |
| 363 | return new DataContentDescription(this); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 364 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 365 | 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 | |
| 447 | class 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 Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 466 | RTC_DEPRECATED DataContentDescription* as_data() override; |
| 467 | RTC_DEPRECATED const DataContentDescription* as_data() const override; |
| 468 | DataContentDescription* deprecated_as_data() override; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 469 | |
| 470 | private: |
| 471 | std::unique_ptr<DataContentDescription> shim_; |
| 472 | }; |
| 473 | |
| 474 | class 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 Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 490 | RTC_DEPRECATED DataContentDescription* as_data() override; |
| 491 | RTC_DEPRECATED const DataContentDescription* as_data() const override; |
| 492 | DataContentDescription* deprecated_as_data() override; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 493 | |
| 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 499 | |
| 500 | bool use_sctpmap() const { return use_sctpmap_; } |
| 501 | void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 502 | 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 Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 508 | |
| 509 | private: |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 510 | 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 Alvestrand | fbb45bd | 2019-05-15 08:07:47 +0200 | [diff] [blame] | 513 | // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K |
| 514 | int max_message_size_ = 64 * 1024; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 515 | std::unique_ptr<DataContentDescription> shim_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 516 | }; |
| 517 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 518 | // 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.). |
| 520 | enum 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. |
| 528 | constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp; |
| 529 | constexpr 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 Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 533 | // Owns the description. |
| 534 | class ContentInfo { |
| 535 | public: |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 536 | explicit ContentInfo(MediaProtocolType type) : type(type) {} |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 537 | ~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 Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 543 | |
| 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 Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 549 | 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 Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 558 | // TODO(bugs.webrtc.org/8620): Rename this to mid. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 559 | std::string name; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 560 | MediaProtocolType type; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 561 | bool rejected = false; |
| 562 | bool bundle_only = false; |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 563 | |
| 564 | private: |
| 565 | friend class SessionDescription; |
| 566 | std::unique_ptr<MediaContentDescription> description_; |
| 567 | |
| 568 | public: |
| 569 | // Kept for backwards compatibility only. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 570 | MediaContentDescription* description = nullptr; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 571 | }; |
| 572 | |
| 573 | typedef 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. |
| 579 | class 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 | |
| 601 | typedef std::vector<ContentInfo> ContentInfos; |
| 602 | typedef std::vector<ContentGroup> ContentGroups; |
| 603 | |
| 604 | const ContentInfo* FindContentInfoByName(const ContentInfos& contents, |
| 605 | const std::string& name); |
| 606 | const ContentInfo* FindContentInfoByType(const ContentInfos& contents, |
| 607 | const std::string& type); |
| 608 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 609 | // Determines how the MSID will be signaled in the SDP. These can be used as |
| 610 | // flags to indicate both or none. |
| 611 | enum 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 Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 618 | // 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. |
| 621 | class SessionDescription { |
| 622 | public: |
| 623 | SessionDescription(); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 624 | ~SessionDescription(); |
| 625 | |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 626 | std::unique_ptr<SessionDescription> Clone() const; |
Harald Alvestrand | 8da35a6 | 2019-05-10 09:31:04 +0200 | [diff] [blame] | 627 | // Older API - deprecated. Still expects caller to take ownership. |
| 628 | // Replace with Clone(). |
| 629 | RTC_DEPRECATED SessionDescription* Copy() const; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 630 | |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 631 | struct MediaTransportSetting; |
| 632 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 633 | // 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 Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 638 | const MediaContentDescription* GetContentDescriptionByName( |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 639 | const std::string& name) const; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 640 | MediaContentDescription* GetContentDescriptionByName(const std::string& name); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 641 | const ContentInfo* FirstContentByType(MediaProtocolType type) const; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 642 | 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 Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 647 | MediaProtocolType type, |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 648 | std::unique_ptr<MediaContentDescription> description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 649 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 650 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 651 | bool rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 652 | std::unique_ptr<MediaContentDescription> description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 653 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 654 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 655 | bool rejected, |
| 656 | bool bundle_only, |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame^] | 657 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 682 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 683 | 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 Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 701 | void AddTransportInfo(const TransportInfo& transport_info); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 702 | 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 Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 718 | // 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 Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 725 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 726 | // within the same rtp stream. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 727 | void set_extmap_allow_mixed(bool supported) { |
| 728 | extmap_allow_mixed_ = supported; |
| 729 | MediaContentDescription::ExtmapAllowMixed media_level_setting = |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 730 | supported ? MediaContentDescription::kSession |
| 731 | : MediaContentDescription::kNo; |
| 732 | for (auto& content : contents_) { |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 733 | // Do not set to kNo if the current setting is kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 734 | if (supported || content.media_description()->extmap_allow_mixed_enum() != |
| 735 | MediaContentDescription::kMedia) { |
| 736 | content.media_description()->set_extmap_allow_mixed_enum( |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 737 | media_level_setting); |
| 738 | } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 739 | } |
| 740 | } |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 741 | bool extmap_allow_mixed() const { return extmap_allow_mixed_; } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 742 | |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 743 | // 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 Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 769 | private: |
| 770 | SessionDescription(const SessionDescription&); |
| 771 | |
| 772 | ContentInfos contents_; |
| 773 | TransportInfos transport_infos_; |
| 774 | ContentGroups content_groups_; |
| 775 | bool msid_supported_ = true; |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 776 | // Default to what Plan B would do. |
| 777 | // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection. |
| 778 | int msid_signaling_ = kMsidSignalingSsrcAttribute; |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 779 | // 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 Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 784 | bool extmap_allow_mixed_ = false; |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 785 | |
| 786 | std::vector<MediaTransportSetting> media_transport_settings_; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 787 | }; |
| 788 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 789 | // Indicates whether a session description was sent by the local client or |
| 790 | // received from the remote client. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 791 | enum ContentSource { CS_LOCAL, CS_REMOTE }; |
| 792 | |
| 793 | } // namespace cricket |
| 794 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 795 | #endif // PC_SESSION_DESCRIPTION_H_ |