pub struct Decoder { /* private fields */ }Expand description
Safe AV1 decoder instance
This is the main entry point for decoding AV1 video. It wraps the internal
rav1d decoder with a safe, type-safe interface.
§Example
use rav1d_safe::src::managed::Decoder;
let mut decoder = Decoder::new()?;
let obu_data = b"...";
if let Some(frame) = decoder.decode(obu_data)? {
println!("Decoded {}x{}", frame.width(), frame.height());
}Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn with_settings(settings: Settings) -> Result<Self>
pub fn with_settings(settings: Settings) -> Result<Self>
Create a decoder with custom settings
Sourcepub fn set_stop(&mut self, stop: Option<Arc<dyn Stop>>)
pub fn set_stop(&mut self, stop: Option<Arc<dyn Stop>>)
Set (or clear with None) a cooperative cancellation token (issue #412).
While set, the decode loop polls the token at sbrow boundaries and aborts
the in-flight frame with Error::Cancelled if it fires — so a server
can bound a slow decode of a crafted-but-legal stream without abandoning
the worker thread. Pass any Arc<dyn Stop> (a deadline, a flag, an
Unstoppable no-op); None (the default) disables checking at zero
cost. The token applies to subsequent decode / get_frame / flush
calls and may be swapped between them.
Both decode paths honor the token: the single-threaded loop (threads = 1,
the default) checks it per sbrow, and tile-threaded workers (threads > 1)
check it per task and abort the frame through the same error path the
internal flush uses. Granularity is one superblock row, so a cancel lands
within a few milliseconds even on a large frame, not at the next frame
boundary.
let mut decoder = Decoder::new()?;
decoder.set_stop(Some(Arc::new(Unstoppable)));Sourcepub fn decode(&mut self, data: &[u8]) -> Result<Option<Frame>>
pub fn decode(&mut self, data: &[u8]) -> Result<Option<Frame>>
Decode AV1 OBU data from a byte slice
Returns Ok(None) if more data is needed (the decoder is waiting for more input).
Returns Ok(Some(frame)) when a frame is successfully decoded.
§Example
let mut decoder = Decoder::new()?;
let data = b"..."; // AV1 OBU data
match decoder.decode(data)? {
Some(frame) => {
println!("Got frame: {}x{}", frame.width(), frame.height());
}
None => {
println!("Need more data");
}
}Sourcepub fn get_frame(&mut self) -> Result<Option<Frame>>
pub fn get_frame(&mut self) -> Result<Option<Frame>>
Try to get a decoded frame without sending new data.
After calling decode(), the decoder may have buffered
additional frames (e.g. from a raw OBU stream containing multiple temporal
units). Call this in a loop until it returns Ok(None) to drain them.
Sourcepub fn flush(&mut self) -> Result<Vec<Frame>>
pub fn flush(&mut self) -> Result<Vec<Frame>>
Flush the decoder and return all remaining frames
This should be called after all input data has been fed to the decoder
to retrieve any buffered frames. It is a drain, then a reset: every
frame the decoder still owes for data already passed to
decode() — temporal units not yet parsed from the last
chunk, and frames in flight on frame-threading workers — is returned,
in output order, and only then is the decoder reset so it is ready for
a new stream.
On an error the decoder is still reset, and the error is returned; frames drained before it are dropped with it.