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