pub struct Vp8InterStreamEncoder { /* private fields */ }Expand description
Multi-frame VP8 I + P stream encoder.
One instance drives a sequence of source I420 pictures into a VP8 elementary stream of alternating key frames and ZERO_MV P-frames, owning every piece of cross-frame state the §9 / §16 layers need:
- the frame counter,
- the locked-after-first-frame visible dimensions,
- the §9 three-slot reference-frame buffer
(
LAST/GOLDEN/ALTREF), - the keyframe scheduling parameters (interval + per-call override).
§Scheduling
The encoder picks K or P per frame using two inputs:
- A non-zero
keyframe_intervalconfigured at construction — everykeyframe_intervalth frame (0, K, 2K, 3K, …) is a key frame, the rest are ZERO_MV P-frames. - A per-call
force_keyframeflag onSelf::encode_frame_with_force— set totrue, the next emitted frame is a key frame regardless of the interval, and the interval re-anchors to the forced index.
The first frame fed into a fresh encoder is always a key
frame — there is no prior reference to predict from, matching
crate::state::Vp8DecoderState’s rejection of an interframe with
no prior key frame.
§Reference-slot lifecycle
After every successful encode_frame call the three reference
slots are updated to match what
crate::state::Vp8DecoderState::decode_frame would do for the
just-emitted frame:
- Key frame (§9.7 / §9.8) — all three slots are replaced with a clone of the post-§15 reconstruction.
- ZERO_MV P-frame (§9.7) —
refresh_last = 1only, so the LAST slot is replaced with the post-§15 reconstruction; GOLDEN and ALTREF are left untouched.
This mirrors the underlying [encode_p_frame_zero_mv] refresh
ladder one-for-one.
§Per-frame self-decode invariant
Every emitted frame’s bytes are decodable through
crate::state::Vp8DecoderState::decode_frame, and a sequence of
frames replays into the same per-frame pictures the encoder was
fed (to within the §14 quantiser distortion). The
encoder_inter_stream.rs integration test pins this on a synthetic
10-frame I420 sequence at keyframe interval 4, requiring per-frame
PSNR ≥ 30 dB at a mid quantiser.
§Scope (this round)
- Every P-frame is ZERO_MV from LAST — no motion search, no NEARESTMV / NEARMV / NEWMV / SPLITMV, no GOLDEN / ALTREF selection. Quality on natural content beyond slow translation is bounded by the §14 quantiser absorbing the residual.
- The §9.5 partition count is whatever the caller put in
KeyframeParams::nbr_of_dct_partitionsfor K-frames; P-frames stay single-partition this round (the underlying [encode_p_frame_zero_mv] hardwires 1). - Mid-stream resize is rejected with
StreamEncodeError::DimensionsChanged.
Implementations§
Source§impl Vp8InterStreamEncoder
impl Vp8InterStreamEncoder
Sourcepub fn new(params: KeyframeParams, keyframe_interval: u64) -> Option<Self>
pub fn new(params: KeyframeParams, keyframe_interval: u64) -> Option<Self>
Build a fresh I + P stream encoder.
keyframe_interval controls automatic keyframe scheduling:
1— every frame is a key frame (degenerates to the keyframe-only driver).N > 1— frames 0, N, 2N, 3N, … are key frames; frames in between are ZERO_MV P-frames.0— rejected; the keyframe interval must be at least 1 or the encoder would never emit a key frame.
Returns None for keyframe_interval == 0 to make the bad
configuration impossible-by-construction at the call site.
Sourcepub fn with_golden_interval(self, golden_interval: u64) -> Self
pub fn with_golden_interval(self, golden_interval: u64) -> Self
Set the automatic §9.7 refresh_golden_frame cadence (builder
style) and return the modified encoder.
With golden_interval = N > 0, the scheduler-driven
Self::encode_frame / Self::encode_frame_with_force path
sets refresh_golden_frame = 1 on every N-th P-frame measured
from the most-recent key frame (i.e. the N-th, 2N-th, …
P-frame after each key frame). On those frames the current
reconstruction is written into the encoder’s GOLDEN slot exactly
as the decoder will write its own — the §16.2 inter MBs of later
P-frames can then predict off a recent GOLDEN instead of one
frozen at the last key frame.
golden_interval = 0 (the default after Self::new) disables
the automatic refresh and reproduces the historical
refresh_last-only auto path byte-for-byte. Callers that want
full manual control over the §9.7 / §9.8 ladder keep using the
encode_p_frame_with_refresh* family, which is unaffected.
Sourcepub fn golden_interval(&self) -> u64
pub fn golden_interval(&self) -> u64
The configured automatic §9.7 golden-refresh cadence (0 =
disabled). See Self::with_golden_interval.
Sourcepub fn next_p_frame_refreshes_golden(&self) -> bool
pub fn next_p_frame_refreshes_golden(&self) -> bool
Whether the next scheduler-driven P-frame would set
refresh_golden_frame = 1 under the configured
Self::golden_interval, without encoding anything.
Always false when the automatic cadence is disabled
(golden_interval == 0) or when the next frame is a key frame
(key frames refresh every slot regardless). Otherwise true
exactly when this would be the N-th, 2N-th, … P-frame after
the last key frame.
Sourcepub fn next_frame_is_keyframe(&self) -> FrameKind
pub fn next_frame_is_keyframe(&self) -> FrameKind
Decide whether the next Self::encode_frame call would emit
a key frame, given the current frame index and the last forced
keyframe anchor — without actually encoding anything.
Useful for a caller that wants to pre-roll metadata (IVF keyframe markers, container random-access entries) before handing the frame in. The decision is:
FrameKind::Keyif no frame has been encoded yet (first frame must be a key frame), or ifframe_count - last_keyframe_index >= keyframe_interval.FrameKind::InterZeroMvotherwise.
Sourcepub fn encode_frame(
&mut self,
frame: &I420Frame<'_>,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame( &mut self, frame: &I420Frame<'_>, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame of the stream using the configured keyframe interval to pick K vs P.
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 emitted bytes wrapped in an
EncodedStreamFrame so the caller knows which kind of frame
it received without re-parsing the §9.1 tag bit.
Sourcepub fn encode_frame_with_force(
&mut self,
frame: &I420Frame<'_>,
force_keyframe: bool,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame_with_force( &mut self, frame: &I420Frame<'_>, force_keyframe: bool, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame of the stream, with an optional override that forces it to be coded as a key frame regardless of the configured interval.
A force_keyframe = true call also re-anchors the interval:
after the forced K-frame at frame index i, the next automatic
keyframe lands at i + keyframe_interval, not at the original
multiple of keyframe_interval from the absolute start. This
keeps the inter-keyframe spacing predictable in the presence of
scene-cut overrides.
Sourcepub fn encode_frame_with_intra_pick(
&mut self,
frame: &I420Frame<'_>,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame_with_intra_pick( &mut self, frame: &I420Frame<'_>, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame using the configured keyframe interval to pick K vs P, with the round-160 / round-161 §11 intra-within-inter MB picker engaged on every P-frame.
Drop-in intra-pick companion to Self::encode_frame: the
scheduling decision (K vs P) and the §9.7 reference-slot ladder
are identical to the non-intra-pick path; only the per-MB picker
changes. On every emitted P-frame the per-MB picker scores the
full §11.2 × §11.4 whole-block intra grid (4 luma × 4 chroma =
16 candidates, B_PRED excluded) against the running in-frame
neighbours in addition to the §16 inter ladder, and picks
whichever of (best inter pick, J-best intra) wins on
J + lambda * is_inter_mb-bit. When the intra candidate wins
on at least one MB the §9.10 prob_intra byte drops below 255
and the §16.1 intra-mode-tree path emits on those MBs.
K-frames go through the same
encode_keyframe_with_reconstruction path as
Self::encode_frame — the intra-pick flag only affects the
inter (P-frame) arm. The §9.4 carried-delta state, the §9.7
reference-slot rotation, and the dimensions-lock semantics are
unchanged.
Wire compatibility: on any source where the round-161 picker
never selects an intra MB (e.g. a slow-translation flat
gradient where ZERO_MV already absorbs the residual), the
emitted bytes match Self::encode_frame modulo the
prob_intra byte’s drop from 255 to 1 (≈ 6 extra bits ≈ 1
extra byte per P-frame). This is the same bound the bare
encode_p_frame_multi_ref_with_intra_pick entry-point already
pins under tests/encoder_pframe_intra_pick.rs.
Sourcepub fn encode_frame_with_force_and_intra_pick(
&mut self,
frame: &I420Frame<'_>,
force_keyframe: bool,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame_with_force_and_intra_pick( &mut self, frame: &I420Frame<'_>, force_keyframe: bool, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame with the round-160 / round-161 intra-pick
engaged and an optional force_keyframe override that
re-anchors the keyframe interval, exactly mirroring
Self::encode_frame_with_force.
Companion to Self::encode_frame_with_intra_pick: the
force_keyframe semantics (re-anchoring the interval after a
forced K-frame at frame index i so the next automatic K-frame
lands at i + keyframe_interval) match
Self::encode_frame_with_force exactly. On the K-frame arm
the intra-pick flag is a no-op — every MB in a key frame is
intra by construction.
Sourcepub fn encode_frame_with_fitted_token_prob_updates(
&mut self,
frame: &I420Frame<'_>,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame_with_fitted_token_prob_updates( &mut self, frame: &I420Frame<'_>, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame using the configured keyframe interval to pick
K vs P, with an automatically-fitted §13.4 token_prob_update()
payload on every emitted frame.
Drop-in fitted companion to Self::encode_frame / the K-frame
arm of Self::encode_frame_with_force: scheduling, dimension-
lock semantics, and the §9.7 reference-slot ladder are identical;
only the bitstream differs. Each emitted frame independently
runs the round-157 (keyframe) or round-158 (inter) two-pass
fitter — the §13.4 payload is decided per frame from that frame’s
observed counts, never carried over to the next.
Wire compatibility: on a frame where no §13.4 slot crosses the
fitter’s saving threshold, the safety-guard fall-back returns
the bytes Self::encode_frame_with_force would have emitted
for the same kind of frame.
Carried-base assumption. The inter fitter assumes the prior
key frame was emitted with the §13.5 defaults (i.e. an
encode_keyframe-equivalent base table). This entry-point is
the closure of that loop: K-frames go through
encode_keyframe_with_reconstruction_and_fitted_token_prob_updates
which itself emits a fitted-on-defaults wire — the decoder
rebuilds coeff_probs[4][8][3][11] from defaults overlaid with
the K-frame’s payload, then the next P-frame’s fitter again
overlays its own payload on top of the §13.5 defaults. This
matches what crate::state::Vp8DecoderState::decode_inter_frame
does (overlay_token_probs(self.coeff_probs, &coded.token_prob_updates)
where self.coeff_probs was reset to §13.5 defaults by the prior
key frame).
Sourcepub fn encode_frame_with_force_and_fitted_token_prob_updates(
&mut self,
frame: &I420Frame<'_>,
force_keyframe: bool,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_frame_with_force_and_fitted_token_prob_updates( &mut self, frame: &I420Frame<'_>, force_keyframe: bool, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one frame, with an optional force_keyframe override and
the round-157 / round-158 fitter applied to every emitted frame.
Companion to Self::encode_frame_with_force /
Self::encode_frame_with_fitted_token_prob_updates. The
force_keyframe semantics (re-anchoring the interval) match
Self::encode_frame_with_force exactly.
Sourcepub fn encode_p_frame_with_refresh(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8 reference-slot refresh pattern.
This is the slot-rotation companion to
crate::encoder::encode_p_frame_multi_ref_with_refresh: it
emits a P-frame whose header carries the requested refresh
bits and then evolves the driver’s LAST / GOLDEN / ALTREF
slots per the §20 page-147 walk (copy_arf → copy_gf → refresh_gf → refresh_arf → refresh_last), so the next
encode_frame* call sees the same slot trio the in-tree
decoder would after consuming the same wire.
Pre-conditions:
- A
LASTslot must be present (the stream must have emitted at least one prior frame). If not, the call returnsStreamEncodeError::NoLastReference— the caller should drive at least one frame through the scheduler (Self::encode_frameorSelf::encode_frame_with_force) first. - Dimensions must match the stream’s locked dimensions; a
mismatch is surfaced as
StreamEncodeError::DimensionsChanged. refreshis forwarded tocrate::encoder::encode_p_frame_multi_ref_with_refresh, which runsRefreshControls::validate; invalidcopy_buffer_to_*selectors surface asEncodeError::InvalidCopyBufferSelectorwrapped inStreamEncodeError::Frame.
The keyframe scheduler is bypassed by this entry-point: the caller has asked for a specific refresh pattern, and forcing a key frame here would lose it.
The slot rotation runs after the bitstream is emitted, mirroring the §20 page-147 ordering verbatim:
copy_buffer_to_alternate(1 = LAST → ALTREF, 2 = GOLDEN → ALTREF).copy_buffer_to_golden(1 = LAST → GOLDEN, 2 = ALTREF → GOLDEN).refresh_golden_frame(replace GOLDEN with current reconstruction).refresh_alternate_frame(replace ALTREF with current reconstruction).refresh_last(replace LAST with current reconstruction).
last_keyframe_index is not touched (this is a P-frame).
Sourcepub fn encode_p_frame_with_refresh_and_intra_pick(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_intra_pick( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8 reference-slot refresh pattern, with the round-160 / round-161 §11 intra-within-inter MB picker engaged.
Combines Self::encode_p_frame_with_refresh (caller-driven
refresh ladder + stream-side slot rotation per §20 page-147)
with the round-161 picker. On every MB the picker scores the
full §11.2 × §11.4 whole-block intra grid (4 luma × 4 chroma)
against the running in-frame neighbours in addition to the §16
inter ladder, and picks whichever of (best inter, J-best intra)
wins on J + lambda * is_inter_mb-bit.
Pre-conditions and slot-rotation mirror
Self::encode_p_frame_with_refresh exactly:
- A
LASTslot must be present —StreamEncodeError::NoLastReferenceotherwise. - Dimensions must match the stream’s locked dimensions —
StreamEncodeError::DimensionsChangedotherwise. refreshis forwarded tocrate::encoder::encode_p_frame_multi_ref_with_refresh_and_intra_pick, which runsRefreshControls::validate; invalid selectors surface asEncodeError::InvalidCopyBufferSelectorwrapped inStreamEncodeError::Frame.- The keyframe scheduler is bypassed (the caller is asking for a P-frame with a specific refresh).
Slot-rotation runs after the bitstream is emitted, mirroring
the §20 page-147 walk (copy_arf → copy_gf → refresh_gf → refresh_arf → refresh_last). last_keyframe_index is not
touched. The §9.4 carried-delta state is not updated this
round — the picker engages the round-160 inter path with
LoopFilterDeltas::default (matching the bare-encoder
encode_p_frame_multi_ref_with_refresh_and_intra_pick
signature), so the effective deltas resolve to 0 and there
is no fresh value to carry. Callers that need both intra-pick
AND §9.4 deltas should sit one round above this — the
composition fits naturally into the
…_intra_pick_and_lf_deltas companion that a follow-up round
will expose; this round’s scope is exactly the intra-pick
thread, not the full Cartesian product.
Sourcepub fn encode_p_frame_with_refresh_and_lf_deltas(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
lf_deltas: &LoopFilterDeltas,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_lf_deltas( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, lf_deltas: &LoopFilterDeltas, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8
reference-slot refresh pattern and a caller-supplied §9.4
mb_lf_adjustments() per-reference / per-mode loop-filter
delta layer.
Companion to Self::encode_p_frame_with_refresh that exposes
the §9.4 loop_filter_adj_enable /
mode_ref_lf_delta_update + per-slot delta fields through
crate::encoder::LoopFilterDeltas. The stream encoder threads
the across-frame carried delta state per RFC 6386 §9.4 (“the
values from the previous frame are used, unless they are updated
in the current header”) — the caller does not need to track it.
Wire compatibility: passing
crate::encoder::LoopFilterDeltas::default (with
enabled = false) reproduces
Self::encode_p_frame_with_refresh byte-for-byte, including
when called repeatedly through the carried-state mechanism
(enabled = false resolves effective deltas to 0 regardless
of carried state).
Slot-rotation and pre-conditions match
Self::encode_p_frame_with_refresh.
Sourcepub fn encode_p_frame_with_refresh_and_lf_deltas_and_token_updates(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
lf_deltas: &LoopFilterDeltas,
token_updates: Option<&TokenProbUpdates>,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_lf_deltas_and_token_updates( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, lf_deltas: &LoopFilterDeltas, token_updates: Option<&TokenProbUpdates>, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8 refresh
pattern, §9.4 mb_lf_adjustments() delta layer, and §13.4
token_prob_update() payload.
Companion to Self::encode_p_frame_with_refresh_and_lf_deltas
that exposes the §13.4 per-position
coeff_prob_update_flag / coeff_prob sub-block through
crate::coded_header::TokenProbUpdates. The encoder writes the
replacement layer into the first-partition header and codes the
§13.3 residual tokens against the merged
coeff_probs[4][8][3][11] table (§13.5 defaults overlaid with
the caller’s per-position values), exactly mirroring what the
decoder’s decode_inter_frame rebuilds from the same wire.
Wire compatibility: passing token_updates = None (or an
all-None array) reproduces
Self::encode_p_frame_with_refresh_and_lf_deltas byte-for-byte
— every §13.4 flag is 0 and the §13.5 defaults stay in force.
Slot-rotation and pre-conditions match
Self::encode_p_frame_with_refresh.
Assumption on carried entropy state. This entry-point assumes
the prior key frame was emitted with the §13.5 defaults (i.e.
either crate::encoder::encode_keyframe /
crate::encoder::encode_keyframe_with_reconstruction, or
crate::encoder::encode_keyframe_with_token_prob_updates
called with an all-None array). The standard stream entry-points
Self::encode_frame / Self::encode_frame_with_force both
satisfy this since they go through
crate::encoder::encode_keyframe_with_reconstruction. Mixing a
non-default-base keyframe with this entry-point is out of round-
156 scope.
Sourcepub fn encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
lf_deltas: &LoopFilterDeltas,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, lf_deltas: &LoopFilterDeltas, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8
reference-slot refresh pattern, a caller-supplied §9.4
mb_lf_adjustments() per-reference / per-mode loop-filter delta
layer, and the round-160 / round-161 §11 intra-within-inter
MB picker engaged.
Composition of Self::encode_p_frame_with_refresh_and_lf_deltas
(round 151 §9.4 layer + across-frame carried-delta state) and
Self::encode_p_frame_with_refresh_and_intra_pick (round 162
stream thread of the round-160 / 161 picker). The round 162 next-
step ladder named exactly this composition — “compose the §9.4
mb_lf_adjustments() deltas with the intra-pick on the refresh
path (encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick)”
— as the follow-up that would expose both knobs together. Round
163 lands it.
Internally calls
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_intra_pick
(the matching bare-encoder wrapper). The stream encoder threads
the across-frame carried delta state per RFC 6386 §9.4 (“the
values from the previous frame are used, unless they are updated
in the current header”) — the caller does not need to track it;
the carry-update rule is identical to
Self::encode_p_frame_with_refresh_and_lf_deltas (adj-enabled
frames write back the effective deltas; adj-disabled frames leave
the carry untouched). The intra-pick toggle does NOT affect the
§9.4 delta carry — it governs per-MB candidate scoring only.
Wire compatibility:
- Passing
crate::encoder::LoopFilterDeltas::default(withenabled = false) reproducesSelf::encode_p_frame_with_refresh_and_intra_pickbyte-for-byte. The §9.4 layer is gated onlf_deltas.enabledexactly as on the non-intra-pick path. - On a source where intra never beats inter the wire matches
Self::encode_p_frame_with_refresh_and_lf_deltasmodulo a ~6 bits ≈ 1 byte frame-constant difference at the §9.10prob_intrabyte (sentinel255→ fitted1), matching the bound documented on the bare-encoder intra-pick path.
Pre-conditions, slot-rotation (§20 page-147 walk
copy_arf → copy_gf → refresh_gf → refresh_arf → refresh_last),
and error surface (NoLastReference, DimensionsChanged) match
Self::encode_p_frame_with_refresh exactly. last_keyframe_index
is not touched.
Sourcepub fn encode_p_frame_with_refresh_and_lf_deltas_and_fitted_token_prob_updates(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
lf_deltas: &LoopFilterDeltas,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_lf_deltas_and_fitted_token_prob_updates( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, lf_deltas: &LoopFilterDeltas, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8
reference-slot refresh pattern, a caller-supplied §9.4
mb_lf_adjustments() per-reference / per-mode loop-filter delta
layer, and the round-157 / round-158 §13.4 token-prob
observed-counts fitter engaged.
Round 158 landed the bare-encoder
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_fitted_token_prob_updates
(two-pass: encode with §13.5 defaults to collect observed branch
counts, run crate::encoder::fit_token_prob_updates to derive
a TokenProbUpdates payload that nets a positive bit saving,
then re-encode with that payload through
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_token_updates
— with the bytes_fitted <= bytes_default safety guard). Round
159 threaded the scheduler-driven fitter through
Self::encode_frame_with_fitted_token_prob_updates /
Self::encode_frame_with_force_and_fitted_token_prob_updates.
The round-158 entry-point itself flagged the gap that this
method closes:
Out of round-158 scope: threading the fitter into
Vp8InterStreamEncoder’sencode_frameladder — the stream-driver methodencode_p_frame_with_refresh_and_lf_deltas_and_token_updatesstays on the caller-driven entry-point for now; a subsequent round adds the analogous_with_fitted_token_prob_updatesstream method.
Round 164 lands that subsequent-round method on the refresh +
lf-deltas axis — i.e. composed with the caller-supplied §9.4
delta layer. The companion scheduler-driven fitter path
(Self::encode_frame_with_fitted_token_prob_updates) already
exists; this is the missing refresh-axis sibling.
Internally calls
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_fitted_token_prob_updates.
The stream encoder threads the across-frame carried delta state
per RFC 6386 §9.4 — the caller does not need to track it; the
carry-update rule is identical to
Self::encode_p_frame_with_refresh_and_lf_deltas (adj-enabled
frames write back the effective deltas; adj-disabled frames
leave the carry untouched). The §13.4 fitter does NOT affect
the §9.4 delta carry — it governs residual-token coding only,
exactly as on the caller-driven token-updates sibling
Self::encode_p_frame_with_refresh_and_lf_deltas_and_token_updates.
Wire compatibility:
- Whenever the fitter’s safety guard falls back (no slot crossed
the saving threshold, or the fitted re-encode is larger
than the default-encode wire), the returned bytes are the
default-encode bytes, byte-equal to
Self::encode_p_frame_with_refresh_and_lf_deltason the same inputs. - Whenever the fitter wins, the bytes are byte-equal to the
bare-encoder composition
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_fitted_token_prob_updateson the same inputs. The bare-encoder’s safety guard also ensures the wire is<=the default-encode wire on every frame — this property carries through unchanged to the stream driver.
Pre-conditions, slot-rotation (§20 page-147 walk
copy_arf → copy_gf → refresh_gf → refresh_arf → refresh_last),
and error surface (NoLastReference, DimensionsChanged) match
Self::encode_p_frame_with_refresh exactly. last_keyframe_index
is not touched.
Carried-base assumption. Same as the round-158 bare-encoder
fitter: this method assumes the prior key frame was emitted
with the §13.5 defaults — i.e. either
crate::encoder::encode_keyframe /
crate::encoder::encode_keyframe_with_reconstruction, or
crate::encoder::encode_keyframe_with_token_prob_updates
called with an all-None array. The standard stream entry-points
Self::encode_frame / Self::encode_frame_with_force both
satisfy this since they go through
crate::encoder::encode_keyframe_with_reconstruction. Mixing
a fitted keyframe (e.g.
Self::encode_frame_with_fitted_token_prob_updates) with this
entry-point is out of round-164 scope — same rule as the
round-156 caller-driven token-updates sibling.
Sourcepub fn encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick_and_fitted_token_prob_updates(
&mut self,
frame: &I420Frame<'_>,
refresh: &RefreshControls,
lf_deltas: &LoopFilterDeltas,
) -> Result<EncodedStreamFrame, StreamEncodeError>
pub fn encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick_and_fitted_token_prob_updates( &mut self, frame: &I420Frame<'_>, refresh: &RefreshControls, lf_deltas: &LoopFilterDeltas, ) -> Result<EncodedStreamFrame, StreamEncodeError>
Encode one P-frame with a caller-supplied §9.7 / §9.8
reference-slot refresh pattern, a caller-supplied §9.4
mb_lf_adjustments() per-reference / per-mode loop-filter delta
layer, the round-160 / round-161 §11 intra-within-inter MB
picker, and the round-157 / round-158 §13.4 token-prob
observed-counts fitter — all on the stream-driver path.
Round 163 landed
Self::encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick
(§11 picker on the refresh + §9.4 deltas axis) and round 164
landed
Self::encode_p_frame_with_refresh_and_lf_deltas_and_fitted_token_prob_updates
(§13.4 fitter on the refresh + §9.4 deltas axis). Each composed
individually with the lf-deltas axis but neither composed with
the other.
Round 164’s next-step ladder names this as item (5):
(5) parallel fitter composition on the intra-pick + refresh + lf-deltas axis (combining r163 + r164 — the picker on the fitted refresh path).
Internally calls
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_intra_pick_and_fitted_token_prob_updates
— a two-pass encode that mirrors the round-158 fitter (pass 1
with the §13.5 defaults to collect observed branch counts; pass
2 with the fitted crate::coded_header::TokenProbUpdates
payload), with the §11 intra picker engaged on both passes
so the recorded counts already reflect the intra/inter mix that
will reappear on pass 2. The pass-2 RD picker re-scores against
the merged probability table.
The stream encoder threads the across-frame carried §9.4 delta
state per RFC 6386 §9.4 exactly as
Self::encode_p_frame_with_refresh_and_lf_deltas /
Self::encode_p_frame_with_refresh_and_lf_deltas_and_intra_pick /
Self::encode_p_frame_with_refresh_and_lf_deltas_and_fitted_token_prob_updates:
adj-enabled frames write back the effective deltas; adj-disabled
frames leave the carry untouched. Neither the §11 picker nor the
§13.4 fitter perturbs the §9.4 carry — both govern residual /
per-MB decisions only.
Wire compatibility:
- Whenever the fitter’s safety guard falls back (no slot crossed
the saving threshold, or the fitted re-encode is larger
than the default-encode wire), the returned bytes are the
default-encode bytes, byte-equal to
Self::encode_p_frame_with_refresh_and_lf_deltas_and_intra_pickon the same inputs. The pass-1 planes are also returned in the fallback so a streaming caller’s next-frame LAST matches the decoder’s reconstruction. - Whenever the fitter wins, the bytes are byte-equal to the
bare-encoder composition
crate::encoder::encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_intra_pick_and_fitted_token_prob_updateson the same inputs. - In every case the wire is
<=theSelf::encode_p_frame_with_refresh_and_lf_deltas_and_intra_pickdefault — the round-158 bare-encoder safety guard lifted into the stream driver.
Pre-conditions, slot-rotation (§20 page-147 walk
copy_arf → copy_gf → refresh_gf → refresh_arf → refresh_last),
and error surface (NoLastReference, DimensionsChanged) match
Self::encode_p_frame_with_refresh exactly. last_keyframe_index
is not touched.
Carried-base assumption. Same as the round-158 bare-encoder
fitter: this method assumes the prior key frame was emitted with
the §13.5 defaults — i.e. either
crate::encoder::encode_keyframe /
crate::encoder::encode_keyframe_with_reconstruction, or
crate::encoder::encode_keyframe_with_token_prob_updates
called with an all-None array. The standard stream entry-points
Self::encode_frame / Self::encode_frame_with_force both
satisfy this. Mixing a fitted keyframe (e.g.
Self::encode_frame_with_fitted_token_prob_updates) with this
entry-point is out of round-165 scope — same rule as the
round-156 / round-164 caller-driven / fitted-token-updates
siblings.
Sourcepub fn carried_ref_deltas(&self) -> [i16; 4]
pub fn carried_ref_deltas(&self) -> [i16; 4]
Borrow the across-frame §9.4 ref_frame_delta[] carried state
(in {CURRENT, LAST, GOLDEN, ALTREF} order). Cleared to
[0; 4] on every key frame per RFC 6386 §9.4.
Sourcepub fn carried_mode_deltas(&self) -> [i16; 4]
pub fn carried_mode_deltas(&self) -> [i16; 4]
Borrow the across-frame §9.4 mode_delta[] carried state
(in {B_PRED, ZERO_MV, OTHER_MV, SPLIT_MV} order). Cleared
to [0; 4] on every key frame per RFC 6386 §9.4.
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 keyframe_interval(&self) -> u64
pub fn keyframe_interval(&self) -> u64
Configured keyframe interval.
Sourcepub fn last_keyframe_index(&self) -> Option<u64>
pub fn last_keyframe_index(&self) -> Option<u64>
0-based frame index of the most recent key frame, or None if
no frame has been encoded yet.
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.