Expand description
The owned codec ticket — one stream’s AVCodecParameters, mirrored
into plain Rust and rebuilt on demand.
§Why the mirror exists
ffmpeg_next::codec::Parameters is a *mut AVCodecParameters
behind a Send-but-not-Sync wrapper. A track row that stores one
is !Sync, an Arc of that row is !Send, and every consumer that
shares a track table across tasks stops compiling — for a struct
FFmpeg documents as a plain descriptor with no thread affinity at
all. The auto-trait is missing, not the safety.
The crate already answers that class one way: it mirrors what a
consumer needs into owned Rust —
TrackParams mirrors the
common seats, SideDataEntry mirrors a frame’s metadata,
FfmpegBytes mirrors its pixels. CodecTicket walks that road
its last mile: every seat of an AVCodecParameters, held as
owned bytes and plain integers, with Sync arriving by
construction rather than by an unsafe impl over FFI.
§The two halves
CodecTicket::mirrorreads a liveAVCodecParametersinto the ticket. It is the only place that reads one.CodecTicket::rebuildallocates a freshAVCodecParametersand writes every seat back. It is the only place in this crate’s track-row road that allocates one, and what it hands back is whatavcodec_parameters_to_contextis fed — unchanged from before the mirror existed.
The pair is proved in tests/codec_ticket_parity.rs: for every
stream of every fixture the corpus can mint, the rebuilt struct is
compared with the original field by field, including
extradata bytes, the AV_INPUT_BUFFER_PADDING_SIZE zeroes past
their end, every coded_side_data entry’s type id and payload, and
the channel layout down to a custom map’s per-channel names. The
shapes no container will hand over — a custom map, an unnamed
side-data kind, every scalar set off its default — are built by
hand in the same file, and a decoder is opened through a rebuilt
ticket and made to produce a frame.
§The reading discipline, inherited
Not one bindgen enum is materialised out of FFmpeg memory. Every
open C enum seat — the media type, the codec id, the field order,
the five colour seats, the alpha mode, the channel order, a custom
channel’s id, a side-data type id — travels as the raw 32-bit
pattern it is on the wire, read and written through the same
i32 cast, so a value this build’s bindings cannot name is still a
value this ticket carries. That is the same rule
[crate::extras::bounded_clone_parameters] is written to, for the
same reason: forming a typed reference to a struct whose enum field
holds an unnamed discriminant is undefined behaviour before a
single field is read.
Structs§
- Channel
Layout Ticket - The owned mirror of an
AVChannelLayout. - Codec
Ticket - Every seat of one stream’s
AVCodecParameters, owned. - Custom
Channel - One entry of a custom channel map — the
AV_CHANNEL_ORDER_CUSTOMarm ofChannelLayoutTicket. - Dolby
Vision Config - The Dolby Vision decoder configuration record’s two routing seats —
the profile number and the base-layer signal-compatibility id —
read from the container’s
dvcC/dvvC/dwvCbox when present. - Ratio
- A verbatim
AVRationalseat.