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§
Sourcetype Adapter: ImageAdapter
type Adapter: ImageAdapter
Backend-specific vocabulary.
Required Methods§
Sourcefn 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>
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. That is not the receive-path
convention wearing different clothes: Received names the
states of a session — nothing yet, over — and a one-shot decode
has neither. “These bytes are not a picture” is a fact about the
payload the caller handed over, which is what an error is for.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".