// BaseChannel contains logic common to voice and video, including enable, // marshaling calls to a worker and network threads, and connection and media // monitors. // // BaseChannel assumes signaling and other threads are allowed to make // synchronous calls to the worker thread, the worker thread makes synchronous // calls only to the network thread, and the network thread can't be blocked by // other threads. // All methods with _n suffix must be called on network thread, // methods with _w suffix on worker thread // and methods with _s suffix on signaling thread. // Network and worker threads may be the same thread. // class BaseChannel : public ChannelInterface, public MediaChannelNetworkInterface, public RtpPacketSinkInterface { public: // If `srtp_required` is true, the channel will not send or receive any // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP). // The BaseChannel does not own the UniqueRandomIdGenerator so it is the // responsibility of the user to ensure it outlives this object. // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists // which will make it easier to change the constructor.
// Constructor for use when the MediaChannels are split
BaseChannel(
TaskQueueBase* worker_thread,
Thread* network_thread,
TaskQueueBase* signaling_thread,
std::unique_ptr<MediaSendChannelInterface> media_send_channel,
std::unique_ptr<MediaReceiveChannelInterface> media_receive_channel,
absl::string_view mid,
MediaType media_type, bool srtp_required,
CryptoOptions crypto_options,
UniqueRandomIdGenerator* ssrc_generator,
ChannelCallbacks callbacks = {});
~BaseChannel() override;
// This function returns true if using SRTP (DTLS-based keying or SDES). bool srtp_active() const {
RTC_DCHECK_RUN_ON(network_thread()); return rtp_transport_ && rtp_transport_->IsSrtpActive();
}
// Set an RTP level transport which could be an RtpTransport without // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. // This can be called from any thread and it hops to the network thread // internally. It would replace the `SetTransports` and its variants. bool SetRtpTransport(RtpTransportInternal* rtp_transport) override;
// Call to verify that: // * The required content description directions have been set. // * The channel is enabled. // * The SRTP filter is active if it's needed. // * The transport has been writable before, meaning it should be at least // possible to succeed in sending a packet. // // When any of these properties change, UpdateMediaSendRecvState_w should be // called. bool IsReadyToSendMedia_w() const RTC_RUN_ON(worker_thread());
// NetworkInterface implementation, called by MediaEngine bool SendPacket(CopyOnWriteBuffer* packet, const AsyncSocketPacketOptions& options) override; bool SendRtcp(CopyOnWriteBuffer* packet, const AsyncSocketPacketOptions& options) override;
// From RtpTransportInternal void OnWritableState(bool writable);
// Performs actions if the RTP/RTCP writable state changed. This should // be called whenever a channel's writable state changes or when RTCP muxing // becomes active/inactive. void UpdateWritableState_n() RTC_RUN_ON(network_thread()); void ChannelWritable_n() RTC_RUN_ON(network_thread()); void ChannelNotWritable_n() RTC_RUN_ON(network_thread());
// Should be called whenever the conditions for // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). // Updates the send/recv state of the media channel. void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread());
// Returns a list of RTP header extensions where any extension URI is unique. // Encrypted extensions will be either preferred or discarded, depending on // the current crypto_options_.
RtpHeaderExtensions GetDeduplicatedRtpHeaderExtensions( const RtpHeaderExtensions& extensions);
// Returns `true` if either an update wasn't needed or one was successfully // applied. If the return value is `false`, then updating the demuxer criteria // failed, which needs to be treated as an error.
RTCError MaybeUpdateDemuxerAndRtpExtensions_w( bool update_demuxer,
std::optional<flat_set<uint8_t>> payload_types, const RtpHeaderExtensions& extensions,
std::optional<flat_set<uint32_t>> ssrcs) RTC_RUN_ON(worker_thread());
// Registers a demuxer criteria with the transport, on the network thread. // This function will fail if there's no transport of if a sink is already // registered for this channel's demuxer_critera(). bool RegisterRtpDemuxerSink_w(bool clear_payload_types,
std::optional<flat_set<uint32_t>> ssrcs)
RTC_RUN_ON(worker_thread());
// Return description of media channel to facilitate logging
std::string ToString() const;
// The functions are deleted after they have been called.
absl::AnyInvocable<void(const RtpPacketReceived&) &&>
on_first_packet_received_ RTC_GUARDED_BY(network_thread());
absl::AnyInvocable<void() &&> on_first_packet_sent_
RTC_GUARDED_BY(network_thread());
// Used to unmute.
absl::AnyInvocable<void(const RtpPacketReceived&)> on_packet_received_n_
RTC_GUARDED_BY(network_thread());
// Set to either kPreferEncryptedExtension or kDiscardEncryptedExtension // based on the supplied CryptoOptions. const RtpExtension::Filter extensions_filter_;
// Currently the `enabled_` flag is accessed from the signaling thread as // well, but it can be changed only when signaling thread does a synchronous // call to the worker thread, so it should be safe. bool enabled_ RTC_GUARDED_BY(worker_thread()) = false; bool enabled_s_ RTC_GUARDED_BY(signaling_thread()) = false;
std::vector<StreamParams> local_streams_ RTC_GUARDED_BY(worker_thread());
std::vector<StreamParams> remote_streams_ RTC_GUARDED_BY(worker_thread());
RtpTransceiverDirection local_content_direction_
RTC_GUARDED_BY(worker_thread()) = RtpTransceiverDirection::kInactive;
RtpTransceiverDirection remote_content_direction_
RTC_GUARDED_BY(worker_thread()) = RtpTransceiverDirection::kInactive;
// Cached list of payload types, used if payload type demuxing is re-enabled.
flat_set<uint8_t> payload_types_ RTC_GUARDED_BY(network_thread());
using ReceiverParamsVariant =
std::variant<AudioReceiverParameters, VideoReceiverParameters>; using SenderParamsVariant =
std::variant<AudioSenderParameter, VideoSenderParameters>;
ReceiverParamsVariant last_recv_params_;
SenderParamsVariant last_send_params_; const MediaType media_type_; // This generator is used to generate SSRCs for local streams. // This is needed in cases where SSRCs are not negotiated or set explicitly // like in Simulcast. // This object is not owned by the channel so it must outlive it.
UniqueRandomIdGenerator* const ssrc_generator_;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.