embedded_audio_driver/decoder.rs
1use crate::Result;
2use crate::stream::AudioFormat;
3
4/// Decoder information and capabilities
5#[derive(Debug, Clone)]
6pub struct DecoderInfo {
7 /// List of supported input formats (e.g., "MP3", "WAV")
8 pub supported_formats: &'static [&'static str],
9 /// Output audio format specification
10 pub output_format: AudioFormat,
11}
12
13/// Decoder runtime state
14#[derive(Debug, Clone, Copy)]
15pub struct DecoderState {
16 /// Total number of samples in the stream
17 pub total_samples: u64,
18 /// Number of samples decoded so far
19 pub decoded_samples: u64,
20 /// Current bitrate in bits per second
21 pub current_bitrate: u32,
22}
23
24/// Audio decoder interface
25///
26/// This trait defines the operations for audio decoders,
27/// supporting initialization, decoding, and state management.
28pub trait Decoder {
29 /// Initialize the decoder
30 fn init(&mut self) -> Result<()>;
31
32 /// Decode a block of input data
33 /// Returns the number of bytes written to output
34 fn decode(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize>;
35
36 /// Get decoder capabilities and information
37 fn get_info(&self) -> DecoderInfo;
38
39 /// Get current decoder state
40 fn get_state(&self) -> Result<DecoderState>;
41
42 /// Reset decoder to initial state
43 fn reset(&mut self) -> Result<()>;
44}