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
impl Consumer
sourcepub fn id(&self) -> ConsumerId
pub fn id(&self) -> ConsumerId
Consumer id.
sourcepub fn producer_id(&self) -> ProducerId
pub fn producer_id(&self) -> ProducerId
Associated Producer id.
sourcepub fn rtp_parameters(&self) -> &RtpParameters
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).
sourcepub fn type(&self) -> ConsumerType
pub fn type(&self) -> ConsumerType
Consumer type.
sourcepub fn paused(&self) -> bool
pub fn paused(&self) -> bool
Whether the consumer is paused. It does not take into account whether the associated producer is paused.
sourcepub fn producer_paused(&self) -> bool
pub fn producer_paused(&self) -> bool
Whether the associate Producer is paused.
sourcepub fn priority(&self) -> u8
pub fn priority(&self) -> u8
Consumer priority (see Consumer::set_priority
method).
sourcepub fn score(&self) -> ConsumerScore
pub fn score(&self) -> ConsumerScore
The score of the RTP stream being sent, representing its transmission quality.
sourcepub fn preferred_layers(&self) -> Option<ConsumerLayers>
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.
sourcepub fn current_layers(&self) -> Option<ConsumerLayers>
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).
sourcepub async fn get_stats(&self) -> Result<ConsumerStats, RequestError>
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).
sourcepub async fn pause(&self) -> Result<(), RequestError>
pub async fn pause(&self) -> Result<(), RequestError>
Pauses the consumer (no RTP is sent to the consuming endpoint).
sourcepub async fn resume(&self) -> Result<(), RequestError>
pub async fn resume(&self) -> Result<(), RequestError>
Resumes the consumer (RTP is sent again to the consuming endpoint).
sourcepub async fn set_preferred_layers(
&self,
consumer_layers: ConsumerLayers
) -> Result<(), RequestError>
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.
sourcepub async fn set_priority(&self, priority: u8) -> Result<(), RequestError>
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.
sourcepub async fn unset_priority(&self) -> Result<(), RequestError>
pub async fn unset_priority(&self) -> Result<(), RequestError>
Unsets the priority for this consumer (it sets it to its default value 1
).
sourcepub async fn request_key_frame(&self) -> Result<(), RequestError>
pub async fn request_key_frame(&self) -> Result<(), RequestError>
Request a key frame from associated producer. Just valid for video consumers.
sourcepub async fn enable_trace_event(
&self,
types: Vec<ConsumerTraceEventType>
) -> Result<(), RequestError>
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.
sourcepub fn on_rtp<F: Fn(&[u8]) + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
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
.
sourcepub fn on_pause<F: Fn() + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
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.
sourcepub fn on_resume<F: Fn() + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
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.
sourcepub fn on_producer_pause<F: Fn() + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
pub fn on_producer_pause<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId
Callback is called when the associated producer is paused.
sourcepub fn on_producer_resume<F: Fn() + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
pub fn on_producer_resume<F: Fn() + Send + Sync + 'static>( &self, callback: F ) -> HandlerId
Callback is called when the associated producer is resumed.
sourcepub fn on_score<F: Fn(&ConsumerScore) + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
pub fn on_score<F: Fn(&ConsumerScore) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId
Callback is called when the consumer score changes.
sourcepub fn on_layers_change<F: Fn(&Option<ConsumerLayers>) + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
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.
sourcepub fn on_trace<F: Fn(&ConsumerTraceEventData) + Send + Sync + 'static>(
&self,
callback: F
) -> HandlerId
pub fn on_trace<F: Fn(&ConsumerTraceEventData) + Send + Sync + 'static>( &self, callback: F ) -> HandlerId
See Consumer::enable_trace_event
method.
sourcepub fn on_producer_close<F: FnOnce() + Send + 'static>(
&self,
callback: F
) -> HandlerId
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.
sourcepub fn on_transport_close<F: FnOnce() + Send + 'static>(
&self,
callback: F
) -> HandlerId
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.
sourcepub fn on_close<F: FnOnce() + Send + 'static>(&self, callback: F) -> HandlerId
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.
sourcepub fn downgrade(&self) -> WeakConsumer
pub fn downgrade(&self) -> WeakConsumer
Downgrade Consumer
to WeakConsumer
instance.