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