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
impl TrackExtra
Sourcepub fn new(
stream_index: i32,
parameters: Parameters,
) -> Result<Self, DemuxError>
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.
Sourcepub fn try_clone(&self) -> Result<Self, DemuxError>
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.
Sourcepub fn clone_parameters(&self) -> Result<Parameters, DemuxError>
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.
Sourcepub const fn stream_index(&self) -> i32
pub const fn stream_index(&self) -> i32
Returns the source AVStream.index.
Sourcepub const fn disposition(&self) -> i32
pub const fn disposition(&self) -> i32
Returns the raw AVStream.disposition bit set.
Sourcepub const fn start_time(&self) -> Option<i64>
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.
Sourcepub const fn frame_count(&self) -> Option<i64>
pub const fn frame_count(&self) -> Option<i64>
Returns AVStream.nb_frames when the container carries it.
Sourcepub const fn parameters(&self) -> &Parameters
pub const fn parameters(&self) -> &Parameters
Returns the stream’s codec parameters — the handle a decoder is opened from.
Sourcepub const fn with_disposition(self, value: i32) -> Self
pub const fn with_disposition(self, value: i32) -> Self
Sets the disposition bits (consuming builder).
Sourcepub const fn with_start_time(self, value: Option<i64>) -> Self
pub const fn with_start_time(self, value: Option<i64>) -> Self
Sets the start time (consuming builder).
Sourcepub const fn with_frame_count(self, value: Option<i64>) -> Self
pub const fn with_frame_count(self, value: Option<i64>) -> Self
Sets the frame count (consuming builder).
Sourcepub const fn set_disposition(&mut self, value: i32) -> &mut Self
pub const fn set_disposition(&mut self, value: i32) -> &mut Self
Sets the disposition bits in place.
Sourcepub const fn set_start_time(&mut self, value: Option<i64>) -> &mut Self
pub const fn set_start_time(&mut self, value: Option<i64>) -> &mut Self
Sets the start time in place.
Sourcepub const fn set_frame_count(&mut self, value: Option<i64>) -> &mut Self
pub const fn set_frame_count(&mut self, value: Option<i64>) -> &mut Self
Sets the frame count in place.