pub struct CodecTicket { /* private fields */ }Expand description
Every seat of one stream’s AVCodecParameters, owned.
§The roster
All thirty-two fields FFmpeg n9.0 declares, in that struct’s own
order. Nothing is elided as “video only” or “audio only”:
avcodec_parameters_to_context reads a different subset per medium
but the file carries whatever it carries, and a mirror that kept
only one medium’s subset would lose a seat the moment a container
declared something unusual.
They land in three kinds. Three seats own heap and become owned
Rust: extradata, coded_side_data, and ch_layout’s custom map.
Two are lengths of those — extradata_size and
nb_coded_side_data — and are not stored: a carrier already
knows its own length, and a second copy of it is a second thing to
keep in agreement. The remaining twenty-seven are scalars, held as
the integers (or, for the two AVRational seats, the Ratio)
they are.
§Send + Sync, by construction
Every field is an integer, an FfmpegBytes
(an Arc<[u8]>), or a Vec of those. There is no raw pointer, so
there is no unsafe impl and no safety argument to get wrong —
which is exactly the point of the road this type is on. See
tests::the_ticket_is_send_and_sync.
§What it does not carry, and why that is a refusal rather than a
loss
AVChannelLayout::opaque and AVChannelCustom::opaque are
documented as “private data of the user”: raw pointers, set by
nobody but the caller who owns them, and unreadable to a mirror
that must outlive the pointer’s owner. libavformat never sets
either, so no demuxed stream reaches this type carrying one. If one
ever did, CodecTicket::mirror refuses with
DemuxError::ParametersOpaque rather than dropping it in
silence — the same fail-closed answer
measure_parameters gives a channel order it has
never heard of.
Implementations§
Source§impl CodecTicket
impl CodecTicket
Sourcepub fn mirror(
source: &Parameters,
stream_index: usize,
budget: usize,
) -> Result<Self, DemuxError>
pub fn mirror( source: &Parameters, stream_index: usize, budget: usize, ) -> Result<Self, DemuxError>
Mirrors a live set of codec parameters into an owned ticket.
budget is the ceiling the mirror’s heap seats must fit under,
measured before a byte is copied — the same admission
[crate::extras::bounded_clone_parameters] performs and the same
number admit_streams charges against the session’s total. A set
of parameters over the ceiling is refused with
DemuxError::ParametersTooLarge, never truncated.
Fails with DemuxError::ParametersMissing when source is
null-backed — Parameters::new() and Parameters::default() are
safe constructors over an unchecked avcodec_parameters_alloc,
so a caller can hold one without ever having been told.
Sourcepub fn rebuild(&self) -> Result<Parameters, DemuxError>
pub fn rebuild(&self) -> Result<Parameters, DemuxError>
Rebuilds a live AVCodecParameters from the ticket.
The one ffmpeg-native allocation on the track row’s road, and the handoff a decoder is opened from:
FfmpegAudioStreamDecoder::open(
track.extra().clone_parameters()?,
track.timebase(),
limits,
)Every seat that can hold a non-default value is written, so the
result depends on the ticket rather than on what
avcodec_parameters_alloc happened to leave behind. Stated
exactly, because the difference is load-bearing:
- The twenty-seven scalars are written unconditionally. Those
are the seats
avcodec_parameters_allocgives non-zero defaults to —formatis-1,profileandlevelareAV_PROFILE_UNKNOWN/AV_LEVEL_UNKNOWN, both rationals are0/1, and so on — so leaving any of them would let a default masquerade as the file’s own value. - The four descriptor seats —
extradataandextradata_size,coded_side_dataandnb_coded_side_data— are written only when the ticket has something to put there. On the empty path they keep the allocator’s zero, and that is correct rather than an omission:codec_parameters_resetmemsets the whole struct to zero and then assigns non-zero defaults to a named list that contains none of these four. A null pointer with a zero length is exactly what “no extradata” and “no side data” mean, and it is what the source had. ch_layoutis always written — order, channel count, and either the mask or the map.
That is what makes field-by-field parity with the original
provable rather than hopeful, and
tests/codec_ticket_parity.rs::every_scalar_seat_is_written_back
is the assertion that a seat quietly relying on a default cannot
pass.
Fallible because allocation is: ParametersAlloc when the struct
itself cannot be allocated, ParametersCopy carrying ENOMEM
when one of the heap seats cannot. Nothing here consults a
budget — the bytes are already resident and were admitted at
Self::mirror; what this allocates is exactly
Self::footprint_bytes.
Sourcepub const fn footprint_bytes(&self) -> usize
pub const fn footprint_bytes(&self) -> usize
What Self::rebuild asks FFmpeg’s allocator for: extradata
with the AV_INPUT_BUFFER_PADDING_SIZE decoders read past the
end into, the coded_side_data descriptor array and every
entry’s payload, and a custom channel map.
The number the session admitted this stream at, and the number
DemuxLimits::max_codec_parameter_bytes was judged against — so
a row that opened is a row whose every rebuild fits the ceiling
it opened under.
Not the ticket’s own residency: the owned mirror holds the payload without FFmpeg’s trailing padding, and shares its buffers by refcount.
Sourcepub const fn stream_index(&self) -> usize
pub const fn stream_index(&self) -> usize
The AVStream.index this mirror was taken at — what
Self::rebuild’s errors name.
Sourcepub const fn codec_type(&self) -> i32
pub const fn codec_type(&self) -> i32
The raw AVMediaType.
Sourcepub const fn codec_tag(&self) -> u32
pub const fn codec_tag(&self) -> u32
The codec tag — the AVI FOURCC, when the container carries one.
Sourcepub fn extradata(&self) -> &[u8] ⓘ
pub fn extradata(&self) -> &[u8] ⓘ
The decoder-initialisation bytes — SPS/PPS for H.264, the
AudioSpecificConfig for AAC, a font’s payload for an
attachment. Empty when the stream carries none, or when the row
was built on the attachment road that leaves them to the carrier.
Sourcepub const fn extradata_ref(&self) -> &FfmpegBytes
pub const fn extradata_ref(&self) -> &FfmpegBytes
The extradata’s carrier, for a consumer that wants the bytes without copying them again.
Sourcepub fn coded_side_data(&self) -> &[SideDataEntry]
pub fn coded_side_data(&self) -> &[SideDataEntry]
Stream-level side data — where a MOV prof atom’s ICC profile
arrives, among others.
Sourcepub fn dolby_vision_config(&self) -> Option<DolbyVisionConfig>
pub fn dolby_vision_config(&self) -> Option<DolbyVisionConfig>
The Dolby Vision configuration record — profile number and base-
layer compatibility id — from the container’s dvcC / dvvC /
dwvC box, when the stream carries one.
None when Self::coded_side_data holds no
AV_PKT_DATA_DOVI_CONF entry (an ordinary, non-Dolby-Vision
stream — the overwhelming majority) or the entry’s payload is too
short to hold both seats. Absent configuration answers absent,
same as every other seat this crate exposes as an Option.
This is the configuration-record half of Dolby Vision — the
two numbers a consumer routes base-layer-vs-refuse on before a
single frame decodes. The per-frame half — the RPU buffer
(AV_FRAME_DATA_DOVI_RPU_BUFFER) and parsed dynamic metadata
(AV_FRAME_DATA_DOVI_METADATA), plus HDR10+ dynamic metadata
(AV_FRAME_DATA_DYNAMIC_HDR_PLUS) — is not exposed by this crate
yet: mediadecode#54.
Sourcepub const fn format(&self) -> i32
pub const fn format(&self) -> i32
The pixel format (video) or sample format (audio), as the raw integer both enums share this seat as.
Sourcepub const fn bits_per_coded_sample(&self) -> i32
pub const fn bits_per_coded_sample(&self) -> i32
Bits per sample in the coded bitstream.
Sourcepub const fn bits_per_raw_sample(&self) -> i32
pub const fn bits_per_raw_sample(&self) -> i32
Valid bits in each output sample.
Sourcepub const fn sample_aspect_ratio(&self) -> Ratio
pub const fn sample_aspect_ratio(&self) -> Ratio
The sample aspect ratio. A zero numerator means unknown.
Sourcepub const fn framerate(&self) -> Ratio
pub const fn framerate(&self) -> Ratio
The codec-level frame rate. 0/1 when frames differ in duration
or the value is not known.
Sourcepub const fn field_order(&self) -> i32
pub const fn field_order(&self) -> i32
The raw AVFieldOrder.
Sourcepub const fn color_range(&self) -> i32
pub const fn color_range(&self) -> i32
The raw AVColorRange.
Sourcepub const fn color_primaries(&self) -> i32
pub const fn color_primaries(&self) -> i32
The raw AVColorPrimaries.
Sourcepub const fn color_space(&self) -> i32
pub const fn color_space(&self) -> i32
The raw AVColorSpace.
Sourcepub const fn chroma_location(&self) -> i32
pub const fn chroma_location(&self) -> i32
The raw AVChromaLocation.
Sourcepub const fn video_delay(&self) -> i32
pub const fn video_delay(&self) -> i32
Number of delayed frames — the decoder’s has_b_frames.
Sourcepub const fn ch_layout(&self) -> &ChannelLayoutTicket
pub const fn ch_layout(&self) -> &ChannelLayoutTicket
The channel layout.
Sourcepub const fn sample_rate(&self) -> i32
pub const fn sample_rate(&self) -> i32
Audio samples per second.
Sourcepub const fn block_align(&self) -> i32
pub const fn block_align(&self) -> i32
Bytes per coded audio frame — nBlockAlign in WAVEFORMATEX.
Sourcepub const fn frame_size(&self) -> i32
pub const fn frame_size(&self) -> i32
Audio frame size, when the format fixes one.
Sourcepub const fn initial_padding(&self) -> i32
pub const fn initial_padding(&self) -> i32
Leading padding samples the encoder inserted.
Sourcepub const fn trailing_padding(&self) -> i32
pub const fn trailing_padding(&self) -> i32
Trailing padding samples the encoder appended.
Sourcepub const fn seek_preroll(&self) -> i32
pub const fn seek_preroll(&self) -> i32
Samples to skip after a discontinuity.
Sourcepub const fn alpha_mode(&self) -> i32
pub const fn alpha_mode(&self) -> i32
The raw AVAlphaMode — how an alpha channel relates to the
colour values, and the last field AVCodecParameters declares.
New in FFmpeg n9.0, and the seat this mirror’s first draft dropped: video-only, left at its zero by every fixture the corpus can mint, and therefore reading back identically whether it is mirrored or forgotten. The parity comparator names every field for exactly that reason.
Trait Implementations§
Source§impl Clone for CodecTicket
impl Clone for CodecTicket
Source§fn clone(&self) -> CodecTicket
fn clone(&self) -> CodecTicket
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more