| 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. |
| 9 | */ |
| 10 |
| 11 | // Types and classes used in media session descriptions. |
| 12 |
| 13 | #ifndef PC_MEDIA_SESSION_H_ |
| 14 | #define PC_MEDIA_SESSION_H_ |
| 15 |
| 16 | #include <map> |
| 17 | #include <memory> |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 |
| 21 | #include "api/crypto/crypto_options.h" |
| 22 | #include "api/field_trials_view.h" |
| 23 | #include "api/media_types.h" |
| 24 | #include "api/rtp_parameters.h" |
| 25 | #include "api/rtp_transceiver_direction.h" |
| 26 | #include "media/base/media_constants.h" |
| 27 | #include "media/base/rid_description.h" |
| 28 | #include "media/base/stream_params.h" |
| 29 | #include "p2p/base/ice_credentials_iterator.h" |
| 30 | #include "p2p/base/transport_description.h" |
| 31 | #include "p2p/base/transport_description_factory.h" |
| 32 | #include "p2p/base/transport_info.h" |
| 33 | #include "pc/jsep_transport.h" |
| 34 | #include "pc/media_protocol_names.h" |
| 35 | #include "pc/session_description.h" |
| 36 | #include "pc/simulcast_description.h" |
| 37 | #include "rtc_base/memory/always_valid_pointer.h" |
| 38 | #include "rtc_base/unique_id_generator.h" |
| 39 |
| 40 | namespace webrtc { |
| 41 |
| 42 | // Forward declaration due to circular dependecy. |
| 43 | class ConnectionContext; |
| 44 |
| 45 | } // namespace webrtc |
| 46 |
| 47 | namespace cricket { |
| 48 |
| 49 | class ChannelManager; |
| 50 | class MediaEngineInterface; |
| 51 |
| 52 | // Default RTCP CNAME for unit tests. |
| 53 | const char kDefaultRtcpCname[] = "DefaultRtcpCname"; |
| 54 |
| 55 | // Options for an RtpSender contained with an media description/"m=" section. |
| 56 | // Note: Spec-compliant Simulcast and legacy simulcast are mutually exclusive. |
| 57 | struct SenderOptions { |
| 58 | std::string track_id; |
| 59 | std::vector<std::string> stream_ids; |
| 60 | // Use RIDs and Simulcast Layers to indicate spec-compliant Simulcast. |
| 61 | std::vector<RidDescription> rids; |
| 62 | SimulcastLayerList simulcast_layers; |
| 63 | // Use `num_sim_layers` to indicate legacy simulcast. |
| 64 | int num_sim_layers; |
| 65 | }; |
| 66 |
| 67 | // Options for an individual media description/"m=" section. |
| 68 | struct MediaDescriptionOptions { |
| 69 | MediaDescriptionOptions(MediaType type, |
| 70 | const std::string& mid, |
| 71 | webrtc::RtpTransceiverDirection direction, |
| 72 | bool stopped) |
| 73 | : type(type), mid(mid), direction(direction), stopped(stopped) {} |
| 74 |
| 75 | // TODO(deadbeef): When we don't support Plan B, there will only be one |
| 76 | // sender per media description and this can be simplified. |
| 77 | void AddAudioSender(const std::string& track_id, |
| 78 | const std::vector<std::string>& stream_ids); |
| 79 | void AddVideoSender(const std::string& track_id, |
| 80 | const std::vector<std::string>& stream_ids, |
| 81 | const std::vector<RidDescription>& rids, |
| 82 | const SimulcastLayerList& simulcast_layers, |
| 83 | int num_sim_layers); |
| 84 |
| 85 | MediaType type; |
| 86 | std::string mid; |
| 87 | webrtc::RtpTransceiverDirection direction; |
| 88 | bool stopped; |
| 89 | TransportOptions transport_options; |
| 90 | // Note: There's no equivalent "RtpReceiverOptions" because only send |
| 91 | // stream information goes in the local descriptions. |
| 92 | std::vector<SenderOptions> sender_options; |
| 93 | std::vector<webrtc::RtpCodecCapability> codec_preferences; |
| 94 | std::vector<webrtc::RtpHeaderExtensionCapability> header_extensions; |
| 95 |
| 96 | private: |
| 97 | // Doesn't DCHECK on `type`. |
| 98 | void AddSenderInternal(const std::string& track_id, |
| 99 | const std::vector<std::string>& stream_ids, |
| 100 | const std::vector<RidDescription>& rids, |
| 101 | const SimulcastLayerList& simulcast_layers, |
| 102 | int num_sim_layers); |
| 103 | }; |
| 104 |
| 105 | // Provides a mechanism for describing how m= sections should be generated. |
| 106 | // The m= section with index X will use media_description_options[X]. There |
| 107 | // must be an option for each existing section if creating an answer, or a |
| 108 | // subsequent offer. |
| 109 | struct MediaSessionOptions { |
| 110 | MediaSessionOptions() {} |
| 111 |
| 112 | bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); } |
| 113 | bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); } |
| 114 | bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); } |
| 115 |
| 116 | bool HasMediaDescription(MediaType type) const; |
| 117 |
| 118 | bool vad_enabled = true; // When disabled, removes all CN codecs from SDP. |
| 119 | bool rtcp_mux_enabled = true; |
| 120 | bool bundle_enabled = false; |
| 121 | bool offer_extmap_allow_mixed = false; |
| 122 | bool raw_packetization_for_video = false; |
| 123 | std::string rtcp_cname = kDefaultRtcpCname; |
| 124 | webrtc::CryptoOptions crypto_options; |
| 125 | // List of media description options in the same order that the media |
| 126 | // descriptions will be generated. |
| 127 | std::vector<MediaDescriptionOptions> media_description_options; |
| 128 | std::vector<IceParameters> pooled_ice_credentials; |
| 129 |
| 130 | // Use the draft-ietf-mmusic-sctp-sdp-03 obsolete syntax for SCTP |
| 131 | // datachannels. |
| 132 | // Default is true for backwards compatibility with clients that use |
| 133 | // this internal interface. |
| 134 | bool use_obsolete_sctp_sdp = true; |
| 135 | }; |
| 136 |
| 137 | // Creates media session descriptions according to the supplied codecs and |
| 138 | // other fields, as well as the supplied per-call options. |
| 139 | // When creating answers, performs the appropriate negotiation |
| 140 | // of the various fields to determine the proper result. |
| 141 | class MediaSessionDescriptionFactory { |
| 142 | public: |
| 143 | // Simple constructor that does not set any configuration for the factory. |
| 144 | // When using this constructor, the methods below can be used to set the |
| 145 | // configuration. |
| 146 | // The TransportDescriptionFactory and the UniqueRandomIdGenerator are not |
| 147 | // owned by MediaSessionDescriptionFactory, so they must be kept alive by the |
| 148 | // user of this class. |
| 149 | MediaSessionDescriptionFactory(const TransportDescriptionFactory* factory, |
| 150 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
| 151 | // This helper automatically sets up the factory to get its configuration |
| 152 | // from the specified MediaEngine |
| 153 | MediaSessionDescriptionFactory(cricket::MediaEngineInterface* media_engine, |
| 154 | bool rtx_enabled, |
| 155 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
| 156 | const TransportDescriptionFactory* factory); |
| 157 |
| 158 | const AudioCodecs& audio_sendrecv_codecs() const; |
| 159 | const AudioCodecs& audio_send_codecs() const; |
| 160 | const AudioCodecs& audio_recv_codecs() const; |
| 161 | void set_audio_codecs(const AudioCodecs& send_codecs, |
| 162 | const AudioCodecs& recv_codecs); |
| 163 | const VideoCodecs& video_sendrecv_codecs() const; |
| 164 | const VideoCodecs& video_send_codecs() const; |
| 165 | const VideoCodecs& video_recv_codecs() const; |
| 166 | void set_video_codecs(const VideoCodecs& send_codecs, |
| 167 | const VideoCodecs& recv_codecs); |
| 168 | RtpHeaderExtensions filtered_rtp_header_extensions( |
| 169 | RtpHeaderExtensions extensions) const; |
| 170 | SecurePolicy secure() const { return secure_; } |
| 171 | void set_secure(SecurePolicy s) { secure_ = s; } |
| 172 |
| 173 | void set_enable_encrypted_rtp_header_extensions(bool enable) { |
| 174 | enable_encrypted_rtp_header_extensions_ = enable; |
| 175 | } |
| 176 |
| 177 | void set_is_unified_plan(bool is_unified_plan) { |
| 178 | is_unified_plan_ = is_unified_plan; |
| 179 | } |
| 180 |
| 181 | std::unique_ptr<SessionDescription> CreateOffer( |
| 182 | const MediaSessionOptions& options, |
| 183 | const SessionDescription* current_description) const; |
| 184 | std::unique_ptr<SessionDescription> CreateAnswer( |
| 185 | const SessionDescription* offer, |
| 186 | const MediaSessionOptions& options, |
| 187 | const SessionDescription* current_description) const; |
| 188 |
| 189 | private: |
| 190 | struct AudioVideoRtpHeaderExtensions { |
| 191 | RtpHeaderExtensions audio; |
| 192 | RtpHeaderExtensions video; |
| 193 | }; |
| 194 |
| 195 | const AudioCodecs& GetAudioCodecsForOffer( |
| 196 | const webrtc::RtpTransceiverDirection& direction) const; |
| 197 | const AudioCodecs& GetAudioCodecsForAnswer( |
| 198 | const webrtc::RtpTransceiverDirection& offer, |
| 199 | const webrtc::RtpTransceiverDirection& answer) const; |
| 200 | const VideoCodecs& GetVideoCodecsForOffer( |
| 201 | const webrtc::RtpTransceiverDirection& direction) const; |
| 202 | const VideoCodecs& GetVideoCodecsForAnswer( |
| 203 | const webrtc::RtpTransceiverDirection& offer, |
| 204 | const webrtc::RtpTransceiverDirection& answer) const; |
| 205 | void GetCodecsForOffer( |
| 206 | const std::vector<const ContentInfo*>& current_active_contents, |
| 207 | AudioCodecs* audio_codecs, |
| 208 | VideoCodecs* video_codecs) const; |
| 209 | void GetCodecsForAnswer( |
| 210 | const std::vector<const ContentInfo*>& current_active_contents, |
| 211 | const SessionDescription& remote_offer, |
| 212 | AudioCodecs* audio_codecs, |
| 213 | VideoCodecs* video_codecs) const; |
| 214 | AudioVideoRtpHeaderExtensions GetOfferedRtpHeaderExtensionsWithIds( |
| 215 | const std::vector<const ContentInfo*>& current_active_contents, |
| 216 | bool extmap_allow_mixed, |
| 217 | const std::vector<MediaDescriptionOptions>& media_description_options) |
| 218 | const; |
| 219 | bool AddTransportOffer(const std::string& content_name, |
| 220 | const TransportOptions& transport_options, |
| 221 | const SessionDescription* current_desc, |
| 222 | SessionDescription* offer, |
| 223 | IceCredentialsIterator* ice_credentials) const; |
| 224 |
| 225 | std::unique_ptr<TransportDescription> CreateTransportAnswer( |
| 226 | const std::string& content_name, |
| 227 | const SessionDescription* offer_desc, |
| 228 | const TransportOptions& transport_options, |
| 229 | const SessionDescription* current_desc, |
| 230 | bool require_transport_attributes, |
| 231 | IceCredentialsIterator* ice_credentials) const; |
| 232 |
| 233 | bool AddTransportAnswer(const std::string& content_name, |
| 234 | const TransportDescription& transport_desc, |
| 235 | SessionDescription* answer_desc) const; |
| 236 |
| 237 | // Helpers for adding media contents to the SessionDescription. Returns true |
| 238 | // it succeeds or the media content is not needed, or false if there is any |
| 239 | // error. |
| 240 |
| 241 | bool AddAudioContentForOffer( |
| 242 | const MediaDescriptionOptions& media_description_options, |
| 243 | const MediaSessionOptions& session_options, |
| 244 | const ContentInfo* current_content, |
| 245 | const SessionDescription* current_description, |
| 246 | const RtpHeaderExtensions& audio_rtp_extensions, |
| 247 | const AudioCodecs& audio_codecs, |
| 248 | StreamParamsVec* current_streams, |
| 249 | SessionDescription* desc, |
| 250 | IceCredentialsIterator* ice_credentials) const; |
| 251 |
| 252 | bool AddVideoContentForOffer( |
| 253 | const MediaDescriptionOptions& media_description_options, |
| 254 | const MediaSessionOptions& session_options, |
| 255 | const ContentInfo* current_content, |
| 256 | const SessionDescription* current_description, |
| 257 | const RtpHeaderExtensions& video_rtp_extensions, |
| 258 | const VideoCodecs& video_codecs, |
| 259 | StreamParamsVec* current_streams, |
| 260 | SessionDescription* desc, |
| 261 | IceCredentialsIterator* ice_credentials) const; |
| 262 |
| 263 | bool AddDataContentForOffer( |
| 264 | const MediaDescriptionOptions& media_description_options, |
| 265 | const MediaSessionOptions& session_options, |
| 266 | const ContentInfo* current_content, |
| 267 | const SessionDescription* current_description, |
| 268 | StreamParamsVec* current_streams, |
| 269 | SessionDescription* desc, |
| 270 | IceCredentialsIterator* ice_credentials) const; |
| 271 |
| 272 | bool AddUnsupportedContentForOffer( |
| 273 | const MediaDescriptionOptions& media_description_options, |
| 274 | const MediaSessionOptions& session_options, |
| 275 | const ContentInfo* current_content, |
| 276 | const SessionDescription* current_description, |
| 277 | SessionDescription* desc, |
| 278 | IceCredentialsIterator* ice_credentials) const; |
| 279 |
| 280 | bool AddAudioContentForAnswer( |
| 281 | const MediaDescriptionOptions& media_description_options, |
| 282 | const MediaSessionOptions& session_options, |
| 283 | const ContentInfo* offer_content, |
| 284 | const SessionDescription* offer_description, |
| 285 | const ContentInfo* current_content, |
| 286 | const SessionDescription* current_description, |
| 287 | const TransportInfo* bundle_transport, |
| 288 | const AudioCodecs& audio_codecs, |
| 289 | const RtpHeaderExtensions& default_audio_rtp_header_extensions, |
| 290 | StreamParamsVec* current_streams, |
| 291 | SessionDescription* answer, |
| 292 | IceCredentialsIterator* ice_credentials) const; |
| 293 |
| 294 | bool AddVideoContentForAnswer( |
| 295 | const MediaDescriptionOptions& media_description_options, |
| 296 | const MediaSessionOptions& session_options, |
| 297 | const ContentInfo* offer_content, |
| 298 | const SessionDescription* offer_description, |
| 299 | const ContentInfo* current_content, |
| 300 | const SessionDescription* current_description, |
| 301 | const TransportInfo* bundle_transport, |
| 302 | const VideoCodecs& video_codecs, |
| 303 | const RtpHeaderExtensions& default_video_rtp_header_extensions, |
| 304 | StreamParamsVec* current_streams, |
| 305 | SessionDescription* answer, |
| 306 | IceCredentialsIterator* ice_credentials) const; |
| 307 |
| 308 | bool AddDataContentForAnswer( |
| 309 | const MediaDescriptionOptions& media_description_options, |
| 310 | const MediaSessionOptions& session_options, |
| 311 | const ContentInfo* offer_content, |
| 312 | const SessionDescription* offer_description, |
| 313 | const ContentInfo* current_content, |
| 314 | const SessionDescription* current_description, |
| 315 | const TransportInfo* bundle_transport, |
| 316 | StreamParamsVec* current_streams, |
| 317 | SessionDescription* answer, |
| 318 | IceCredentialsIterator* ice_credentials) const; |
| 319 |
| 320 | bool AddUnsupportedContentForAnswer( |
| 321 | const MediaDescriptionOptions& media_description_options, |
| 322 | const MediaSessionOptions& session_options, |
| 323 | const ContentInfo* offer_content, |
| 324 | const SessionDescription* offer_description, |
| 325 | const ContentInfo* current_content, |
| 326 | const SessionDescription* current_description, |
| 327 | const TransportInfo* bundle_transport, |
| 328 | SessionDescription* answer, |
| 329 | IceCredentialsIterator* ice_credentials) const; |
| 330 |
| 331 | void ComputeAudioCodecsIntersectionAndUnion(); |
| 332 |
| 333 | void ComputeVideoCodecsIntersectionAndUnion(); |
| 334 |
| 335 | rtc::UniqueRandomIdGenerator* ssrc_generator() const { |
| 336 | return ssrc_generator_.get(); |
| 337 | } |
| 338 |
| 339 | bool is_unified_plan_ = false; |
| 340 | AudioCodecs audio_send_codecs_; |
| 341 | AudioCodecs audio_recv_codecs_; |
| 342 | // Intersection of send and recv. |
| 343 | AudioCodecs audio_sendrecv_codecs_; |
| 344 | // Union of send and recv. |
| 345 | AudioCodecs all_audio_codecs_; |
| 346 | VideoCodecs video_send_codecs_; |
| 347 | VideoCodecs video_recv_codecs_; |
| 348 | // Intersection of send and recv. |
| 349 | VideoCodecs video_sendrecv_codecs_; |
| 350 | // Union of send and recv. |
| 351 | VideoCodecs all_video_codecs_; |
| 352 | // This object may or may not be owned by this class. |
| 353 | webrtc::AlwaysValidPointer<rtc::UniqueRandomIdGenerator> const |
| 354 | ssrc_generator_; |
| 355 | bool enable_encrypted_rtp_header_extensions_ = false; |
| 356 | // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter |
| 357 | // and setter. |
| 358 | SecurePolicy secure_ = SEC_DISABLED; |
| 359 | const TransportDescriptionFactory* transport_desc_factory_; |
| 360 | }; |
| 361 |
| 362 | // Convenience functions. |
| 363 | bool IsMediaContent(const ContentInfo* content); |
| 364 | bool IsAudioContent(const ContentInfo* content); |
| 365 | bool IsVideoContent(const ContentInfo* content); |
| 366 | bool IsDataContent(const ContentInfo* content); |
| 367 | bool IsUnsupportedContent(const ContentInfo* content); |
| 368 | const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, |
| 369 | MediaType media_type); |
| 370 | const ContentInfo* GetFirstAudioContent(const ContentInfos& contents); |
| 371 | const ContentInfo* GetFirstVideoContent(const ContentInfos& contents); |
| 372 | const ContentInfo* GetFirstDataContent(const ContentInfos& contents); |
| 373 | const ContentInfo* GetFirstMediaContent(const SessionDescription* sdesc, |
| 374 | MediaType media_type); |
| 375 | const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc); |
| 376 | const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc); |
| 377 | const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc); |
| 378 | const AudioContentDescription* GetFirstAudioContentDescription( |
| 379 | const SessionDescription* sdesc); |
| 380 | const VideoContentDescription* GetFirstVideoContentDescription( |
| 381 | const SessionDescription* sdesc); |
| 382 | const SctpDataContentDescription* GetFirstSctpDataContentDescription( |
| 383 | const SessionDescription* sdesc); |
| 384 | // Non-const versions of the above functions. |
| 385 | // Useful when modifying an existing description. |
| 386 | ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type); |
| 387 | ContentInfo* GetFirstAudioContent(ContentInfos* contents); |
| 388 | ContentInfo* GetFirstVideoContent(ContentInfos* contents); |
| 389 | ContentInfo* GetFirstDataContent(ContentInfos* contents); |
| 390 | ContentInfo* GetFirstMediaContent(SessionDescription* sdesc, |
| 391 | MediaType media_type); |
| 392 | ContentInfo* GetFirstAudioContent(SessionDescription* sdesc); |
| 393 | ContentInfo* GetFirstVideoContent(SessionDescription* sdesc); |
| 394 | ContentInfo* GetFirstDataContent(SessionDescription* sdesc); |
| 395 | AudioContentDescription* GetFirstAudioContentDescription( |
| 396 | SessionDescription* sdesc); |
| 397 | VideoContentDescription* GetFirstVideoContentDescription( |
| 398 | SessionDescription* sdesc); |
| 399 | SctpDataContentDescription* GetFirstSctpDataContentDescription( |
| 400 | SessionDescription* sdesc); |
| 401 |
| 402 | // Helper functions to return crypto suites used for SDES. |
| 403 | void GetSupportedAudioSdesCryptoSuites( |
| 404 | const webrtc::CryptoOptions& crypto_options, |
| 405 | std::vector<int>* crypto_suites); |
| 406 | void GetSupportedVideoSdesCryptoSuites( |
| 407 | const webrtc::CryptoOptions& crypto_options, |
| 408 | std::vector<int>* crypto_suites); |
| 409 | void GetSupportedDataSdesCryptoSuites( |
| 410 | const webrtc::CryptoOptions& crypto_options, |
| 411 | std::vector<int>* crypto_suites); |
| 412 | void GetSupportedAudioSdesCryptoSuiteNames( |
| 413 | const webrtc::CryptoOptions& crypto_options, |
| 414 | std::vector<std::string>* crypto_suite_names); |
| 415 | void GetSupportedVideoSdesCryptoSuiteNames( |
| 416 | const webrtc::CryptoOptions& crypto_options, |
| 417 | std::vector<std::string>* crypto_suite_names); |
| 418 | void GetSupportedDataSdesCryptoSuiteNames( |
| 419 | const webrtc::CryptoOptions& crypto_options, |
| 420 | std::vector<std::string>* crypto_suite_names); |
| 421 |
| 422 | } // namespace cricket |
| 423 |
| 424 | #endif // PC_MEDIA_SESSION_H_ |
| 425 |