pub struct OutputParamsWatch { /* private fields */ }Expand description
Consumer-side helper for the Decoder::output_params /
Decoder::output_params_generation contract: folds the decoder’s
output description into a stream’s CodecParameters once, and
again only when the decoder signals a mid-stream change — one
integer compare per frame otherwise.
Call observe after every successful
receive_frame (the first call always reads the description; later
calls re-read only when the generation moved). Call
prime before the first frame when the shape is
needed up front (to size a renderer, pick a converter); it merges
whatever the decoder already knows without consuming the
first-frame read, since the description may still be refined up to
the first frame.
fn pump(dec: &mut dyn Decoder, stream: &mut CodecParameters) -> oxideav_core::Result<()> {
let mut watch = OutputParamsWatch::new();
while let Ok(_frame) = dec.receive_frame() {
if watch.observe(&*dec, stream) {
// shape changed (or was first resolved): reconfigure
// the converter / renderer from `stream` here.
}
}
Ok(())
}Implementations§
Source§impl OutputParamsWatch
impl OutputParamsWatch
Sourcepub fn observe<D: Decoder + ?Sized>(
&mut self,
decoder: &D,
stream: &mut CodecParameters,
) -> bool
pub fn observe<D: Decoder + ?Sized>( &mut self, decoder: &D, stream: &mut CodecParameters, ) -> bool
Call after a successful receive_frame. Re-reads
Decoder::output_params on the first call and whenever
Decoder::output_params_generation differs from the value of
the last read, merging it into stream through
CodecParameters::merge_output_params. Returns true when
that changed an output-describing field of stream.
A decoder that still answers None leaves stream untouched
and is asked again on the next call.