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:
- Attach
EncodedVideoTrack::track()to a send-only transceiver. - Call
push_encoded_framewhenever 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
impl EncodedVideoTrack
Sourcepub fn on_encoder_feedback(
&self,
cb: impl FnMut(EncoderFeedback) + Send + 'static,
)
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.
Sourcepub fn track(&self) -> &VideoTrack
pub fn track(&self) -> &VideoTrack
The underlying video track handle — pass track() (or the
VideoTrack itself) to
Transceiver::set_track; it derefs to
&Track.
Sourcepub fn push_frame(&self, frame: EncodedVideoFrame) -> Result<()>
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.
Sourcepub fn push_frame_with_metadata(
&self,
frame: EncodedVideoFrame,
user_data: &[u8],
) -> Result<()>
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.