henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | // Types and classes used in media session descriptions. |
| 12 | |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 13 | #ifndef WEBRTC_PC_MEDIASESSION_H_ |
| 14 | #define WEBRTC_PC_MEDIASESSION_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 16 | #include <algorithm> |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 17 | #include <map> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 21 | #include "webrtc/api/mediatypes.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 22 | #include "webrtc/media/base/codec.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 23 | #include "webrtc/media/base/cryptoparams.h" |
| 24 | #include "webrtc/media/base/mediachannel.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 25 | #include "webrtc/media/base/mediaconstants.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 26 | #include "webrtc/media/base/mediaengine.h" // For DataChannelType |
| 27 | #include "webrtc/media/base/streamparams.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 28 | #include "webrtc/p2p/base/sessiondescription.h" |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 29 | #include "webrtc/p2p/base/jseptransport.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 30 | #include "webrtc/p2p/base/transportdescriptionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | |
| 32 | namespace cricket { |
| 33 | |
| 34 | class ChannelManager; |
| 35 | typedef std::vector<AudioCodec> AudioCodecs; |
| 36 | typedef std::vector<VideoCodec> VideoCodecs; |
| 37 | typedef std::vector<DataCodec> DataCodecs; |
| 38 | typedef std::vector<CryptoParams> CryptoParamsVec; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 39 | typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | enum MediaContentDirection { |
| 42 | MD_INACTIVE, |
| 43 | MD_SENDONLY, |
| 44 | MD_RECVONLY, |
| 45 | MD_SENDRECV |
| 46 | }; |
| 47 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 48 | std::string MediaContentDirectionToString(MediaContentDirection direction); |
| 49 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 50 | enum CryptoType { |
| 51 | CT_NONE, |
| 52 | CT_SDES, |
| 53 | CT_DTLS |
| 54 | }; |
| 55 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | // RTC4585 RTP/AVPF |
| 57 | extern const char kMediaProtocolAvpf[]; |
| 58 | // RFC5124 RTP/SAVPF |
| 59 | extern const char kMediaProtocolSavpf[]; |
| 60 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 61 | extern const char kMediaProtocolDtlsSavpf[]; |
| 62 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | extern const char kMediaProtocolRtpPrefix[]; |
| 64 | |
| 65 | extern const char kMediaProtocolSctp[]; |
| 66 | extern const char kMediaProtocolDtlsSctp[]; |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 +0000 | [diff] [blame] | 67 | extern const char kMediaProtocolUdpDtlsSctp[]; |
lally@webrtc.org | a747093 | 2015-02-24 20:19:21 +0000 | [diff] [blame] | 68 | extern const char kMediaProtocolTcpDtlsSctp[]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | |
| 70 | // Options to control how session descriptions are generated. |
| 71 | const int kAutoBandwidth = -1; |
| 72 | const int kBufferedModeDisabled = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 74 | // Default RTCP CNAME for unit tests. |
| 75 | const char kDefaultRtcpCname[] = "DefaultRtcpCname"; |
| 76 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 77 | struct RtpTransceiverDirection { |
| 78 | bool send; |
| 79 | bool recv; |
| 80 | |
| 81 | RtpTransceiverDirection(bool send, bool recv) : send(send), recv(recv) {} |
| 82 | |
| 83 | bool operator==(const RtpTransceiverDirection& o) const { |
| 84 | return send == o.send && recv == o.recv; |
| 85 | } |
| 86 | |
| 87 | bool operator!=(const RtpTransceiverDirection& o) const { |
| 88 | return !(*this == o); |
| 89 | } |
| 90 | |
| 91 | static RtpTransceiverDirection FromMediaContentDirection( |
| 92 | MediaContentDirection md); |
| 93 | |
| 94 | MediaContentDirection ToMediaContentDirection() const; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 95 | |
| 96 | RtpTransceiverDirection Reversed() const { |
| 97 | return RtpTransceiverDirection(recv, send); |
| 98 | } |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | RtpTransceiverDirection |
| 102 | NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, |
| 103 | RtpTransceiverDirection wants); |
| 104 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 105 | // Options for an RtpSender contained with an media description/"m=" section. |
| 106 | struct SenderOptions { |
| 107 | std::string track_id; |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 108 | // TODO(steveanton): As part of work towards Unified Plan, this has been |
| 109 | // changed to be a vector. But for now this can only have exactly one. |
| 110 | std::vector<std::string> stream_ids; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 111 | int num_sim_layers; |
| 112 | }; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 113 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 114 | // Options for an individual media description/"m=" section. |
| 115 | struct MediaDescriptionOptions { |
| 116 | MediaDescriptionOptions(MediaType type, |
| 117 | const std::string& mid, |
| 118 | RtpTransceiverDirection direction, |
| 119 | bool stopped) |
| 120 | : type(type), mid(mid), direction(direction), stopped(stopped) {} |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 121 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 122 | // TODO(deadbeef): When we don't support Plan B, there will only be one |
| 123 | // sender per media description and this can be simplified. |
| 124 | void AddAudioSender(const std::string& track_id, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 125 | const std::vector<std::string>& stream_ids); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 126 | void AddVideoSender(const std::string& track_id, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 127 | const std::vector<std::string>& stream_ids, |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 128 | int num_sim_layers); |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 129 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 130 | // Internally just uses sender_options. |
| 131 | void AddRtpDataChannel(const std::string& track_id, |
| 132 | const std::string& stream_id); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 133 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 134 | MediaType type; |
| 135 | std::string mid; |
| 136 | RtpTransceiverDirection direction; |
| 137 | bool stopped; |
| 138 | TransportOptions transport_options; |
| 139 | // Note: There's no equivalent "RtpReceiverOptions" because only send |
| 140 | // stream information goes in the local descriptions. |
| 141 | std::vector<SenderOptions> sender_options; |
| 142 | |
| 143 | private: |
| 144 | // Doesn't DCHECK on |type|. |
| 145 | void AddSenderInternal(const std::string& track_id, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 146 | const std::vector<std::string>& stream_ids, |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 147 | int num_sim_layers); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 148 | }; |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 149 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 150 | // Provides a mechanism for describing how m= sections should be generated. |
| 151 | // The m= section with index X will use media_description_options[X]. There |
| 152 | // must be an option for each existing section if creating an answer, or a |
| 153 | // subsequent offer. |
| 154 | struct MediaSessionOptions { |
| 155 | MediaSessionOptions() {} |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 156 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 157 | bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); } |
| 158 | bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); } |
| 159 | bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); } |
| 160 | |
| 161 | bool HasMediaDescription(MediaType type) const; |
| 162 | |
| 163 | DataChannelType data_channel_type = DCT_NONE; |
| 164 | bool is_muc = false; |
| 165 | bool vad_enabled = true; // When disabled, removes all CN codecs from SDP. |
| 166 | bool rtcp_mux_enabled = true; |
| 167 | bool bundle_enabled = false; |
| 168 | std::string rtcp_cname = kDefaultRtcpCname; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 169 | rtc::CryptoOptions crypto_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 170 | // List of media description options in the same order that the media |
| 171 | // descriptions will be generated. |
| 172 | std::vector<MediaDescriptionOptions> media_description_options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | // "content" (as used in XEP-0166) descriptions for voice and video. |
| 176 | class MediaContentDescription : public ContentDescription { |
| 177 | public: |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 178 | MediaContentDescription() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 179 | |
| 180 | virtual MediaType type() const = 0; |
| 181 | virtual bool has_codecs() const = 0; |
| 182 | |
| 183 | // |protocol| is the expected media transport protocol, such as RTP/AVPF, |
| 184 | // RTP/SAVPF or SCTP/DTLS. |
| 185 | std::string protocol() const { return protocol_; } |
| 186 | void set_protocol(const std::string& protocol) { protocol_ = protocol; } |
| 187 | |
| 188 | MediaContentDirection direction() const { return direction_; } |
| 189 | void set_direction(MediaContentDirection direction) { |
| 190 | direction_ = direction; |
| 191 | } |
| 192 | |
| 193 | bool rtcp_mux() const { return rtcp_mux_; } |
| 194 | void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; } |
| 195 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 196 | bool rtcp_reduced_size() const { return rtcp_reduced_size_; } |
| 197 | void set_rtcp_reduced_size(bool reduced_size) { |
| 198 | rtcp_reduced_size_ = reduced_size; |
| 199 | } |
| 200 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | int bandwidth() const { return bandwidth_; } |
| 202 | void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; } |
| 203 | |
| 204 | const std::vector<CryptoParams>& cryptos() const { return cryptos_; } |
| 205 | void AddCrypto(const CryptoParams& params) { |
| 206 | cryptos_.push_back(params); |
| 207 | } |
| 208 | void set_cryptos(const std::vector<CryptoParams>& cryptos) { |
| 209 | cryptos_ = cryptos; |
| 210 | } |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 211 | |
| 212 | CryptoType crypto_required() const { return crypto_required_; } |
| 213 | void set_crypto_required(CryptoType type) { |
| 214 | crypto_required_ = type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | const RtpHeaderExtensions& rtp_header_extensions() const { |
| 218 | return rtp_header_extensions_; |
| 219 | } |
| 220 | void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 221 | rtp_header_extensions_ = extensions; |
| 222 | rtp_header_extensions_set_ = true; |
| 223 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 224 | void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | rtp_header_extensions_.push_back(ext); |
| 226 | rtp_header_extensions_set_ = true; |
| 227 | } |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 228 | void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) { |
| 229 | webrtc::RtpExtension webrtc_extension; |
| 230 | webrtc_extension.uri = ext.uri; |
| 231 | webrtc_extension.id = ext.id; |
| 232 | rtp_header_extensions_.push_back(webrtc_extension); |
| 233 | rtp_header_extensions_set_ = true; |
| 234 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 235 | void ClearRtpHeaderExtensions() { |
| 236 | rtp_header_extensions_.clear(); |
| 237 | rtp_header_extensions_set_ = true; |
| 238 | } |
| 239 | // We can't always tell if an empty list of header extensions is |
| 240 | // because the other side doesn't support them, or just isn't hooked up to |
| 241 | // signal them. For now we assume an empty list means no signaling, but |
| 242 | // provide the ClearRtpHeaderExtensions method to allow "no support" to be |
| 243 | // clearly indicated (i.e. when derived from other information). |
| 244 | bool rtp_header_extensions_set() const { |
| 245 | return rtp_header_extensions_set_; |
| 246 | } |
| 247 | // True iff the client supports multiple streams. |
| 248 | void set_multistream(bool multistream) { multistream_ = multistream; } |
| 249 | bool multistream() const { return multistream_; } |
| 250 | const StreamParamsVec& streams() const { |
| 251 | return streams_; |
| 252 | } |
| 253 | // TODO(pthatcher): Remove this by giving mediamessage.cc access |
| 254 | // to MediaContentDescription |
| 255 | StreamParamsVec& mutable_streams() { |
| 256 | return streams_; |
| 257 | } |
| 258 | void AddStream(const StreamParams& stream) { |
| 259 | streams_.push_back(stream); |
| 260 | } |
| 261 | // Legacy streams have an ssrc, but nothing else. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 262 | void AddLegacyStream(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 263 | streams_.push_back(StreamParams::CreateLegacy(ssrc)); |
| 264 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 265 | void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | StreamParams sp = StreamParams::CreateLegacy(ssrc); |
| 267 | sp.AddFidSsrc(ssrc, fid_ssrc); |
| 268 | streams_.push_back(sp); |
| 269 | } |
| 270 | // Sets the CNAME of all StreamParams if it have not been set. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | void SetCnameIfEmpty(const std::string& cname) { |
| 272 | for (cricket::StreamParamsVec::iterator it = streams_.begin(); |
| 273 | it != streams_.end(); ++it) { |
| 274 | if (it->cname.empty()) |
| 275 | it->cname = cname; |
| 276 | } |
| 277 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 278 | uint32_t first_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 279 | if (streams_.empty()) { |
| 280 | return 0; |
| 281 | } |
| 282 | return streams_[0].first_ssrc(); |
| 283 | } |
| 284 | bool has_ssrcs() const { |
| 285 | if (streams_.empty()) { |
| 286 | return false; |
| 287 | } |
| 288 | return streams_[0].has_ssrcs(); |
| 289 | } |
| 290 | |
| 291 | void set_conference_mode(bool enable) { conference_mode_ = enable; } |
| 292 | bool conference_mode() const { return conference_mode_; } |
| 293 | |
| 294 | void set_partial(bool partial) { partial_ = partial; } |
| 295 | bool partial() const { return partial_; } |
| 296 | |
| 297 | void set_buffered_mode_latency(int latency) { |
| 298 | buffered_mode_latency_ = latency; |
| 299 | } |
| 300 | int buffered_mode_latency() const { return buffered_mode_latency_; } |
| 301 | |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 302 | // https://tools.ietf.org/html/rfc4566#section-5.7 |
| 303 | // May be present at the media or session level of SDP. If present at both |
| 304 | // levels, the media-level attribute overwrites the session-level one. |
| 305 | void set_connection_address(const rtc::SocketAddress& address) { |
| 306 | connection_address_ = address; |
| 307 | } |
| 308 | const rtc::SocketAddress& connection_address() const { |
| 309 | return connection_address_; |
| 310 | } |
| 311 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | protected: |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 313 | bool rtcp_mux_ = false; |
| 314 | bool rtcp_reduced_size_ = false; |
| 315 | int bandwidth_ = kAutoBandwidth; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | std::string protocol_; |
| 317 | std::vector<CryptoParams> cryptos_; |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 318 | CryptoType crypto_required_ = CT_NONE; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 319 | std::vector<webrtc::RtpExtension> rtp_header_extensions_; |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 320 | bool rtp_header_extensions_set_ = false; |
| 321 | bool multistream_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 322 | StreamParamsVec streams_; |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 323 | bool conference_mode_ = false; |
| 324 | bool partial_ = false; |
| 325 | int buffered_mode_latency_ = kBufferedModeDisabled; |
| 326 | MediaContentDirection direction_ = MD_SENDRECV; |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 327 | rtc::SocketAddress connection_address_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | template <class C> |
| 331 | class MediaContentDescriptionImpl : public MediaContentDescription { |
| 332 | public: |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 333 | typedef C CodecType; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 334 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 335 | // Codecs should be in preference order (most preferred codec first). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | const std::vector<C>& codecs() const { return codecs_; } |
| 337 | void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; } |
| 338 | virtual bool has_codecs() const { return !codecs_.empty(); } |
| 339 | bool HasCodec(int id) { |
| 340 | bool found = false; |
| 341 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 342 | iter != codecs_.end(); ++iter) { |
| 343 | if (iter->id == id) { |
| 344 | found = true; |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | return found; |
| 349 | } |
| 350 | void AddCodec(const C& codec) { |
| 351 | codecs_.push_back(codec); |
| 352 | } |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 353 | void AddOrReplaceCodec(const C& codec) { |
| 354 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 355 | iter != codecs_.end(); ++iter) { |
| 356 | if (iter->id == codec.id) { |
| 357 | *iter = codec; |
| 358 | return; |
| 359 | } |
| 360 | } |
| 361 | AddCodec(codec); |
| 362 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | void AddCodecs(const std::vector<C>& codecs) { |
| 364 | typename std::vector<C>::const_iterator codec; |
| 365 | for (codec = codecs.begin(); codec != codecs.end(); ++codec) { |
| 366 | AddCodec(*codec); |
| 367 | } |
| 368 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 369 | |
| 370 | private: |
| 371 | std::vector<C> codecs_; |
| 372 | }; |
| 373 | |
| 374 | class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> { |
| 375 | public: |
| 376 | AudioContentDescription() : |
| 377 | agc_minus_10db_(false) {} |
| 378 | |
| 379 | virtual ContentDescription* Copy() const { |
| 380 | return new AudioContentDescription(*this); |
| 381 | } |
| 382 | virtual MediaType type() const { return MEDIA_TYPE_AUDIO; } |
| 383 | |
| 384 | const std::string &lang() const { return lang_; } |
| 385 | void set_lang(const std::string &lang) { lang_ = lang; } |
| 386 | |
| 387 | bool agc_minus_10db() const { return agc_minus_10db_; } |
| 388 | void set_agc_minus_10db(bool enable) { |
| 389 | agc_minus_10db_ = enable; |
| 390 | } |
| 391 | |
| 392 | private: |
| 393 | bool agc_minus_10db_; |
| 394 | |
| 395 | private: |
| 396 | std::string lang_; |
| 397 | }; |
| 398 | |
| 399 | class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> { |
| 400 | public: |
| 401 | virtual ContentDescription* Copy() const { |
| 402 | return new VideoContentDescription(*this); |
| 403 | } |
| 404 | virtual MediaType type() const { return MEDIA_TYPE_VIDEO; } |
| 405 | }; |
| 406 | |
| 407 | class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> { |
| 408 | public: |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 409 | DataContentDescription() {} |
| 410 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 411 | virtual ContentDescription* Copy() const { |
| 412 | return new DataContentDescription(*this); |
| 413 | } |
| 414 | virtual MediaType type() const { return MEDIA_TYPE_DATA; } |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 415 | |
| 416 | bool use_sctpmap() const { return use_sctpmap_; } |
| 417 | void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; } |
| 418 | |
| 419 | private: |
| 420 | bool use_sctpmap_ = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | // Creates media session descriptions according to the supplied codecs and |
| 424 | // other fields, as well as the supplied per-call options. |
| 425 | // When creating answers, performs the appropriate negotiation |
| 426 | // of the various fields to determine the proper result. |
| 427 | class MediaSessionDescriptionFactory { |
| 428 | public: |
| 429 | // Default ctor; use methods below to set configuration. |
| 430 | // The TransportDescriptionFactory is not owned by MediaSessionDescFactory, |
| 431 | // so it must be kept alive by the user of this class. |
| 432 | explicit MediaSessionDescriptionFactory( |
| 433 | const TransportDescriptionFactory* factory); |
| 434 | // This helper automatically sets up the factory to get its configuration |
| 435 | // from the specified ChannelManager. |
| 436 | MediaSessionDescriptionFactory(ChannelManager* cmanager, |
| 437 | const TransportDescriptionFactory* factory); |
| 438 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 439 | const AudioCodecs& audio_sendrecv_codecs() const; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 440 | const AudioCodecs& audio_send_codecs() const; |
| 441 | const AudioCodecs& audio_recv_codecs() const; |
| 442 | void set_audio_codecs(const AudioCodecs& send_codecs, |
| 443 | const AudioCodecs& recv_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 445 | audio_rtp_extensions_ = extensions; |
| 446 | } |
| 447 | const RtpHeaderExtensions& audio_rtp_header_extensions() const { |
| 448 | return audio_rtp_extensions_; |
| 449 | } |
| 450 | const VideoCodecs& video_codecs() const { return video_codecs_; } |
| 451 | void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; } |
| 452 | void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 453 | video_rtp_extensions_ = extensions; |
| 454 | } |
| 455 | const RtpHeaderExtensions& video_rtp_header_extensions() const { |
| 456 | return video_rtp_extensions_; |
| 457 | } |
| 458 | const DataCodecs& data_codecs() const { return data_codecs_; } |
| 459 | void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } |
| 460 | SecurePolicy secure() const { return secure_; } |
| 461 | void set_secure(SecurePolicy s) { secure_ = s; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 463 | void set_enable_encrypted_rtp_header_extensions(bool enable) { |
| 464 | enable_encrypted_rtp_header_extensions_ = enable; |
| 465 | } |
| 466 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | SessionDescription* CreateOffer( |
| 468 | const MediaSessionOptions& options, |
| 469 | const SessionDescription* current_description) const; |
| 470 | SessionDescription* CreateAnswer( |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 471 | const SessionDescription* offer, |
| 472 | const MediaSessionOptions& options, |
| 473 | const SessionDescription* current_description) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 474 | |
| 475 | private: |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 476 | const AudioCodecs& GetAudioCodecsForOffer( |
| 477 | const RtpTransceiverDirection& direction) const; |
| 478 | const AudioCodecs& GetAudioCodecsForAnswer( |
| 479 | const RtpTransceiverDirection& offer, |
| 480 | const RtpTransceiverDirection& answer) const; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 481 | void GetCodecsForOffer(const SessionDescription* current_description, |
| 482 | AudioCodecs* audio_codecs, |
| 483 | VideoCodecs* video_codecs, |
| 484 | DataCodecs* data_codecs) const; |
| 485 | void GetCodecsForAnswer(const SessionDescription* current_description, |
| 486 | const SessionDescription* remote_offer, |
| 487 | AudioCodecs* audio_codecs, |
| 488 | VideoCodecs* video_codecs, |
| 489 | DataCodecs* data_codecs) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | void GetRtpHdrExtsToOffer(const SessionDescription* current_description, |
| 491 | RtpHeaderExtensions* audio_extensions, |
| 492 | RtpHeaderExtensions* video_extensions) const; |
| 493 | bool AddTransportOffer( |
| 494 | const std::string& content_name, |
| 495 | const TransportOptions& transport_options, |
| 496 | const SessionDescription* current_desc, |
| 497 | SessionDescription* offer) const; |
| 498 | |
| 499 | TransportDescription* CreateTransportAnswer( |
| 500 | const std::string& content_name, |
| 501 | const SessionDescription* offer_desc, |
| 502 | const TransportOptions& transport_options, |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 503 | const SessionDescription* current_desc, |
| 504 | bool require_transport_attributes) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | |
| 506 | bool AddTransportAnswer( |
| 507 | const std::string& content_name, |
| 508 | const TransportDescription& transport_desc, |
| 509 | SessionDescription* answer_desc) const; |
| 510 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 511 | // Helpers for adding media contents to the SessionDescription. Returns true |
| 512 | // it succeeds or the media content is not needed, or false if there is any |
| 513 | // error. |
| 514 | |
| 515 | bool AddAudioContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 516 | const MediaDescriptionOptions& media_description_options, |
| 517 | const MediaSessionOptions& session_options, |
| 518 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 519 | const SessionDescription* current_description, |
| 520 | const RtpHeaderExtensions& audio_rtp_extensions, |
| 521 | const AudioCodecs& audio_codecs, |
| 522 | StreamParamsVec* current_streams, |
| 523 | SessionDescription* desc) const; |
| 524 | |
| 525 | bool AddVideoContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 526 | const MediaDescriptionOptions& media_description_options, |
| 527 | const MediaSessionOptions& session_options, |
| 528 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 529 | const SessionDescription* current_description, |
| 530 | const RtpHeaderExtensions& video_rtp_extensions, |
| 531 | const VideoCodecs& video_codecs, |
| 532 | StreamParamsVec* current_streams, |
| 533 | SessionDescription* desc) const; |
| 534 | |
| 535 | bool AddDataContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 536 | const MediaDescriptionOptions& media_description_options, |
| 537 | const MediaSessionOptions& session_options, |
| 538 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 539 | const SessionDescription* current_description, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 540 | const DataCodecs& data_codecs, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 541 | StreamParamsVec* current_streams, |
| 542 | SessionDescription* desc) const; |
| 543 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 544 | bool AddAudioContentForAnswer( |
| 545 | const MediaDescriptionOptions& media_description_options, |
| 546 | const MediaSessionOptions& session_options, |
| 547 | const ContentInfo* offer_content, |
| 548 | const SessionDescription* offer_description, |
| 549 | const ContentInfo* current_content, |
| 550 | const SessionDescription* current_description, |
| 551 | const TransportInfo* bundle_transport, |
| 552 | const AudioCodecs& audio_codecs, |
| 553 | StreamParamsVec* current_streams, |
| 554 | SessionDescription* answer) const; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 555 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 556 | bool AddVideoContentForAnswer( |
| 557 | const MediaDescriptionOptions& media_description_options, |
| 558 | const MediaSessionOptions& session_options, |
| 559 | const ContentInfo* offer_content, |
| 560 | const SessionDescription* offer_description, |
| 561 | const ContentInfo* current_content, |
| 562 | const SessionDescription* current_description, |
| 563 | const TransportInfo* bundle_transport, |
| 564 | const VideoCodecs& video_codecs, |
| 565 | StreamParamsVec* current_streams, |
| 566 | SessionDescription* answer) const; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 567 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 568 | bool AddDataContentForAnswer( |
| 569 | const MediaDescriptionOptions& media_description_options, |
| 570 | const MediaSessionOptions& session_options, |
| 571 | const ContentInfo* offer_content, |
| 572 | const SessionDescription* offer_description, |
| 573 | const ContentInfo* current_content, |
| 574 | const SessionDescription* current_description, |
| 575 | const TransportInfo* bundle_transport, |
| 576 | const DataCodecs& data_codecs, |
| 577 | StreamParamsVec* current_streams, |
| 578 | SessionDescription* answer) const; |
| 579 | |
| 580 | void ComputeAudioCodecsIntersectionAndUnion(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 581 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 582 | AudioCodecs audio_send_codecs_; |
| 583 | AudioCodecs audio_recv_codecs_; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 584 | // Intersection of send and recv. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 585 | AudioCodecs audio_sendrecv_codecs_; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 586 | // Union of send and recv. |
| 587 | AudioCodecs all_audio_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | RtpHeaderExtensions audio_rtp_extensions_; |
| 589 | VideoCodecs video_codecs_; |
| 590 | RtpHeaderExtensions video_rtp_extensions_; |
| 591 | DataCodecs data_codecs_; |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 592 | bool enable_encrypted_rtp_header_extensions_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 593 | // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter |
| 594 | // and setter. |
| 595 | SecurePolicy secure_ = SEC_DISABLED; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 596 | std::string lang_; |
| 597 | const TransportDescriptionFactory* transport_desc_factory_; |
| 598 | }; |
| 599 | |
| 600 | // Convenience functions. |
| 601 | bool IsMediaContent(const ContentInfo* content); |
| 602 | bool IsAudioContent(const ContentInfo* content); |
| 603 | bool IsVideoContent(const ContentInfo* content); |
| 604 | bool IsDataContent(const ContentInfo* content); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 605 | const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, |
| 606 | MediaType media_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 607 | const ContentInfo* GetFirstAudioContent(const ContentInfos& contents); |
| 608 | const ContentInfo* GetFirstVideoContent(const ContentInfos& contents); |
| 609 | const ContentInfo* GetFirstDataContent(const ContentInfos& contents); |
| 610 | const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc); |
| 611 | const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc); |
| 612 | const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc); |
| 613 | const AudioContentDescription* GetFirstAudioContentDescription( |
| 614 | const SessionDescription* sdesc); |
| 615 | const VideoContentDescription* GetFirstVideoContentDescription( |
| 616 | const SessionDescription* sdesc); |
| 617 | const DataContentDescription* GetFirstDataContentDescription( |
| 618 | const SessionDescription* sdesc); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 619 | // Non-const versions of the above functions. |
| 620 | // Useful when modifying an existing description. |
| 621 | ContentInfo* GetFirstMediaContent(ContentInfos& contents, MediaType media_type); |
| 622 | ContentInfo* GetFirstAudioContent(ContentInfos& contents); |
| 623 | ContentInfo* GetFirstVideoContent(ContentInfos& contents); |
| 624 | ContentInfo* GetFirstDataContent(ContentInfos& contents); |
| 625 | ContentInfo* GetFirstAudioContent(SessionDescription* sdesc); |
| 626 | ContentInfo* GetFirstVideoContent(SessionDescription* sdesc); |
| 627 | ContentInfo* GetFirstDataContent(SessionDescription* sdesc); |
| 628 | AudioContentDescription* GetFirstAudioContentDescription( |
| 629 | SessionDescription* sdesc); |
| 630 | VideoContentDescription* GetFirstVideoContentDescription( |
| 631 | SessionDescription* sdesc); |
| 632 | DataContentDescription* GetFirstDataContentDescription( |
| 633 | SessionDescription* sdesc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 634 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 635 | // Helper functions to return crypto suites used for SDES. |
| 636 | void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 637 | std::vector<int>* crypto_suites); |
| 638 | void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 639 | std::vector<int>* crypto_suites); |
| 640 | void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 641 | std::vector<int>* crypto_suites); |
| 642 | void GetSupportedAudioSdesCryptoSuiteNames( |
| 643 | const rtc::CryptoOptions& crypto_options, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 644 | std::vector<std::string>* crypto_suite_names); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 645 | void GetSupportedVideoSdesCryptoSuiteNames( |
| 646 | const rtc::CryptoOptions& crypto_options, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 647 | std::vector<std::string>* crypto_suite_names); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 648 | void GetSupportedDataSdesCryptoSuiteNames( |
| 649 | const rtc::CryptoOptions& crypto_options, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 650 | std::vector<std::string>* crypto_suite_names); |
| 651 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | } // namespace cricket |
| 653 | |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 654 | #endif // WEBRTC_PC_MEDIASESSION_H_ |