Skip to main content

EncodedVideoTrack

Struct EncodedVideoTrack 

Source
pub struct EncodedVideoTrack { /* private fields */ }
Expand description

A video track that accepts pre-encoded frames directly, bypassing the libwebrtc software encoder pipeline entirely.

Obtain one via [PeerConnectionFactory::create_video_track_with_options] with TrackVideoEncoder::PreEncoded, then:

  1. Attach EncodedVideoTrack::track() to a send-only transceiver.
  2. Call push_encoded_frame whenever your encoder (VideoToolbox, NVENC, GStreamer, libvpx, …) produces a frame — at your rate, on any thread.

§Timing

The WebRTC encoder thread is triggered internally each time you call push_encoded_frame, so you do not need to call push_video_frame separately. The dummy raw frame used to trigger it is cheap (pre-allocated; the I420 data is discarded by the encoder callback before it ever touches your encoded bytes).

Implementations§

Source§

impl EncodedVideoTrack

Source

pub fn on_encoder_feedback( &self, cb: impl FnMut(EncoderFeedback) + Send + 'static, )

Listen for encoder feedback for this track — EncoderFeedback::KeyFrameRequest (answer with an IDR promptly) and EncoderFeedback::RateUpdate (adapt your encoder’s target). Latest registration wins. The callback fires on WebRTC threads, like every other sink in this API.

Source

pub fn track(&self) -> &VideoTrack

The underlying video track handle — pass track() (or the VideoTrack itself) to Transceiver::set_track; it derefs to &Track.

Source

pub fn push_frame(&self, frame: EncodedVideoFrame) -> Result<()>

Inject a pre-encoded frame into the WebRTC RTP stack.

The call returns immediately; the frame is queued and forwarded to the RTP packetizer on the WebRTC encoder thread. Thread-safe — call from any thread, including a hardware encoder callback.

Set frame.width / frame.height to 0 to inherit from the track’s configured resolution — the PreEncodedOptions the track was created with.

Source

pub fn push_frame_with_metadata( &self, frame: EncodedVideoFrame, user_data: &[u8], ) -> Result<()>

Inject a pre-encoded frame with per-frame metadata embedded as a protobuf trailer.

frame_id and capture_time_us are filled in internally, the latter from time_micros; the caller supplies only user_data. A capture time cannot be declared here the way it can on a raw Track: these frames arrive already encoded and the encoder clamps future capture timestamps, which is why this path correlates its metadata by FIFO order instead. Requires sender_metadata_transform to be called and the returned FrameTransform to be attached to the sender transceiver before the first SDP exchange.

Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.