Skip to main content

CodecTicket

Struct CodecTicket 

Source
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

Source

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.

Source

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_alloc gives non-zero defaults to — format is -1, profile and level are AV_PROFILE_UNKNOWN / AV_LEVEL_UNKNOWN, both rationals are 0/1, and so on — so leaving any of them would let a default masquerade as the file’s own value.
  • The four descriptor seatsextradata and extradata_size, coded_side_data and nb_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_reset memsets 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_layout is 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.

Source

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.

Source

pub const fn stream_index(&self) -> usize

The AVStream.index this mirror was taken at — what Self::rebuild’s errors name.

Source

pub const fn codec_type(&self) -> i32

The raw AVMediaType.

Source

pub const fn codec_id(&self) -> i32

The raw AVCodecID.

Source

pub const fn codec_tag(&self) -> u32

The codec tag — the AVI FOURCC, when the container carries one.

Source

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.

Source

pub const fn extradata_ref(&self) -> &FfmpegBytes

The extradata’s carrier, for a consumer that wants the bytes without copying them again.

Source

pub fn coded_side_data(&self) -> &[SideDataEntry]

Stream-level side data — where a MOV prof atom’s ICC profile arrives, among others.

Source

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.

Source

pub const fn format(&self) -> i32

The pixel format (video) or sample format (audio), as the raw integer both enums share this seat as.

Source

pub const fn bit_rate(&self) -> i64

Average bitrate in bits per second.

Source

pub const fn bits_per_coded_sample(&self) -> i32

Bits per sample in the coded bitstream.

Source

pub const fn bits_per_raw_sample(&self) -> i32

Valid bits in each output sample.

Source

pub const fn profile(&self) -> i32

The codec profile.

Source

pub const fn level(&self) -> i32

The codec level.

Source

pub const fn width(&self) -> i32

Frame width in pixels — video, and the subtitle canvas.

Source

pub const fn height(&self) -> i32

Frame height in pixels — video, and the subtitle canvas.

Source

pub const fn sample_aspect_ratio(&self) -> Ratio

The sample aspect ratio. A zero numerator means unknown.

Source

pub const fn framerate(&self) -> Ratio

The codec-level frame rate. 0/1 when frames differ in duration or the value is not known.

Source

pub const fn field_order(&self) -> i32

The raw AVFieldOrder.

Source

pub const fn color_range(&self) -> i32

The raw AVColorRange.

Source

pub const fn color_primaries(&self) -> i32

The raw AVColorPrimaries.

Source

pub const fn color_trc(&self) -> i32

The raw AVColorTransferCharacteristic.

Source

pub const fn color_space(&self) -> i32

The raw AVColorSpace.

Source

pub const fn chroma_location(&self) -> i32

The raw AVChromaLocation.

Source

pub const fn video_delay(&self) -> i32

Number of delayed frames — the decoder’s has_b_frames.

Source

pub const fn ch_layout(&self) -> &ChannelLayoutTicket

The channel layout.

Source

pub const fn sample_rate(&self) -> i32

Audio samples per second.

Source

pub const fn block_align(&self) -> i32

Bytes per coded audio frame — nBlockAlign in WAVEFORMATEX.

Source

pub const fn frame_size(&self) -> i32

Audio frame size, when the format fixes one.

Source

pub const fn initial_padding(&self) -> i32

Leading padding samples the encoder inserted.

Source

pub const fn trailing_padding(&self) -> i32

Trailing padding samples the encoder appended.

Source

pub const fn seek_preroll(&self) -> i32

Samples to skip after a discontinuity.

Source

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

Source§

fn clone(&self) -> CodecTicket

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodecTicket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Sizes rather than payloads. An extradata blob and an ICC profile are both megabyte-scale and neither is readable; what a reader of a log wants is the stream’s identity and whether the heap seats are populated.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more