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