henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | // Types and classes used in media session descriptions. |
| 29 | |
| 30 | #ifndef TALK_SESSION_MEDIA_MEDIASESSION_H_ |
| 31 | #define TALK_SESSION_MEDIA_MEDIASESSION_H_ |
| 32 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 33 | #include <algorithm> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include <string> |
| 35 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include "talk/media/base/codec.h" |
| 38 | #include "talk/media/base/constants.h" |
| 39 | #include "talk/media/base/cryptoparams.h" |
| 40 | #include "talk/media/base/mediachannel.h" |
| 41 | #include "talk/media/base/mediaengine.h" // For DataChannelType |
| 42 | #include "talk/media/base/streamparams.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame^] | 43 | #include "webrtc/p2p/base/sessiondescription.h" |
| 44 | #include "webrtc/p2p/base/transport.h" |
| 45 | #include "webrtc/p2p/base/transportdescriptionfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 46 | #include "webrtc/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | |
| 48 | namespace cricket { |
| 49 | |
| 50 | class ChannelManager; |
| 51 | typedef std::vector<AudioCodec> AudioCodecs; |
| 52 | typedef std::vector<VideoCodec> VideoCodecs; |
| 53 | typedef std::vector<DataCodec> DataCodecs; |
| 54 | typedef std::vector<CryptoParams> CryptoParamsVec; |
| 55 | typedef std::vector<RtpHeaderExtension> RtpHeaderExtensions; |
| 56 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | enum MediaType { |
| 58 | MEDIA_TYPE_AUDIO, |
| 59 | MEDIA_TYPE_VIDEO, |
| 60 | MEDIA_TYPE_DATA |
| 61 | }; |
| 62 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 63 | std::string MediaTypeToString(MediaType type); |
| 64 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | enum MediaContentDirection { |
| 66 | MD_INACTIVE, |
| 67 | MD_SENDONLY, |
| 68 | MD_RECVONLY, |
| 69 | MD_SENDRECV |
| 70 | }; |
| 71 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 72 | enum CryptoType { |
| 73 | CT_NONE, |
| 74 | CT_SDES, |
| 75 | CT_DTLS |
| 76 | }; |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | // RTC4585 RTP/AVPF |
| 79 | extern const char kMediaProtocolAvpf[]; |
| 80 | // RFC5124 RTP/SAVPF |
| 81 | extern const char kMediaProtocolSavpf[]; |
| 82 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 83 | extern const char kMediaProtocolDtlsSavpf[]; |
| 84 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | extern const char kMediaProtocolRtpPrefix[]; |
| 86 | |
| 87 | extern const char kMediaProtocolSctp[]; |
| 88 | extern const char kMediaProtocolDtlsSctp[]; |
| 89 | |
| 90 | // Options to control how session descriptions are generated. |
| 91 | const int kAutoBandwidth = -1; |
| 92 | const int kBufferedModeDisabled = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | |
| 94 | struct MediaSessionOptions { |
| 95 | MediaSessionOptions() : |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 96 | recv_audio(true), |
| 97 | recv_video(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | data_channel_type(DCT_NONE), |
| 99 | is_muc(false), |
| 100 | vad_enabled(true), // When disabled, removes all CN codecs from SDP. |
| 101 | rtcp_mux_enabled(true), |
| 102 | bundle_enabled(false), |
| 103 | video_bandwidth(kAutoBandwidth), |
| 104 | data_bandwidth(kDataMaxBandwidth) { |
| 105 | } |
| 106 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 107 | bool has_audio() const { |
| 108 | return recv_audio || HasSendMediaStream(MEDIA_TYPE_AUDIO); |
| 109 | } |
| 110 | bool has_video() const { |
| 111 | return recv_video || HasSendMediaStream(MEDIA_TYPE_VIDEO); |
| 112 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | bool has_data() const { return data_channel_type != DCT_NONE; } |
| 114 | |
| 115 | // Add a stream with MediaType type and id. |
| 116 | // All streams with the same sync_label will get the same CNAME. |
| 117 | // All ids must be unique. |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 118 | void AddSendStream(MediaType type, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | const std::string& id, |
| 120 | const std::string& sync_label); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 121 | void AddSendVideoStream(const std::string& id, |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 122 | const std::string& sync_label, |
| 123 | int num_sim_layers); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 124 | void RemoveSendStream(MediaType type, const std::string& id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 126 | |
| 127 | // Helper function. |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 128 | void AddSendStreamInternal(MediaType type, |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 129 | const std::string& id, |
| 130 | const std::string& sync_label, |
| 131 | int num_sim_layers); |
| 132 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 133 | bool HasSendMediaStream(MediaType type) const; |
| 134 | |
| 135 | bool recv_audio; |
| 136 | bool recv_video; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | DataChannelType data_channel_type; |
| 138 | bool is_muc; |
| 139 | bool vad_enabled; |
| 140 | bool rtcp_mux_enabled; |
| 141 | bool bundle_enabled; |
| 142 | // bps. -1 == auto. |
| 143 | int video_bandwidth; |
| 144 | int data_bandwidth; |
| 145 | TransportOptions transport_options; |
| 146 | |
| 147 | struct Stream { |
| 148 | Stream(MediaType type, |
| 149 | const std::string& id, |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 150 | const std::string& sync_label, |
| 151 | int num_sim_layers) |
| 152 | : type(type), id(id), sync_label(sync_label), |
| 153 | num_sim_layers(num_sim_layers) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 154 | } |
| 155 | MediaType type; |
| 156 | std::string id; |
| 157 | std::string sync_label; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 158 | int num_sim_layers; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | typedef std::vector<Stream> Streams; |
| 162 | Streams streams; |
| 163 | }; |
| 164 | |
| 165 | // "content" (as used in XEP-0166) descriptions for voice and video. |
| 166 | class MediaContentDescription : public ContentDescription { |
| 167 | public: |
| 168 | MediaContentDescription() |
| 169 | : rtcp_mux_(false), |
| 170 | bandwidth_(kAutoBandwidth), |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 171 | crypto_required_(CT_NONE), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | rtp_header_extensions_set_(false), |
| 173 | multistream_(false), |
| 174 | conference_mode_(false), |
| 175 | partial_(false), |
| 176 | buffered_mode_latency_(kBufferedModeDisabled), |
| 177 | direction_(MD_SENDRECV) { |
| 178 | } |
| 179 | |
| 180 | virtual MediaType type() const = 0; |
| 181 | virtual bool has_codecs() const = 0; |
| 182 | |
| 183 | // |protocol| is the expected media transport protocol, such as RTP/AVPF, |
| 184 | // RTP/SAVPF or SCTP/DTLS. |
| 185 | std::string protocol() const { return protocol_; } |
| 186 | void set_protocol(const std::string& protocol) { protocol_ = protocol; } |
| 187 | |
| 188 | MediaContentDirection direction() const { return direction_; } |
| 189 | void set_direction(MediaContentDirection direction) { |
| 190 | direction_ = direction; |
| 191 | } |
| 192 | |
| 193 | bool rtcp_mux() const { return rtcp_mux_; } |
| 194 | void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; } |
| 195 | |
| 196 | int bandwidth() const { return bandwidth_; } |
| 197 | void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; } |
| 198 | |
| 199 | const std::vector<CryptoParams>& cryptos() const { return cryptos_; } |
| 200 | void AddCrypto(const CryptoParams& params) { |
| 201 | cryptos_.push_back(params); |
| 202 | } |
| 203 | void set_cryptos(const std::vector<CryptoParams>& cryptos) { |
| 204 | cryptos_ = cryptos; |
| 205 | } |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 206 | |
| 207 | CryptoType crypto_required() const { return crypto_required_; } |
| 208 | void set_crypto_required(CryptoType type) { |
| 209 | crypto_required_ = type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | const RtpHeaderExtensions& rtp_header_extensions() const { |
| 213 | return rtp_header_extensions_; |
| 214 | } |
| 215 | void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 216 | rtp_header_extensions_ = extensions; |
| 217 | rtp_header_extensions_set_ = true; |
| 218 | } |
| 219 | void AddRtpHeaderExtension(const RtpHeaderExtension& ext) { |
| 220 | rtp_header_extensions_.push_back(ext); |
| 221 | rtp_header_extensions_set_ = true; |
| 222 | } |
| 223 | void ClearRtpHeaderExtensions() { |
| 224 | rtp_header_extensions_.clear(); |
| 225 | rtp_header_extensions_set_ = true; |
| 226 | } |
| 227 | // We can't always tell if an empty list of header extensions is |
| 228 | // because the other side doesn't support them, or just isn't hooked up to |
| 229 | // signal them. For now we assume an empty list means no signaling, but |
| 230 | // provide the ClearRtpHeaderExtensions method to allow "no support" to be |
| 231 | // clearly indicated (i.e. when derived from other information). |
| 232 | bool rtp_header_extensions_set() const { |
| 233 | return rtp_header_extensions_set_; |
| 234 | } |
| 235 | // True iff the client supports multiple streams. |
| 236 | void set_multistream(bool multistream) { multistream_ = multistream; } |
| 237 | bool multistream() const { return multistream_; } |
| 238 | const StreamParamsVec& streams() const { |
| 239 | return streams_; |
| 240 | } |
| 241 | // TODO(pthatcher): Remove this by giving mediamessage.cc access |
| 242 | // to MediaContentDescription |
| 243 | StreamParamsVec& mutable_streams() { |
| 244 | return streams_; |
| 245 | } |
| 246 | void AddStream(const StreamParams& stream) { |
| 247 | streams_.push_back(stream); |
| 248 | } |
| 249 | // Legacy streams have an ssrc, but nothing else. |
| 250 | void AddLegacyStream(uint32 ssrc) { |
| 251 | streams_.push_back(StreamParams::CreateLegacy(ssrc)); |
| 252 | } |
| 253 | void AddLegacyStream(uint32 ssrc, uint32 fid_ssrc) { |
| 254 | StreamParams sp = StreamParams::CreateLegacy(ssrc); |
| 255 | sp.AddFidSsrc(ssrc, fid_ssrc); |
| 256 | streams_.push_back(sp); |
| 257 | } |
| 258 | // Sets the CNAME of all StreamParams if it have not been set. |
| 259 | // This can be used to set the CNAME of legacy streams. |
| 260 | void SetCnameIfEmpty(const std::string& cname) { |
| 261 | for (cricket::StreamParamsVec::iterator it = streams_.begin(); |
| 262 | it != streams_.end(); ++it) { |
| 263 | if (it->cname.empty()) |
| 264 | it->cname = cname; |
| 265 | } |
| 266 | } |
| 267 | uint32 first_ssrc() const { |
| 268 | if (streams_.empty()) { |
| 269 | return 0; |
| 270 | } |
| 271 | return streams_[0].first_ssrc(); |
| 272 | } |
| 273 | bool has_ssrcs() const { |
| 274 | if (streams_.empty()) { |
| 275 | return false; |
| 276 | } |
| 277 | return streams_[0].has_ssrcs(); |
| 278 | } |
| 279 | |
| 280 | void set_conference_mode(bool enable) { conference_mode_ = enable; } |
| 281 | bool conference_mode() const { return conference_mode_; } |
| 282 | |
| 283 | void set_partial(bool partial) { partial_ = partial; } |
| 284 | bool partial() const { return partial_; } |
| 285 | |
| 286 | void set_buffered_mode_latency(int latency) { |
| 287 | buffered_mode_latency_ = latency; |
| 288 | } |
| 289 | int buffered_mode_latency() const { return buffered_mode_latency_; } |
| 290 | |
| 291 | protected: |
| 292 | bool rtcp_mux_; |
| 293 | int bandwidth_; |
| 294 | std::string protocol_; |
| 295 | std::vector<CryptoParams> cryptos_; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 296 | CryptoType crypto_required_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | std::vector<RtpHeaderExtension> rtp_header_extensions_; |
| 298 | bool rtp_header_extensions_set_; |
| 299 | bool multistream_; |
| 300 | StreamParamsVec streams_; |
| 301 | bool conference_mode_; |
| 302 | bool partial_; |
| 303 | int buffered_mode_latency_; |
| 304 | MediaContentDirection direction_; |
| 305 | }; |
| 306 | |
| 307 | template <class C> |
| 308 | class MediaContentDescriptionImpl : public MediaContentDescription { |
| 309 | public: |
| 310 | struct PreferenceSort { |
| 311 | bool operator()(C a, C b) { return a.preference > b.preference; } |
| 312 | }; |
| 313 | |
| 314 | const std::vector<C>& codecs() const { return codecs_; } |
| 315 | void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; } |
| 316 | virtual bool has_codecs() const { return !codecs_.empty(); } |
| 317 | bool HasCodec(int id) { |
| 318 | bool found = false; |
| 319 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 320 | iter != codecs_.end(); ++iter) { |
| 321 | if (iter->id == id) { |
| 322 | found = true; |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | return found; |
| 327 | } |
| 328 | void AddCodec(const C& codec) { |
| 329 | codecs_.push_back(codec); |
| 330 | } |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 331 | void AddOrReplaceCodec(const C& codec) { |
| 332 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 333 | iter != codecs_.end(); ++iter) { |
| 334 | if (iter->id == codec.id) { |
| 335 | *iter = codec; |
| 336 | return; |
| 337 | } |
| 338 | } |
| 339 | AddCodec(codec); |
| 340 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | void AddCodecs(const std::vector<C>& codecs) { |
| 342 | typename std::vector<C>::const_iterator codec; |
| 343 | for (codec = codecs.begin(); codec != codecs.end(); ++codec) { |
| 344 | AddCodec(*codec); |
| 345 | } |
| 346 | } |
| 347 | void SortCodecs() { |
| 348 | std::sort(codecs_.begin(), codecs_.end(), PreferenceSort()); |
| 349 | } |
| 350 | |
| 351 | private: |
| 352 | std::vector<C> codecs_; |
| 353 | }; |
| 354 | |
| 355 | class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> { |
| 356 | public: |
| 357 | AudioContentDescription() : |
| 358 | agc_minus_10db_(false) {} |
| 359 | |
| 360 | virtual ContentDescription* Copy() const { |
| 361 | return new AudioContentDescription(*this); |
| 362 | } |
| 363 | virtual MediaType type() const { return MEDIA_TYPE_AUDIO; } |
| 364 | |
| 365 | const std::string &lang() const { return lang_; } |
| 366 | void set_lang(const std::string &lang) { lang_ = lang; } |
| 367 | |
| 368 | bool agc_minus_10db() const { return agc_minus_10db_; } |
| 369 | void set_agc_minus_10db(bool enable) { |
| 370 | agc_minus_10db_ = enable; |
| 371 | } |
| 372 | |
| 373 | private: |
| 374 | bool agc_minus_10db_; |
| 375 | |
| 376 | private: |
| 377 | std::string lang_; |
| 378 | }; |
| 379 | |
| 380 | class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> { |
| 381 | public: |
| 382 | virtual ContentDescription* Copy() const { |
| 383 | return new VideoContentDescription(*this); |
| 384 | } |
| 385 | virtual MediaType type() const { return MEDIA_TYPE_VIDEO; } |
| 386 | }; |
| 387 | |
| 388 | class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> { |
| 389 | public: |
| 390 | virtual ContentDescription* Copy() const { |
| 391 | return new DataContentDescription(*this); |
| 392 | } |
| 393 | virtual MediaType type() const { return MEDIA_TYPE_DATA; } |
| 394 | }; |
| 395 | |
| 396 | // Creates media session descriptions according to the supplied codecs and |
| 397 | // other fields, as well as the supplied per-call options. |
| 398 | // When creating answers, performs the appropriate negotiation |
| 399 | // of the various fields to determine the proper result. |
| 400 | class MediaSessionDescriptionFactory { |
| 401 | public: |
| 402 | // Default ctor; use methods below to set configuration. |
| 403 | // The TransportDescriptionFactory is not owned by MediaSessionDescFactory, |
| 404 | // so it must be kept alive by the user of this class. |
| 405 | explicit MediaSessionDescriptionFactory( |
| 406 | const TransportDescriptionFactory* factory); |
| 407 | // This helper automatically sets up the factory to get its configuration |
| 408 | // from the specified ChannelManager. |
| 409 | MediaSessionDescriptionFactory(ChannelManager* cmanager, |
| 410 | const TransportDescriptionFactory* factory); |
| 411 | |
| 412 | const AudioCodecs& audio_codecs() const { return audio_codecs_; } |
| 413 | void set_audio_codecs(const AudioCodecs& codecs) { audio_codecs_ = codecs; } |
| 414 | void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 415 | audio_rtp_extensions_ = extensions; |
| 416 | } |
| 417 | const RtpHeaderExtensions& audio_rtp_header_extensions() const { |
| 418 | return audio_rtp_extensions_; |
| 419 | } |
| 420 | const VideoCodecs& video_codecs() const { return video_codecs_; } |
| 421 | void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; } |
| 422 | void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 423 | video_rtp_extensions_ = extensions; |
| 424 | } |
| 425 | const RtpHeaderExtensions& video_rtp_header_extensions() const { |
| 426 | return video_rtp_extensions_; |
| 427 | } |
| 428 | const DataCodecs& data_codecs() const { return data_codecs_; } |
| 429 | void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } |
| 430 | SecurePolicy secure() const { return secure_; } |
| 431 | void set_secure(SecurePolicy s) { secure_ = s; } |
| 432 | // Decides if a StreamParams shall be added to the audio and video media |
| 433 | // content in SessionDescription when CreateOffer and CreateAnswer is called |
| 434 | // even if |options| don't include a Stream. This is needed to support legacy |
| 435 | // applications. |add_legacy_| is true per default. |
| 436 | void set_add_legacy_streams(bool add_legacy) { add_legacy_ = add_legacy; } |
| 437 | |
| 438 | SessionDescription* CreateOffer( |
| 439 | const MediaSessionOptions& options, |
| 440 | const SessionDescription* current_description) const; |
| 441 | SessionDescription* CreateAnswer( |
| 442 | const SessionDescription* offer, |
| 443 | const MediaSessionOptions& options, |
| 444 | const SessionDescription* current_description) const; |
| 445 | |
| 446 | private: |
| 447 | void GetCodecsToOffer(const SessionDescription* current_description, |
| 448 | AudioCodecs* audio_codecs, |
| 449 | VideoCodecs* video_codecs, |
| 450 | DataCodecs* data_codecs) const; |
| 451 | void GetRtpHdrExtsToOffer(const SessionDescription* current_description, |
| 452 | RtpHeaderExtensions* audio_extensions, |
| 453 | RtpHeaderExtensions* video_extensions) const; |
| 454 | bool AddTransportOffer( |
| 455 | const std::string& content_name, |
| 456 | const TransportOptions& transport_options, |
| 457 | const SessionDescription* current_desc, |
| 458 | SessionDescription* offer) const; |
| 459 | |
| 460 | TransportDescription* CreateTransportAnswer( |
| 461 | const std::string& content_name, |
| 462 | const SessionDescription* offer_desc, |
| 463 | const TransportOptions& transport_options, |
| 464 | const SessionDescription* current_desc) const; |
| 465 | |
| 466 | bool AddTransportAnswer( |
| 467 | const std::string& content_name, |
| 468 | const TransportDescription& transport_desc, |
| 469 | SessionDescription* answer_desc) const; |
| 470 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 471 | // Helpers for adding media contents to the SessionDescription. Returns true |
| 472 | // it succeeds or the media content is not needed, or false if there is any |
| 473 | // error. |
| 474 | |
| 475 | bool AddAudioContentForOffer( |
| 476 | const MediaSessionOptions& options, |
| 477 | const SessionDescription* current_description, |
| 478 | const RtpHeaderExtensions& audio_rtp_extensions, |
| 479 | const AudioCodecs& audio_codecs, |
| 480 | StreamParamsVec* current_streams, |
| 481 | SessionDescription* desc) const; |
| 482 | |
| 483 | bool AddVideoContentForOffer( |
| 484 | const MediaSessionOptions& options, |
| 485 | const SessionDescription* current_description, |
| 486 | const RtpHeaderExtensions& video_rtp_extensions, |
| 487 | const VideoCodecs& video_codecs, |
| 488 | StreamParamsVec* current_streams, |
| 489 | SessionDescription* desc) const; |
| 490 | |
| 491 | bool AddDataContentForOffer( |
| 492 | const MediaSessionOptions& options, |
| 493 | const SessionDescription* current_description, |
| 494 | DataCodecs* data_codecs, |
| 495 | StreamParamsVec* current_streams, |
| 496 | SessionDescription* desc) const; |
| 497 | |
| 498 | bool AddAudioContentForAnswer( |
| 499 | const SessionDescription* offer, |
| 500 | const MediaSessionOptions& options, |
| 501 | const SessionDescription* current_description, |
| 502 | StreamParamsVec* current_streams, |
| 503 | SessionDescription* answer) const; |
| 504 | |
| 505 | bool AddVideoContentForAnswer( |
| 506 | const SessionDescription* offer, |
| 507 | const MediaSessionOptions& options, |
| 508 | const SessionDescription* current_description, |
| 509 | StreamParamsVec* current_streams, |
| 510 | SessionDescription* answer) const; |
| 511 | |
| 512 | bool AddDataContentForAnswer( |
| 513 | const SessionDescription* offer, |
| 514 | const MediaSessionOptions& options, |
| 515 | const SessionDescription* current_description, |
| 516 | StreamParamsVec* current_streams, |
| 517 | SessionDescription* answer) const; |
| 518 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | AudioCodecs audio_codecs_; |
| 520 | RtpHeaderExtensions audio_rtp_extensions_; |
| 521 | VideoCodecs video_codecs_; |
| 522 | RtpHeaderExtensions video_rtp_extensions_; |
| 523 | DataCodecs data_codecs_; |
| 524 | SecurePolicy secure_; |
| 525 | bool add_legacy_; |
| 526 | std::string lang_; |
| 527 | const TransportDescriptionFactory* transport_desc_factory_; |
| 528 | }; |
| 529 | |
| 530 | // Convenience functions. |
| 531 | bool IsMediaContent(const ContentInfo* content); |
| 532 | bool IsAudioContent(const ContentInfo* content); |
| 533 | bool IsVideoContent(const ContentInfo* content); |
| 534 | bool IsDataContent(const ContentInfo* content); |
| 535 | const ContentInfo* GetFirstAudioContent(const ContentInfos& contents); |
| 536 | const ContentInfo* GetFirstVideoContent(const ContentInfos& contents); |
| 537 | const ContentInfo* GetFirstDataContent(const ContentInfos& contents); |
| 538 | const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc); |
| 539 | const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc); |
| 540 | const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc); |
| 541 | const AudioContentDescription* GetFirstAudioContentDescription( |
| 542 | const SessionDescription* sdesc); |
| 543 | const VideoContentDescription* GetFirstVideoContentDescription( |
| 544 | const SessionDescription* sdesc); |
| 545 | const DataContentDescription* GetFirstDataContentDescription( |
| 546 | const SessionDescription* sdesc); |
| 547 | bool GetStreamBySsrc( |
| 548 | const SessionDescription* sdesc, MediaType media_type, |
| 549 | uint32 ssrc, StreamParams* stream_out); |
| 550 | bool GetStreamByIds( |
| 551 | const SessionDescription* sdesc, MediaType media_type, |
| 552 | const std::string& groupid, const std::string& id, |
| 553 | StreamParams* stream_out); |
| 554 | |
| 555 | // Functions for translating media candidate names. |
| 556 | |
| 557 | // For converting between media ICE component and G-ICE channel |
| 558 | // names. For example: |
| 559 | // "rtp" <=> 1 |
| 560 | // "rtcp" <=> 2 |
| 561 | // "video_rtp" <=> 1 |
| 562 | // "video_rtcp" <=> 2 |
| 563 | // Will not convert in the general case of arbitrary channel names, |
| 564 | // but is useful for cases where we have candidates for media |
| 565 | // channels. |
| 566 | // returns false if there is no mapping. |
| 567 | bool GetMediaChannelNameFromComponent( |
| 568 | int component, cricket::MediaType media_type, std::string* channel_name); |
| 569 | bool GetMediaComponentFromChannelName( |
| 570 | const std::string& channel_name, int* component); |
| 571 | bool GetMediaTypeFromChannelName( |
| 572 | const std::string& channel_name, cricket::MediaType* media_type); |
| 573 | |
| 574 | void GetSupportedAudioCryptoSuites(std::vector<std::string>* crypto_suites); |
| 575 | void GetSupportedVideoCryptoSuites(std::vector<std::string>* crypto_suites); |
| 576 | void GetSupportedDataCryptoSuites(std::vector<std::string>* crypto_suites); |
| 577 | void GetSupportedDefaultCryptoSuites(std::vector<std::string>* crypto_suites); |
| 578 | } // namespace cricket |
| 579 | |
| 580 | #endif // TALK_SESSION_MEDIA_MEDIASESSION_H_ |