Trait creek_core::read::Decoder

source ·
pub trait Decoder: Sized + 'static {
    type T: Copy + Clone + Default + Send;
    type AdditionalOpts: Send + Default + Debug;
    type FileParams: Clone + Send;
    type OpenError: Error + Send;
    type FatalError: Error + Send;

    const DEFAULT_BLOCK_SIZE: usize;
    const DEFAULT_NUM_CACHE_BLOCKS: usize;
    const DEFAULT_NUM_LOOK_AHEAD_BLOCKS: usize;

    // Required methods
    fn new(
        file: PathBuf,
        start_frame: usize,
        block_size: usize,
        additional_opts: Self::AdditionalOpts
    ) -> Result<(Self, FileInfo<Self::FileParams>), Self::OpenError>;
    fn seek(&mut self, frame: usize) -> Result<(), Self::FatalError>;
    fn decode(
        &mut self,
        data_block: &mut DataBlock<Self::T>
    ) -> Result<(), Self::FatalError>;
    fn current_frame(&self) -> usize;
}
Expand description

A type that decodes a file in a read stream.

Required Associated Types§

source

type T: Copy + Clone + Default + Send

The data type of a single sample. (i.e. f32)

source

type AdditionalOpts: Send + Default + Debug

Any additional options for opening a file with this decoder.

source

type FileParams: Clone + Send

Any additional information on the file.

source

type OpenError: Error + Send

The error type while opening the file.

source

type FatalError: Error + Send

The error type when a fatal error occurs.

Required Associated Constants§

source

const DEFAULT_BLOCK_SIZE: usize

The default number of frames in a prefetch block.

source

const DEFAULT_NUM_CACHE_BLOCKS: usize

The default number of prefetch blocks in a cache block. This will cause a cache to be used whenever the stream is seeked to a frame in the range:

[cache_start, cache_start + (num_cache_blocks * block_size))

If this is 0, then the cache is only used when seeked to exactly cache_start.

source

const DEFAULT_NUM_LOOK_AHEAD_BLOCKS: usize

The number of prefetch blocks to store ahead of the cache block. This must be sufficiently large to ensure enough to time to fill the buffer in the worst case latency scenerio.

Required Methods§

source

fn new( file: PathBuf, start_frame: usize, block_size: usize, additional_opts: Self::AdditionalOpts ) -> Result<(Self, FileInfo<Self::FileParams>), Self::OpenError>

Open the file and start reading from start_frame.

Please note this algorithm depends on knowing the exact number of frames in a file. Do not return an approximate length in the returned FileInfo.

source

fn seek(&mut self, frame: usize) -> Result<(), Self::FatalError>

Seek to a frame in the file. If a frame lies outside of the end of the file, set the read position the end of the file instead of returning an error.

source

fn decode( &mut self, data_block: &mut DataBlock<Self::T> ) -> Result<(), Self::FatalError>

Decode data into the data_block starting from your current internal read position. This is streaming, meaning the next call to decode() should pick up where the previous left off.

Fill each channel in the data block with block_size number of frames (you should have gotten this value from Decoder::new()). If there isn’t enough data left because the end of the file has been reached, then only fill up how ever many frames are left. If the end of the file has already been reached since the last call to decode(), then do nothing.

Each channel Vec in data_block will have a length of zero.

source

fn current_frame(&self) -> usize

Return the current read position.

Object Safety§

This trait is not object safe.

Implementors§