Skip to main content

FormatReader

Trait FormatReader 

Source
pub trait FormatReader: Send + Sync {
    // Required methods
    fn format_info(&self) -> &FormatInfo;
    fn media_info(&self) -> &MediaInfo;
    fn metadata(&mut self) -> Metadata<'_>;
    fn seek(&mut self, mode: SeekMode, to: SeekTo) -> Result<SeekedTo>;
    fn tracks(&self) -> &[Track];
    fn next_packet(&mut self) -> Result<Option<Packet>>;
    fn into_inner<'s>(self: Box<Self>) -> MediaSourceStream<'s> 
       where Self: 's;

    // Provided methods
    fn attachments(&self) -> &[Attachment] { ... }
    fn chapters(&self) -> Option<&ChapterGroup> { ... }
    fn first_track(&self, track_type: TrackType) -> Option<&Track> { ... }
    fn first_track_known_codec(&self, track_type: TrackType) -> Option<&Track> { ... }
    fn default_track(&self, track_type: TrackType) -> Option<&Track> { ... }
}
Expand description

A FormatReader is a media container demuxer. It provides methods to read a media container and iterate over the codec bitstream packets of all encapsulated tracks. Additionally, it provides methods to access any metadata, chapters, or attachments.

Most, if not all, media containers contain metadata, then a number of packetized, and interleaved codec bitstreams. These bitstreams are usually referred to as tracks. Generally, the encapsulated bitstreams are independently encoded using some codec. The allowed codecs for a container are defined in the specification of the container format.

While demuxing, packets are read one-by-one and may be discarded or decoded at the choice of the caller. The contents of a packet is undefined: it may be a frame of video, a millisecond of audio, or a subtitle, but a packet will never contain data from two different bitstreams. Therefore the caller can be selective in what tracks(s) should be decoded and consumed.

FormatReader provides an Iterator-like interface over packets for easy consumption and filtering. Seeking will invalidate the state of any Decoder processing packets from the FormatReader and should be reset after a successful seek operation.

Required Methods§

Source

fn format_info(&self) -> &FormatInfo

Get basic information about the container format.

Source

fn media_info(&self) -> &MediaInfo

Get information about the media as a whole.

Source

fn metadata(&mut self) -> Metadata<'_>

Gets the metadata revision log.

Source

fn seek(&mut self, mode: SeekMode, to: SeekTo) -> Result<SeekedTo>

Seek, as precisely as possible depending on the mode, to the Time or track TimeStamp requested. Returns the requested and actual TimeStamps seeked to, as well as the Track.

After a seek, all Decoders consuming packets from this reader should be reset.

Note: The FormatReader by itself cannot seek to an exact audio frame, it is only capable of seeking to the nearest Packet. Therefore, to seek to an exact frame, a Decoder must decode packets until the requested position is reached. When using the accurate SeekMode, the seeked position will always be at or before the requested position. If the coarse SeekMode is used, then the seek position may be after the requested position. Coarse seeking is an optional performance enhancement a reader may implement, therefore, a coarse seek may sometimes be an accurate seek.

Source

fn tracks(&self) -> &[Track]

Gets a list of tracks in the container.

Source

fn next_packet(&mut self) -> Result<Option<Packet>>

Reader the next packet from the container.

If Ok(None) is returned, the media has ended and no more packets will be produced until the reader is seeked to a new position.

If Err(ResetRequired) is returned, then the track list must be re-examined and all Decoders re-created. All other errors are unrecoverable.

Source

fn into_inner<'s>(self: Box<Self>) -> MediaSourceStream<'s>
where Self: 's,

Consumes the FormatReader and returns the underlying media source stream

Provided Methods§

Source

fn attachments(&self) -> &[Attachment]

Get a list of all attachments.

§For Implementations

The default implementation returns an empty slice.

Source

fn chapters(&self) -> Option<&ChapterGroup>

Get media chapters, if available.

§For Implementations

The default implementation returns None.

Source

fn first_track(&self, track_type: TrackType) -> Option<&Track>

Get the first track of a certain track type.

Source

fn first_track_known_codec(&self, track_type: TrackType) -> Option<&Track>

Get the first track of a certain track type with a known (non-null) codec.

Source

fn default_track(&self, track_type: TrackType) -> Option<&Track>

Get the default track of a certain track type.

§For Implementations

The default implementation of this function will return the first track of the desired track type with the default flag set, or if there is no track with the default flag set, the first track of the desired track type with a non-null codec ID. If no tracks are present then None is returned.

Most format reader implementations should not override the default implementation and instead set the default track flag appropriately.

Implementors§