Skip to main content

TrackExtra

Struct TrackExtra 

Source
pub struct TrackExtra { /* private fields */ }
Expand description

Per-TrackInfo extras — the FFmpeg side of one track-table row.

Carries the stream’s Parameters, which is what opens a decoder for the track — through Self::clone_parameters, which is a deep avcodec_parameters_copy with no tie back to the format context, so a decoder outlives the demuxer that named it.

No Clone, and no Default. Both would have to go through ffmpeg_next’s Clone / Default for Parameters, which check neither the allocation nor the copy: safe public code could dereference a null destination or receive parameters that are quietly incomplete. Clone cannot report either, so this type does not implement it; Self::try_clone is the same copy with the answer a caller can act on, and Self::clone_parameters is the handoff a decoder actually needs. This crate shipped a derived Clone over the unchecked path once, reachable from safe code that just copied a track row, and closed it by removing the derive (see demuxer::tests::the_public_track_extra_copies_are_checked_too).

The message-carrier law is the second, independent reason Clone stays off: messages may be Clone, but Clone is always a refcount bump, never a deep copy, and avcodec_parameters_copy is not that. This crate shipped a hand-written, checked Clone here once too — through Self::try_clone, to satisfy a channel bound — and it came back out for the same reason: a consumer that needs to share the TrackInfo this type lives inside wraps it in Arc once, at the door, instead of paying a deep copy per consumer. Self::try_clone remains for the one caller that genuinely wants an owned duplicate of the codec parameters, which sharing a message is not.

disposition is the raw AV_DISPOSITION_* bit set, not ffmpeg_next::format::stream::Disposition. That type’s from_bits_truncate drops bits the linked build has no constant for, and this crate’s stance on bit sets is that every pattern is a value — the same reason PacketFlags reaches the wire as a number.

Implementations§

Source§

impl TrackExtra

Source

pub fn new( stream_index: i32, parameters: Parameters, ) -> Result<Self, DemuxError>

Constructs a TrackExtra from the stream index and its codec parameters. Everything else starts absent.

Fallible, and that is the point. Parameters::new() and Parameters::default() are safe constructors that hand back a null-backed value when avcodec_parameters_alloc fails, saying nothing; accepting one here would store a landmine that goes off later, in a copy, on a thread that has forgotten the allocator ever failed. Refusing it at the door is what lets every other method on this type — and every reader of Self::parameters — rely on there being parameters at all.

Not const fn: Parameters owns a heap allocation.

Source

pub fn try_clone(&self) -> Result<Self, DemuxError>

A deep copy of this row, with the codec-parameter copy checked.

The fallible counterpart of the Clone this type deliberately does not implement — see the type’s own documentation for why.

Source

pub fn clone_parameters(&self) -> Result<Parameters, DemuxError>

An owned deep copy of the track’s codec parameters — the handoff that opens a decoder for this track.

FfmpegAudioStreamDecoder::open(track.extra().clone_parameters()?, track.timebase()). Fallible because the copy is: an allocation failure here is the difference between a decoder that is not opened and one opened on parameters that are not the file’s.

Source

pub const fn stream_index(&self) -> i32

Returns the source AVStream.index.

Source

pub const fn disposition(&self) -> i32

Returns the raw AVStream.disposition bit set.

Source

pub const fn start_time(&self) -> Option<i64>

Returns the stream’s start time in the track’s timebase, or None when the container does not carry one.

Source

pub const fn frame_count(&self) -> Option<i64>

Returns AVStream.nb_frames when the container carries it.

Source

pub const fn parameters(&self) -> &Parameters

Returns the stream’s codec parameters — the handle a decoder is opened from.

Source

pub const fn with_disposition(self, value: i32) -> Self

Sets the disposition bits (consuming builder).

Source

pub const fn with_start_time(self, value: Option<i64>) -> Self

Sets the start time (consuming builder).

Source

pub const fn with_frame_count(self, value: Option<i64>) -> Self

Sets the frame count (consuming builder).

Source

pub const fn set_disposition(&mut self, value: i32) -> &mut Self

Sets the disposition bits in place.

Source

pub const fn set_start_time(&mut self, value: Option<i64>) -> &mut Self

Sets the start time in place.

Source

pub const fn set_frame_count(&mut self, value: Option<i64>) -> &mut Self

Sets the frame count in place.

Trait Implementations§

Source§

impl Debug for TrackExtra

Source§

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

Hand-written because Parameters does not derive Debug. The medium and codec id are the two fields worth printing; the rest of AVCodecParameters is per-kind detail the track row already carries in typed form.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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