pub struct Vp8KeyframeStreamEncoder { /* private fields */ }Expand description
Multi-frame VP8 keyframe encoder driver.
One instance owns the cross-frame state of a single VP8 elementary
stream: the frame counter, the locked-after-first-frame dimensions,
and the §9 three-slot reference-frame buffer
(LAST / GOLDEN / ALTREF).
All emitted frames are key frames this round. Each successful
Self::encode_frame call:
- Validates that this frame’s dimensions match the first frame’s (or, on the first call, locks them in).
- Calls
encode_keyframe_with_reconstructionwith the driver’sKeyframeParams. - Replaces all three reference slots with a clone of the macroblock-aligned post-§15 reconstruction (§9.7 / §9.8 keyframe refresh).
- Increments the frame counter.
- Returns the emitted bytes.
Construct with Self::new and drive with Self::encode_frame.
Self::frame_count, Self::dimensions, and the per-slot
accessors Self::last, Self::golden, Self::altref
expose the running state.
Implementations§
Source§impl Vp8KeyframeStreamEncoder
impl Vp8KeyframeStreamEncoder
Sourcepub fn new(params: KeyframeParams) -> Self
pub fn new(params: KeyframeParams) -> Self
Build a fresh stream encoder configured with the supplied
per-frame KeyframeParams. Same parameters are applied to
every encoded frame in this stream.
The frame counter starts at 0 and all three reference slots
start as None. The dimensions are not locked until the first
encode_frame call.
Sourcepub fn encode_frame(
&mut self,
frame: &I420Frame<'_>,
) -> Result<Vec<u8>, StreamEncodeError>
pub fn encode_frame( &mut self, frame: &I420Frame<'_>, ) -> Result<Vec<u8>, StreamEncodeError>
Encode one frame of the stream as a VP8 key frame.
On the first call this also locks the stream’s dimensions to
frame’s visible width/height. Every subsequent call must
supply a frame with the same dimensions; a mismatch is
surfaced as StreamEncodeError::DimensionsChanged and leaves
the encoder state unchanged.
Returns the raw bytes of one VP8 elementary-stream frame
(one packet = one frame) ready to be fed to a container muxer
(e.g. IVF) or decoded directly through
crate::decode_vp8 / crate::state::Vp8DecoderState::decode_frame.
Sourcepub fn encode_frame_with_fitted_token_prob_updates(
&mut self,
frame: &I420Frame<'_>,
) -> Result<Vec<u8>, StreamEncodeError>
pub fn encode_frame_with_fitted_token_prob_updates( &mut self, frame: &I420Frame<'_>, ) -> Result<Vec<u8>, StreamEncodeError>
Encode one frame of the stream as a VP8 key frame, with an
automatically-fitted §13.4 token_prob_update() payload per
crate::encoder::encode_keyframe_with_reconstruction_and_fitted_token_prob_updates.
Drop-in fitted companion to Self::encode_frame: same K/P
scheduling rules (every emitted frame is a key frame on this
driver), same dimension-lock semantics, same §9.7 / §9.8
three-slot refresh — only the bitstream differs (the fitter is
allowed to shrink the wire by overlaying observed-counts
probabilities on the §13.5 defaults, with the round-157 fitter’s
safety guard that never grows the wire relative to the
caller-driven None baseline).
The returned bytes always decode through
crate::state::Vp8DecoderState::decode_frame and every
compliant VP8 decoder; the §9 reference-frame slots are refreshed
with the matching reconstruction (the round-157 safety-guard
fall-back returns the default-pass planes alongside the
default-pass bytes, so the slot state stays consistent with the
wire on both fitter outcomes).
Closes the round-157 / round-158 follow-up identified in
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_fitted_token_prob_updates
(“Out of round-158 scope: threading the fitter into
Vp8KeyframeStreamEncoder / Vp8InterStreamEncoder”).
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Number of frames successfully encoded so far.
Sourcepub fn dimensions(&self) -> Option<(u32, u32)>
pub fn dimensions(&self) -> Option<(u32, u32)>
Stream dimensions, locked at the first successful
encode_frame call. None before then.
Sourcepub fn last(&self) -> Option<&RefFrameSlot>
pub fn last(&self) -> Option<&RefFrameSlot>
Borrow the current LAST reference slot. None before the
first frame.
Sourcepub fn golden(&self) -> Option<&RefFrameSlot>
pub fn golden(&self) -> Option<&RefFrameSlot>
Borrow the current GOLDEN reference slot. None before the
first frame.
Sourcepub fn altref(&self) -> Option<&RefFrameSlot>
pub fn altref(&self) -> Option<&RefFrameSlot>
Borrow the current ALTREF reference slot. None before the
first frame.
Sourcepub fn params(&self) -> &KeyframeParams
pub fn params(&self) -> &KeyframeParams
Borrow the KeyframeParams applied to every frame this
stream emits.