Skip to main content

ImageDecoder

Trait ImageDecoder 

Source
pub trait ImageDecoder {
    type Adapter: ImageAdapter;
    type Buffer: AsRef<[u8]>;
    type Error;

    // Required method
    fn decode(
        &mut self,
        packet: &AttachmentPacket<<Self::Adapter as ImageAdapter>::PacketExtra, Self::Buffer>,
    ) -> Result<ImageFrame<<Self::Adapter as ImageAdapter>::PixelFormat, <Self::Adapter as ImageAdapter>::FrameExtra, Self::Buffer>, Self::Error>;
}
Expand description

One-shot still-image decoder — cover art, an embedded thumbnail, a poster frame.

No Stream in the name, and no rhythm to go with it. An attachment track delivers exactly one packet (see Demuxer’s attachment contract), that packet is a whole file, and decoding it produces exactly one picture. There is nothing to queue, nothing to drain, and no end-of-stream to signal — so decode takes the packet and returns the frame, instead of the send_packet / receive_frame split the two *StreamDecoder traits need. SubtitleDecoder keeps that split only because FFmpeg’s own subtitle API is push-shaped; nothing forces it here.

The frame has no timestamps, because ImageFrame has no seats for them.

§Where the input comes from

A container’s still images arrive as TrackKind::Attachment tracks: the track row says what codec the picture is in, and the track’s one AttachmentPacket carries its bytes. So the row opens the decoder — off-trait, per the module docs — and the packet is what decode is handed.

§&mut self

Decoding one image needs no state across calls; the exclusive borrow is here because a backend’s decoder handle is a mutable resource (FFmpeg’s AVCodecContext is), and because it lets a backend reuse one open decoder across several attachments of the same codec rather than reopening per picture.

Required Associated Types§

Source

type Adapter: ImageAdapter

Backend-specific vocabulary.

Source

type Buffer: AsRef<[u8]>

Buffer type held by the packet this decoder accepts and the frame it produces. See the module docs for what may be bound here.

Source

type Error

Decoder-specific error type.

Required Methods§

Source

fn decode( &mut self, packet: &AttachmentPacket<<Self::Adapter as ImageAdapter>::PacketExtra, Self::Buffer>, ) -> Result<ImageFrame<<Self::Adapter as ImageAdapter>::PixelFormat, <Self::Adapter as ImageAdapter>::FrameExtra, Self::Buffer>, Self::Error>

Decodes one attachment payload — a whole image file — into a still.

Backends signal “these bytes are not a picture this decoder can read” through a backend-specific Error variant, never by returning an empty frame.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§