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> |
| 19 | #include <vector> |
| 20 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 21 | #include "absl/memory/memory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #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 Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 30 | #include "pc/media_protocol_names.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "pc/simulcast_description.h" |
| 32 | #include "rtc_base/socket_address.h" |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 33 | |
| 34 | namespace cricket { |
| 35 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 36 | typedef std::vector<AudioCodec> AudioCodecs; |
| 37 | typedef std::vector<VideoCodec> VideoCodecs; |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 38 | typedef std::vector<RtpDataCodec> RtpDataCodecs; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 39 | typedef std::vector<CryptoParams> CryptoParamsVec; |
| 40 | typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions; |
| 41 | |
| 42 | // RTC4585 RTP/AVPF |
| 43 | extern const char kMediaProtocolAvpf[]; |
| 44 | // RFC5124 RTP/SAVPF |
| 45 | extern const char kMediaProtocolSavpf[]; |
| 46 | |
| 47 | extern const char kMediaProtocolDtlsSavpf[]; |
| 48 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 49 | |
| 50 | // Options to control how session descriptions are generated. |
| 51 | const int kAutoBandwidth = -1; |
| 52 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 53 | class AudioContentDescription; |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 54 | class VideoContentDescription; |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 55 | class DataContentDescription; |
| 56 | class RtpDataContentDescription; |
| 57 | class SctpDataContentDescription; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 58 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 59 | // Describes a session description media section. There are subclasses for each |
| 60 | // media type (audio, video, data) that will have additional information. |
| 61 | class MediaContentDescription { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 62 | public: |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 63 | MediaContentDescription() = default; |
| 64 | virtual ~MediaContentDescription() = default; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 65 | |
| 66 | virtual MediaType type() const = 0; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 67 | |
| 68 | // Try to cast this media description to an AudioContentDescription. Returns |
| 69 | // nullptr if the cast fails. |
| 70 | virtual AudioContentDescription* as_audio() { return nullptr; } |
| 71 | virtual const AudioContentDescription* as_audio() const { return nullptr; } |
| 72 | |
| 73 | // Try to cast this media description to a VideoContentDescription. Returns |
| 74 | // nullptr if the cast fails. |
| 75 | virtual VideoContentDescription* as_video() { return nullptr; } |
| 76 | virtual const VideoContentDescription* as_video() const { return nullptr; } |
| 77 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 78 | // Backwards compatible shim: Return a shim object that allows |
| 79 | // callers to ignore the distinction between RtpDataContentDescription |
| 80 | // and SctpDataContentDescription objects. |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 81 | virtual DataContentDescription* as_data() { return nullptr; } |
| 82 | virtual const DataContentDescription* as_data() const { return nullptr; } |
| 83 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 84 | virtual RtpDataContentDescription* as_rtp_data() { return nullptr; } |
| 85 | virtual const RtpDataContentDescription* as_rtp_data() const { |
| 86 | return nullptr; |
| 87 | } |
| 88 | |
| 89 | virtual SctpDataContentDescription* as_sctp() { return nullptr; } |
| 90 | virtual const SctpDataContentDescription* as_sctp() const { return nullptr; } |
| 91 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 92 | virtual bool has_codecs() const = 0; |
| 93 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 94 | virtual MediaContentDescription* Copy() const = 0; |
| 95 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 96 | // |protocol| is the expected media transport protocol, such as RTP/AVPF, |
| 97 | // RTP/SAVPF or SCTP/DTLS. |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 98 | virtual std::string protocol() const { return protocol_; } |
| 99 | virtual void set_protocol(const std::string& protocol) { |
| 100 | protocol_ = protocol; |
| 101 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 102 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 103 | virtual webrtc::RtpTransceiverDirection direction() const { |
| 104 | return direction_; |
| 105 | } |
| 106 | virtual void set_direction(webrtc::RtpTransceiverDirection direction) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 107 | direction_ = direction; |
| 108 | } |
| 109 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 110 | virtual bool rtcp_mux() const { return rtcp_mux_; } |
| 111 | virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 112 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 113 | virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; } |
| 114 | virtual void set_rtcp_reduced_size(bool reduced_size) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 115 | rtcp_reduced_size_ = reduced_size; |
| 116 | } |
| 117 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 118 | virtual int bandwidth() const { return bandwidth_; } |
| 119 | virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 120 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 121 | virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; } |
| 122 | virtual void AddCrypto(const CryptoParams& params) { |
| 123 | cryptos_.push_back(params); |
| 124 | } |
| 125 | virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 126 | cryptos_ = cryptos; |
| 127 | } |
| 128 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 129 | virtual const RtpHeaderExtensions& rtp_header_extensions() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 130 | return rtp_header_extensions_; |
| 131 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 132 | virtual void set_rtp_header_extensions( |
| 133 | const RtpHeaderExtensions& extensions) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 134 | rtp_header_extensions_ = extensions; |
| 135 | rtp_header_extensions_set_ = true; |
| 136 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 137 | virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 138 | rtp_header_extensions_.push_back(ext); |
| 139 | rtp_header_extensions_set_ = true; |
| 140 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 141 | virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 142 | webrtc::RtpExtension webrtc_extension; |
| 143 | webrtc_extension.uri = ext.uri; |
| 144 | webrtc_extension.id = ext.id; |
| 145 | rtp_header_extensions_.push_back(webrtc_extension); |
| 146 | rtp_header_extensions_set_ = true; |
| 147 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 148 | virtual void ClearRtpHeaderExtensions() { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 149 | rtp_header_extensions_.clear(); |
| 150 | rtp_header_extensions_set_ = true; |
| 151 | } |
| 152 | // We can't always tell if an empty list of header extensions is |
| 153 | // because the other side doesn't support them, or just isn't hooked up to |
| 154 | // signal them. For now we assume an empty list means no signaling, but |
| 155 | // provide the ClearRtpHeaderExtensions method to allow "no support" to be |
| 156 | // clearly indicated (i.e. when derived from other information). |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 157 | virtual bool rtp_header_extensions_set() const { |
| 158 | return rtp_header_extensions_set_; |
| 159 | } |
| 160 | virtual const StreamParamsVec& streams() const { return send_streams_; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 161 | // TODO(pthatcher): Remove this by giving mediamessage.cc access |
| 162 | // to MediaContentDescription |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 163 | virtual StreamParamsVec& mutable_streams() { return send_streams_; } |
| 164 | virtual void AddStream(const StreamParams& stream) { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 165 | send_streams_.push_back(stream); |
| 166 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 167 | // Legacy streams have an ssrc, but nothing else. |
| 168 | void AddLegacyStream(uint32_t ssrc) { |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 169 | AddStream(StreamParams::CreateLegacy(ssrc)); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 170 | } |
| 171 | void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
| 172 | StreamParams sp = StreamParams::CreateLegacy(ssrc); |
| 173 | sp.AddFidSsrc(ssrc, fid_ssrc); |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 174 | AddStream(sp); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 175 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 176 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 177 | // Sets the CNAME of all StreamParams if it have not been set. |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 178 | virtual void SetCnameIfEmpty(const std::string& cname) { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 179 | for (cricket::StreamParamsVec::iterator it = send_streams_.begin(); |
| 180 | it != send_streams_.end(); ++it) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 181 | if (it->cname.empty()) |
| 182 | it->cname = cname; |
| 183 | } |
| 184 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 185 | virtual uint32_t first_ssrc() const { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 186 | if (send_streams_.empty()) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 187 | return 0; |
| 188 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 189 | return send_streams_[0].first_ssrc(); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 190 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 191 | virtual bool has_ssrcs() const { |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 192 | if (send_streams_.empty()) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 193 | return false; |
| 194 | } |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 195 | return send_streams_[0].has_ssrcs(); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 198 | virtual void set_conference_mode(bool enable) { conference_mode_ = enable; } |
| 199 | virtual bool conference_mode() const { return conference_mode_; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 200 | |
| 201 | // https://tools.ietf.org/html/rfc4566#section-5.7 |
| 202 | // May be present at the media or session level of SDP. If present at both |
| 203 | // levels, the media-level attribute overwrites the session-level one. |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 204 | virtual void set_connection_address(const rtc::SocketAddress& address) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 205 | connection_address_ = address; |
| 206 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 207 | virtual const rtc::SocketAddress& connection_address() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 208 | return connection_address_; |
| 209 | } |
| 210 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 211 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 212 | // within the same rtp stream. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 213 | enum ExtmapAllowMixed { kNo, kSession, kMedia }; |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 214 | virtual void set_extmap_allow_mixed_enum( |
| 215 | ExtmapAllowMixed new_extmap_allow_mixed) { |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 216 | if (new_extmap_allow_mixed == kMedia && |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 217 | extmap_allow_mixed_enum_ == kSession) { |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 218 | // Do not downgrade from session level to media level. |
| 219 | return; |
| 220 | } |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 221 | extmap_allow_mixed_enum_ = new_extmap_allow_mixed; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 222 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 223 | virtual ExtmapAllowMixed extmap_allow_mixed_enum() const { |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 224 | return extmap_allow_mixed_enum_; |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 225 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 226 | virtual bool extmap_allow_mixed() const { |
| 227 | return extmap_allow_mixed_enum_ != kNo; |
| 228 | } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 229 | |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 230 | // Simulcast functionality. |
| 231 | virtual bool HasSimulcast() const { return !simulcast_.empty(); } |
| 232 | virtual SimulcastDescription& simulcast_description() { return simulcast_; } |
| 233 | virtual const SimulcastDescription& simulcast_description() const { |
| 234 | return simulcast_; |
| 235 | } |
| 236 | virtual void set_simulcast_description( |
| 237 | const SimulcastDescription& simulcast) { |
| 238 | simulcast_ = simulcast; |
| 239 | } |
| 240 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 241 | protected: |
| 242 | bool rtcp_mux_ = false; |
| 243 | bool rtcp_reduced_size_ = false; |
| 244 | int bandwidth_ = kAutoBandwidth; |
| 245 | std::string protocol_; |
| 246 | std::vector<CryptoParams> cryptos_; |
| 247 | std::vector<webrtc::RtpExtension> rtp_header_extensions_; |
| 248 | bool rtp_header_extensions_set_ = false; |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 249 | StreamParamsVec send_streams_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 250 | bool conference_mode_ = false; |
| 251 | webrtc::RtpTransceiverDirection direction_ = |
| 252 | webrtc::RtpTransceiverDirection::kSendRecv; |
| 253 | rtc::SocketAddress connection_address_; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 254 | // Mixed one- and two-byte header not included in offer on media level or |
| 255 | // session level, but we will respond that we support it. The plan is to add |
| 256 | // it to our offer on session level. See todo in SessionDescription. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 257 | ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo; |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 258 | |
| 259 | SimulcastDescription simulcast_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 260 | }; |
| 261 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 262 | // TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have |
| 263 | // updated. |
| 264 | using ContentDescription = MediaContentDescription; |
| 265 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 266 | template <class C> |
| 267 | class MediaContentDescriptionImpl : public MediaContentDescription { |
| 268 | public: |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 269 | void set_protocol(const std::string& protocol) override { |
| 270 | RTC_DCHECK(IsRtpProtocol(protocol)); |
| 271 | protocol_ = protocol; |
| 272 | } |
| 273 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 274 | typedef C CodecType; |
| 275 | |
| 276 | // Codecs should be in preference order (most preferred codec first). |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 277 | virtual const std::vector<C>& codecs() const { return codecs_; } |
| 278 | virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; } |
| 279 | bool has_codecs() const override { return !codecs_.empty(); } |
| 280 | virtual bool HasCodec(int id) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 281 | bool found = false; |
| 282 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 283 | iter != codecs_.end(); ++iter) { |
| 284 | if (iter->id == id) { |
| 285 | found = true; |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | return found; |
| 290 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 291 | virtual void AddCodec(const C& codec) { codecs_.push_back(codec); } |
| 292 | virtual void AddOrReplaceCodec(const C& codec) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 293 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 294 | iter != codecs_.end(); ++iter) { |
| 295 | if (iter->id == codec.id) { |
| 296 | *iter = codec; |
| 297 | return; |
| 298 | } |
| 299 | } |
| 300 | AddCodec(codec); |
| 301 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 302 | virtual void AddCodecs(const std::vector<C>& codecs) { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 303 | typename std::vector<C>::const_iterator codec; |
| 304 | for (codec = codecs.begin(); codec != codecs.end(); ++codec) { |
| 305 | AddCodec(*codec); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | private: |
| 310 | std::vector<C> codecs_; |
| 311 | }; |
| 312 | |
| 313 | class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> { |
| 314 | public: |
| 315 | AudioContentDescription() {} |
| 316 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 317 | virtual AudioContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 318 | return new AudioContentDescription(*this); |
| 319 | } |
| 320 | virtual MediaType type() const { return MEDIA_TYPE_AUDIO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 321 | virtual AudioContentDescription* as_audio() { return this; } |
| 322 | virtual const AudioContentDescription* as_audio() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> { |
| 326 | public: |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 327 | virtual VideoContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 328 | return new VideoContentDescription(*this); |
| 329 | } |
| 330 | virtual MediaType type() const { return MEDIA_TYPE_VIDEO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 331 | virtual VideoContentDescription* as_video() { return this; } |
| 332 | virtual const VideoContentDescription* as_video() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 333 | }; |
| 334 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 335 | // The DataContentDescription is a shim over the RtpDataContentDescription |
| 336 | // and SctpDataContentDescription classes that is used for external callers |
| 337 | // into this internal API. |
| 338 | // It is a templated derivation of MediaContentDescriptionImpl because |
| 339 | // that's what the external caller expects it to be. |
| 340 | // TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it |
| 341 | // once external callers have been updated. |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 342 | class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> { |
| 343 | public: |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 344 | DataContentDescription(); |
| 345 | MediaType type() const override { return MEDIA_TYPE_DATA; } |
| 346 | DataContentDescription* as_data() override { return this; } |
| 347 | const DataContentDescription* as_data() const override { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 348 | |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 349 | // Override all methods defined in MediaContentDescription. |
| 350 | bool has_codecs() const override; |
| 351 | DataContentDescription* Copy() const override { |
| 352 | return new DataContentDescription(this); |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 353 | } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 354 | std::string protocol() const override; |
| 355 | void set_protocol(const std::string& protocol) override; |
| 356 | webrtc::RtpTransceiverDirection direction() const override; |
| 357 | void set_direction(webrtc::RtpTransceiverDirection direction) override; |
| 358 | bool rtcp_mux() const override; |
| 359 | void set_rtcp_mux(bool mux) override; |
| 360 | bool rtcp_reduced_size() const override; |
| 361 | void set_rtcp_reduced_size(bool) override; |
| 362 | int bandwidth() const override; |
| 363 | void set_bandwidth(int bandwidth) override; |
| 364 | const std::vector<CryptoParams>& cryptos() const override; |
| 365 | void AddCrypto(const CryptoParams& params) override; |
| 366 | void set_cryptos(const std::vector<CryptoParams>& cryptos) override; |
| 367 | const RtpHeaderExtensions& rtp_header_extensions() const override; |
| 368 | void set_rtp_header_extensions( |
| 369 | const RtpHeaderExtensions& extensions) override; |
| 370 | void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) override; |
| 371 | void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) override; |
| 372 | void ClearRtpHeaderExtensions() override; |
| 373 | bool rtp_header_extensions_set() const override; |
| 374 | const StreamParamsVec& streams() const override; |
| 375 | StreamParamsVec& mutable_streams() override; |
| 376 | void AddStream(const StreamParams& stream) override; |
| 377 | void SetCnameIfEmpty(const std::string& cname) override; |
| 378 | uint32_t first_ssrc() const override; |
| 379 | bool has_ssrcs() const override; |
| 380 | void set_conference_mode(bool enable) override; |
| 381 | bool conference_mode() const override; |
| 382 | void set_connection_address(const rtc::SocketAddress& address) override; |
| 383 | const rtc::SocketAddress& connection_address() const override; |
| 384 | void set_extmap_allow_mixed_enum(ExtmapAllowMixed) override; |
| 385 | ExtmapAllowMixed extmap_allow_mixed_enum() const override; |
| 386 | bool HasSimulcast() const override; |
| 387 | SimulcastDescription& simulcast_description() override; |
| 388 | const SimulcastDescription& simulcast_description() const override; |
| 389 | void set_simulcast_description( |
| 390 | const SimulcastDescription& simulcast) override; |
| 391 | |
| 392 | // Override all methods defined in MediaContentDescriptionImpl. |
| 393 | const std::vector<CodecType>& codecs() const override; |
| 394 | void set_codecs(const std::vector<CodecType>& codecs) override; |
| 395 | bool HasCodec(int id) override; |
| 396 | void AddCodec(const CodecType& codec) override; |
| 397 | void AddOrReplaceCodec(const CodecType& codec) override; |
| 398 | void AddCodecs(const std::vector<CodecType>& codec) override; |
| 399 | |
| 400 | private: |
| 401 | typedef MediaContentDescriptionImpl<DataCodec> Super; |
| 402 | // Friend classes are allowed to create proxies for themselves. |
| 403 | friend class RtpDataContentDescription; // for constructors |
| 404 | friend class SctpDataContentDescription; |
| 405 | friend class SessionDescription; // for Unshim() |
| 406 | // Copy constructor. A copy results in an object that owns its |
| 407 | // real description, which is a copy of the original description |
| 408 | // (whether that was owned or not). |
| 409 | explicit DataContentDescription(const DataContentDescription* o); |
| 410 | |
| 411 | explicit DataContentDescription(RtpDataContentDescription*); |
| 412 | explicit DataContentDescription(SctpDataContentDescription*); |
| 413 | |
| 414 | // Exposed for internal use - new clients should not use this class. |
| 415 | RtpDataContentDescription* as_rtp_data() override; |
| 416 | SctpDataContentDescription* as_sctp() override; |
| 417 | |
| 418 | // Create a shimmed object, owned by the shim. |
| 419 | void CreateShimTarget(bool is_sctp); |
| 420 | |
| 421 | // Return the shimmed object, passing ownership if owned, and set |
| 422 | // |should_delete| to true if it was the owner. If |should_delete| |
| 423 | // is true on return, the caller should immediately delete the |
| 424 | // DataContentDescription object. |
| 425 | MediaContentDescription* Unshim(bool* should_delete); |
| 426 | |
| 427 | // Returns whether SCTP is in use. False when it's not decided. |
| 428 | bool IsSctp() const; |
| 429 | // Check function for use when caller obviously assumes RTP. |
| 430 | void EnsureIsRtp(); |
| 431 | |
| 432 | MediaContentDescription* real_description_ = nullptr; |
| 433 | std::unique_ptr<MediaContentDescription> owned_description_; |
| 434 | }; |
| 435 | |
| 436 | class RtpDataContentDescription |
| 437 | : public MediaContentDescriptionImpl<RtpDataCodec> { |
| 438 | public: |
| 439 | RtpDataContentDescription() {} |
| 440 | RtpDataContentDescription(const RtpDataContentDescription& o) |
| 441 | : MediaContentDescriptionImpl<RtpDataCodec>(o), shim_(nullptr) {} |
| 442 | RtpDataContentDescription& operator=(const RtpDataContentDescription& o) { |
| 443 | this->MediaContentDescriptionImpl<RtpDataCodec>::operator=(o); |
| 444 | // Do not copy the shim. |
| 445 | return *this; |
| 446 | } |
| 447 | |
| 448 | RtpDataContentDescription* Copy() const override { |
| 449 | return new RtpDataContentDescription(*this); |
| 450 | } |
| 451 | MediaType type() const override { return MEDIA_TYPE_DATA; } |
| 452 | RtpDataContentDescription* as_rtp_data() override { return this; } |
| 453 | const RtpDataContentDescription* as_rtp_data() const override { return this; } |
| 454 | // Shim support |
| 455 | DataContentDescription* as_data() override; |
| 456 | const DataContentDescription* as_data() const override; |
| 457 | |
| 458 | private: |
| 459 | std::unique_ptr<DataContentDescription> shim_; |
| 460 | }; |
| 461 | |
| 462 | class SctpDataContentDescription : public MediaContentDescription { |
| 463 | public: |
| 464 | SctpDataContentDescription() {} |
| 465 | SctpDataContentDescription(const SctpDataContentDescription& o) |
| 466 | : MediaContentDescription(o), |
| 467 | use_sctpmap_(o.use_sctpmap_), |
| 468 | port_(o.port_), |
| 469 | max_message_size_(o.max_message_size_), |
| 470 | shim_(nullptr) {} |
| 471 | SctpDataContentDescription* Copy() const override { |
| 472 | return new SctpDataContentDescription(*this); |
| 473 | } |
| 474 | MediaType type() const override { return MEDIA_TYPE_DATA; } |
| 475 | SctpDataContentDescription* as_sctp() override { return this; } |
| 476 | const SctpDataContentDescription* as_sctp() const override { return this; } |
| 477 | // Shim support |
| 478 | DataContentDescription* as_data() override; |
| 479 | const DataContentDescription* as_data() const override; |
| 480 | |
| 481 | bool has_codecs() const override { return false; } |
| 482 | void set_protocol(const std::string& protocol) override { |
| 483 | RTC_DCHECK(IsSctpProtocol(protocol)); |
| 484 | protocol_ = protocol; |
| 485 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 486 | |
| 487 | bool use_sctpmap() const { return use_sctpmap_; } |
| 488 | void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; } |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 489 | int port() const { return port_; } |
| 490 | void set_port(int port) { port_ = port; } |
| 491 | int max_message_size() const { return max_message_size_; } |
| 492 | void set_max_message_size(int max_message_size) { |
| 493 | max_message_size_ = max_message_size; |
| 494 | } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 495 | |
| 496 | private: |
Harald Alvestrand | 14b2758 | 2019-05-04 11:37:04 +0200 | [diff] [blame^] | 497 | bool use_sctpmap_ = true; // Note: "true" is no longer conformant. |
| 498 | // Defaults should be constants imported from SCTP. Quick hack. |
| 499 | int port_ = 5000; |
| 500 | int max_message_size_ = 256 * 1024; |
| 501 | std::unique_ptr<DataContentDescription> shim_; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 502 | }; |
| 503 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 504 | // Protocol used for encoding media. This is the "top level" protocol that may |
| 505 | // be wrapped by zero or many transport protocols (UDP, ICE, etc.). |
| 506 | enum class MediaProtocolType { |
| 507 | kRtp, // Section will use the RTP protocol (e.g., for audio or video). |
| 508 | // https://tools.ietf.org/html/rfc3550 |
| 509 | kSctp // Section will use the SCTP protocol (e.g., for a data channel). |
| 510 | // https://tools.ietf.org/html/rfc4960 |
| 511 | }; |
| 512 | |
| 513 | // TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated. |
| 514 | constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp; |
| 515 | constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp; |
| 516 | |
| 517 | // Represents a session description section. Most information about the section |
| 518 | // is stored in the description, which is a subclass of MediaContentDescription. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 519 | struct ContentInfo { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 520 | friend class SessionDescription; |
| 521 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 522 | explicit ContentInfo(MediaProtocolType type) : type(type) {} |
| 523 | |
| 524 | // Alias for |name|. |
| 525 | std::string mid() const { return name; } |
| 526 | void set_mid(const std::string& mid) { this->name = mid; } |
| 527 | |
| 528 | // Alias for |description|. |
| 529 | MediaContentDescription* media_description() { return description; } |
| 530 | const MediaContentDescription* media_description() const { |
| 531 | return description; |
| 532 | } |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 533 | void set_media_description(MediaContentDescription* desc) { |
| 534 | description = desc; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 537 | // TODO(bugs.webrtc.org/8620): Rename this to mid. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 538 | std::string name; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 539 | MediaProtocolType type; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 540 | bool rejected = false; |
| 541 | bool bundle_only = false; |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 542 | // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this |
| 543 | // private. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 544 | MediaContentDescription* description = nullptr; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 545 | }; |
| 546 | |
| 547 | typedef std::vector<std::string> ContentNames; |
| 548 | |
| 549 | // This class provides a mechanism to aggregate different media contents into a |
| 550 | // group. This group can also be shared with the peers in a pre-defined format. |
| 551 | // GroupInfo should be populated only with the |content_name| of the |
| 552 | // MediaDescription. |
| 553 | class ContentGroup { |
| 554 | public: |
| 555 | explicit ContentGroup(const std::string& semantics); |
| 556 | ContentGroup(const ContentGroup&); |
| 557 | ContentGroup(ContentGroup&&); |
| 558 | ContentGroup& operator=(const ContentGroup&); |
| 559 | ContentGroup& operator=(ContentGroup&&); |
| 560 | ~ContentGroup(); |
| 561 | |
| 562 | const std::string& semantics() const { return semantics_; } |
| 563 | const ContentNames& content_names() const { return content_names_; } |
| 564 | |
| 565 | const std::string* FirstContentName() const; |
| 566 | bool HasContentName(const std::string& content_name) const; |
| 567 | void AddContentName(const std::string& content_name); |
| 568 | bool RemoveContentName(const std::string& content_name); |
| 569 | |
| 570 | private: |
| 571 | std::string semantics_; |
| 572 | ContentNames content_names_; |
| 573 | }; |
| 574 | |
| 575 | typedef std::vector<ContentInfo> ContentInfos; |
| 576 | typedef std::vector<ContentGroup> ContentGroups; |
| 577 | |
| 578 | const ContentInfo* FindContentInfoByName(const ContentInfos& contents, |
| 579 | const std::string& name); |
| 580 | const ContentInfo* FindContentInfoByType(const ContentInfos& contents, |
| 581 | const std::string& type); |
| 582 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 583 | // Determines how the MSID will be signaled in the SDP. These can be used as |
| 584 | // flags to indicate both or none. |
| 585 | enum MsidSignaling { |
| 586 | // Signal MSID with one a=msid line in the media section. |
| 587 | kMsidSignalingMediaSection = 0x1, |
| 588 | // Signal MSID with a=ssrc: msid lines in the media section. |
| 589 | kMsidSignalingSsrcAttribute = 0x2 |
| 590 | }; |
| 591 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 592 | // Describes a collection of contents, each with its own name and |
| 593 | // type. Analogous to a <jingle> or <session> stanza. Assumes that |
| 594 | // contents are unique be name, but doesn't enforce that. |
| 595 | class SessionDescription { |
| 596 | public: |
| 597 | SessionDescription(); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 598 | ~SessionDescription(); |
| 599 | |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 600 | std::unique_ptr<SessionDescription> Clone() const; |
| 601 | // Older API - to be deprecated. Still expects caller to take ownership. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 602 | SessionDescription* Copy() const; |
| 603 | |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 604 | struct MediaTransportSetting; |
| 605 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 606 | // Content accessors. |
| 607 | const ContentInfos& contents() const { return contents_; } |
| 608 | ContentInfos& contents() { return contents_; } |
| 609 | const ContentInfo* GetContentByName(const std::string& name) const; |
| 610 | ContentInfo* GetContentByName(const std::string& name); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 611 | const MediaContentDescription* GetContentDescriptionByName( |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 612 | const std::string& name) const; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 613 | MediaContentDescription* GetContentDescriptionByName(const std::string& name); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 614 | const ContentInfo* FirstContentByType(MediaProtocolType type) const; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 615 | const ContentInfo* FirstContent() const; |
| 616 | |
| 617 | // Content mutators. |
| 618 | // Adds a content to this description. Takes ownership of ContentDescription*. |
| 619 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 620 | MediaProtocolType type, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 621 | MediaContentDescription* description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 622 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 623 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 624 | bool rejected, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 625 | MediaContentDescription* description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 626 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 627 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 628 | bool rejected, |
| 629 | bool bundle_only, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 630 | MediaContentDescription* description); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 631 | void AddContent(ContentInfo* content); |
| 632 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 633 | bool RemoveContentByName(const std::string& name); |
| 634 | |
| 635 | // Transport accessors. |
| 636 | const TransportInfos& transport_infos() const { return transport_infos_; } |
| 637 | TransportInfos& transport_infos() { return transport_infos_; } |
| 638 | const TransportInfo* GetTransportInfoByName(const std::string& name) const; |
| 639 | TransportInfo* GetTransportInfoByName(const std::string& name); |
| 640 | const TransportDescription* GetTransportDescriptionByName( |
| 641 | const std::string& name) const { |
| 642 | const TransportInfo* tinfo = GetTransportInfoByName(name); |
| 643 | return tinfo ? &tinfo->description : NULL; |
| 644 | } |
| 645 | |
| 646 | // Transport mutators. |
| 647 | void set_transport_infos(const TransportInfos& transport_infos) { |
| 648 | transport_infos_ = transport_infos; |
| 649 | } |
| 650 | // Adds a TransportInfo to this description. |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 651 | void AddTransportInfo(const TransportInfo& transport_info); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 652 | bool RemoveTransportInfoByName(const std::string& name); |
| 653 | |
| 654 | // Group accessors. |
| 655 | const ContentGroups& groups() const { return content_groups_; } |
| 656 | const ContentGroup* GetGroupByName(const std::string& name) const; |
| 657 | bool HasGroup(const std::string& name) const; |
| 658 | |
| 659 | // Group mutators. |
| 660 | void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); } |
| 661 | // Remove the first group with the same semantics specified by |name|. |
| 662 | void RemoveGroupByName(const std::string& name); |
| 663 | |
| 664 | // Global attributes. |
| 665 | void set_msid_supported(bool supported) { msid_supported_ = supported; } |
| 666 | bool msid_supported() const { return msid_supported_; } |
| 667 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 668 | // Determines how the MSIDs were/will be signaled. Flag value composed of |
| 669 | // MsidSignaling bits (see enum above). |
| 670 | void set_msid_signaling(int msid_signaling) { |
| 671 | msid_signaling_ = msid_signaling; |
| 672 | } |
| 673 | int msid_signaling() const { return msid_signaling_; } |
| 674 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 675 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 676 | // within the same rtp stream. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 677 | void set_extmap_allow_mixed(bool supported) { |
| 678 | extmap_allow_mixed_ = supported; |
| 679 | MediaContentDescription::ExtmapAllowMixed media_level_setting = |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 680 | supported ? MediaContentDescription::kSession |
| 681 | : MediaContentDescription::kNo; |
| 682 | for (auto& content : contents_) { |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 683 | // Do not set to kNo if the current setting is kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 684 | if (supported || content.media_description()->extmap_allow_mixed_enum() != |
| 685 | MediaContentDescription::kMedia) { |
| 686 | content.media_description()->set_extmap_allow_mixed_enum( |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 687 | media_level_setting); |
| 688 | } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 689 | } |
| 690 | } |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 691 | bool extmap_allow_mixed() const { return extmap_allow_mixed_; } |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 692 | |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 693 | // Adds the media transport setting. |
| 694 | // Media transport name uniquely identifies the type of media transport. |
| 695 | // The name cannot be empty, or repeated in the previously added transport |
| 696 | // settings. |
| 697 | void AddMediaTransportSetting(const std::string& media_transport_name, |
| 698 | const std::string& media_transport_setting) { |
| 699 | RTC_DCHECK(!media_transport_name.empty()); |
| 700 | for (const auto& setting : media_transport_settings_) { |
| 701 | RTC_DCHECK(media_transport_name != setting.transport_name) |
| 702 | << "MediaTransportSetting was already registered, transport_name=" |
| 703 | << setting.transport_name; |
| 704 | } |
| 705 | media_transport_settings_.push_back( |
| 706 | {media_transport_name, media_transport_setting}); |
| 707 | } |
| 708 | |
| 709 | // Gets the media transport settings, in order of preference. |
| 710 | const std::vector<MediaTransportSetting>& MediaTransportSettings() const { |
| 711 | return media_transport_settings_; |
| 712 | } |
| 713 | |
| 714 | struct MediaTransportSetting { |
| 715 | std::string transport_name; |
| 716 | std::string transport_setting; |
| 717 | }; |
| 718 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 719 | private: |
| 720 | SessionDescription(const SessionDescription&); |
| 721 | |
| 722 | ContentInfos contents_; |
| 723 | TransportInfos transport_infos_; |
| 724 | ContentGroups content_groups_; |
| 725 | bool msid_supported_ = true; |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 726 | // Default to what Plan B would do. |
| 727 | // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection. |
| 728 | int msid_signaling_ = kMsidSignalingSsrcAttribute; |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 729 | // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in |
| 730 | // offer at session level. It's currently not included in offer by default |
| 731 | // because clients prior to https://bugs.webrtc.org/9712 cannot parse this |
| 732 | // correctly. If it's included in offer to us we will respond that we support |
| 733 | // it. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 734 | bool extmap_allow_mixed_ = false; |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 11:34:26 -0800 | [diff] [blame] | 735 | |
| 736 | std::vector<MediaTransportSetting> media_transport_settings_; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 737 | }; |
| 738 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 739 | // Indicates whether a session description was sent by the local client or |
| 740 | // received from the remote client. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 741 | enum ContentSource { CS_LOCAL, CS_REMOTE }; |
| 742 | |
| 743 | } // namespace cricket |
| 744 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 745 | #endif // PC_SESSION_DESCRIPTION_H_ |