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