Trait creek_core::write::Encoder
source · 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;
// Required methods
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>;
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.
Required Associated Types§
sourcetype AdditionalOpts: Send + Default + Debug
type AdditionalOpts: Send + Default + Debug
Any additional options for creating a file with this encoder.
sourcetype FileParams: Clone + Send
type FileParams: Clone + Send
Any additional information on the file.
sourcetype FatalError: Error + Send
type FatalError: Error + Send
The error type when a fatal error occurs.
Required Associated Constants§
sourceconst DEFAULT_BLOCK_SIZE: usize
const DEFAULT_BLOCK_SIZE: usize
The default number of frames in a write block.
sourceconst DEFAULT_NUM_WRITE_BLOCKS: usize
const DEFAULT_NUM_WRITE_BLOCKS: usize
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§
sourcefn 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>
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>
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.
sourcefn encode(
&mut self,
write_block: &WriteBlock<Self::T>
) -> Result<WriteStatus, Self::FatalError>
fn encode( &mut self, write_block: &WriteBlock<Self::T> ) -> Result<WriteStatus, Self::FatalError>
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.
sourcefn finish_file(&mut self) -> Result<(), Self::FatalError>
fn finish_file(&mut self) -> Result<(), Self::FatalError>
Finish up the file and then close it.
sourcefn discard_file(&mut self) -> Result<(), Self::FatalError>
fn discard_file(&mut self) -> Result<(), Self::FatalError>
Delete all created files. Do not start over.
sourcefn discard_and_restart(&mut self) -> Result<(), Self::FatalError>
fn discard_and_restart(&mut self) -> Result<(), Self::FatalError>
Delete all created files and start over from the beginning.