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