Trait creek_core::Encoder[][src]

pub trait Encoder: 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_WRITE_BLOCKS: usize;

    fn new(
        file: PathBuf,
        num_channels: u16,
        sample_rate: u32,
        block_size: usize,
        num_write_blocks: usize,
        additional_opts: Self::AdditionalOpts
    ) -> Result<(Self, FileInfo<Self::FileParams>), Self::OpenError>;
unsafe fn encode(
        &mut self,
        write_block: &WriteBlock<Self::T>
    ) -> Result<WriteStatus, Self::FatalError>;
fn finish_file(&mut self) -> Result<(), Self::FatalError>;
fn discard_file(&mut self) -> Result<(), Self::FatalError>;
fn discard_and_restart(&mut self) -> Result<(), Self::FatalError>; }
Expand description

A type that encodes a file in a write stream.

Associated Types

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

Any additional options for creating a file with this encoder.

Any additional information on the file.

The error type while opening the file.

The error type when a fatal error occurs.

Associated Constants

The default number of frames in a write block.

The default number of write blocks. This must be sufficiently large to ensure there are enough write blocks for the client in the worst case write latency scenerio.

Required methods

Open the file for writing.

  • file - The path of the file to open.
  • num_channels - The number of audio channels in the file.
  • sample_rate - The sample rate of the audio data.
  • block_size - The block size to use.
  • max_num_write_blocks - The number of write blocks this stream is using.
  • additional_opts - Any additional encoder-specific options.

Write a block of data to the file.

If the write was successful, return WriteStatus::Ok.

If the codec has a maximum file size (i.e. 4GB for WAV), then keep track of how many bytes were written. Once the file is full (or about full), finish the file, close it, and create a new file with the characters “_XXX” appended to the file name (i.e. “_001” for the first file, “_002” for the second, etc.) This helper function num_files_to_file_name_extension() can be used to find this extension.

Unsafe

This is marked as “unsafe” because a data_block may be uninitialized, causing undefined behavior if unwritten data from the block is read. Please use the value from write_block.num_frames() to know how many frames in the block are valid. (valid frames are from [0..num_frames])

Finish up the file and then close it.

Delete all created files. Do not start over.

Delete all created files and start over from the beginning.

Implementors