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