pub struct Consumer { /* private fields */ }
Expand description

A consumer represents an audio or video source being forwarded from a mediasoup router to an endpoint. It’s created on top of a transport that defines how the media packets are carried.

Implementations§

source§

impl Consumer

source

pub fn id(&self) -> ConsumerId

Consumer id.

source

pub fn producer_id(&self) -> ProducerId

Associated Producer id.

source

pub fn transport(&self) -> &Arc<dyn Transport>

Transport to which consumer belongs.

source

pub fn kind(&self) -> MediaKind

Media kind.

source

pub fn rtp_parameters(&self) -> &RtpParameters

Consumer RTP parameters.

§Notes on usage

Check the RTP Parameters and Capabilities section for more details (TypeScript-oriented, but concepts apply here as well).

source

pub fn type(&self) -> ConsumerType

Consumer type.

source

pub fn paused(&self) -> bool

Whether the consumer is paused. It does not take into account whether the associated producer is paused.

source

pub fn producer_paused(&self) -> bool

Whether the associate Producer is paused.

source

pub fn priority(&self) -> u8

Consumer priority (see Consumer::set_priority method).

source

pub fn score(&self) -> ConsumerScore

The score of the RTP stream being sent, representing its transmission quality.

source

pub fn preferred_layers(&self) -> Option<ConsumerLayers>

Preferred spatial and temporal layers (see Consumer::set_preferred_layers method). For simulcast and SVC consumers, None otherwise.

source

pub fn current_layers(&self) -> Option<ConsumerLayers>

Currently active spatial and temporal layers (for Simulcast and SVC consumers only). It’s None if no layers are being sent to the consuming endpoint at this time (or if the consumer is consuming from a Simulcast or SVC producer).

source

pub fn app_data(&self) -> &AppData

Custom application data.

source

pub fn closed(&self) -> bool

Whether the consumer is closed.

source

pub async fn get_stats(&self) -> Result<ConsumerStats, RequestError>

Returns current RTC statistics of the consumer.

Check the RTC Statistics section for more details (TypeScript-oriented, but concepts apply here as well).

source

pub async fn pause(&self) -> Result<(), RequestError>

Pauses the consumer (no RTP is sent to the consuming endpoint).

source

pub async fn resume(&self) -> Result<(), RequestError>

Resumes the consumer (RTP is sent again to the consuming endpoint).

source

pub async fn set_preferred_layers( &self, consumer_layers: ConsumerLayers ) -> Result<(), RequestError>

Sets the preferred (highest) spatial and temporal layers to be sent to the consuming endpoint. Just valid for Simulcast and SVC consumers.

source

pub async fn set_priority(&self, priority: u8) -> Result<(), RequestError>

Sets the priority for this consumer. It affects how the estimated outgoing bitrate in the transport (obtained via transport-cc or REMB) is distributed among all video consumers, by prioritizing those with higher priority.

source

pub async fn unset_priority(&self) -> Result<(), RequestError>

Unsets the priority for this consumer (it sets it to its default value 1).

source

pub async fn request_key_frame(&self) -> Result<(), RequestError>

Request a key frame from associated producer. Just valid for video consumers.

source

pub async fn enable_trace_event( &self, types: Vec<ConsumerTraceEventType> ) -> Result<(), RequestError>

Instructs the consumer to emit “trace” events. For monitoring purposes. Use with caution.

source

pub fn on_rtp<F: Fn(&[u8]) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the consumer receives through its router a RTP packet from the associated producer.

§Notes on usage

Just available in direct transports, this is, those created via Router::create_direct_transport.

source

pub fn on_pause<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the consumer or its associated producer is paused and, as result, the consumer becomes paused.

source

pub fn on_resume<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the consumer or its associated producer is resumed and, as result, the consumer is no longer paused.

source

pub fn on_producer_pause<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the associated producer is paused.

source

pub fn on_producer_resume<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the associated producer is resumed.

source

pub fn on_score<F: Fn(&ConsumerScore) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the consumer score changes.

source

pub fn on_layers_change<F: Fn(&Option<ConsumerLayers>) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the spatial/temporal layers being sent to the endpoint change. Just for Simulcast or SVC consumers.

§Notes on usage

This callback is called under various circumstances in SVC or Simulcast consumers (assuming the consumer endpoints supports BWE via REMB or Transport-CC):

  • When the consumer (or its associated producer) is paused.
  • When all the RTP streams of the associated producer become inactive (no RTP received for a while).
  • When the available bitrate of the BWE makes the consumer upgrade or downgrade the spatial and/or temporal layers.
  • When there is no available bitrate for this consumer (even for the lowest layers) so the callback is called with None as argument.

The Rust application can detect the latter (consumer deactivated due to not enough bandwidth) by checking if both consumer.paused() and consumer.producer_paused() are falsy after the consumer has called this callback with None as argument.

source

pub fn on_trace<F: Fn(&ConsumerTraceEventData) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId

source

pub fn on_producer_close<F: FnOnce() + Send + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the associated producer is closed for whatever reason. The consumer itself is also closed.

source

pub fn on_transport_close<F: FnOnce() + Send + 'static>( &self, callback: F ) -> HandlerId

Callback is called when the transport this consumer belongs to is closed for whatever reason. The consumer itself is also closed.

source

pub fn on_close<F: FnOnce() + Send + 'static>(&self, callback: F) -> HandlerId

Callback is called when the consumer is closed for whatever reason.

NOTE: Callback will be called in place if consumer is already closed.

source

pub fn downgrade(&self) -> WeakConsumer

Downgrade Consumer to WeakConsumer instance.

Trait Implementations§

source§

impl Clone for Consumer

source§

fn clone(&self) -> Consumer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Consumer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.