vapor-parser 0.1.0

A parser for MPEG files
Documentation
#[derive(Debug, Clone)]
pub struct AudioFrameHeader {
    pub version: MpegVersion,
    pub layer: MpegLayer,
    pub protected: bool,
    pub bitrate: BitRate,
    pub sample_rate: SampleRate,
    pub padding: u8,
    pub private: bool,
    pub channel_mode: ChannelMode,
    pub mode_extension: Option<ModeExtension>,
    pub copyrigth: bool,
    pub original: bool,
    pub emphasis: Emphasis,
}

#[derive(Debug, Clone)]
pub struct AudioFrame {
    pub header: AudioFrameHeader,
    pub xing_header: Option<XingHeader>,
    pub offset: u64,
    pub data: Vec<u8>,
}

#[derive(Debug, Clone)]
pub struct XingHeader {
    pub flags: XingHeaderFlags,
    pub frames: Option<u64>,
    pub bytes: Option<u64>,
    pub toc: Option<[u8; 100]>,
    pub quality: Option<u32>,
    pub sample_rate: Option<u32>,
    pub channels: Option<u32>,
    pub vbr_scale: Option<u32>,
}

#[derive(Debug, Clone)]
pub struct XingHeaderFlags {
    pub frames: bool,
    pub bytes: bool,
    pub toc: bool,
    pub quality: bool,
    pub sample_rate: bool,
    pub channels: bool,
    pub vbr_scale: bool,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum MpegVersion {
    Mpeg1,
    Mpeg2,
    Mpeg2_5,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum MpegLayer {
    NotDefined,
    Layer1,
    Layer2,
    Layer3,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum BitRate {
    Kbps8,
    Kbps16,
    Kbps24,
    Kbps32,
    Kbps40,
    Kbps48,
    Kbps56,
    Kbps64,
    Kbps65,
    Kbps80,
    Kbps96,
    Kbps112,
    Kbps128,
    Kbps144,
    Kbps160,
    Kbps176,
    Kbps192,
    Kbps224,
    Kbps256,
    Kbps284,
    Kbps288,
    Kbps320,
    Kbps352,
    Kbps384,
    Kbps416,
    Kbps448,
}

impl BitRate {
    pub fn bps(self) -> u64 {
        match self {
            BitRate::Kbps8 => 8_000,
            BitRate::Kbps16 => 16_000,
            BitRate::Kbps24 => 24_000,
            BitRate::Kbps32 => 32_000,
            BitRate::Kbps40 => 40_000,
            BitRate::Kbps48 => 48_000,
            BitRate::Kbps56 => 56_000,
            BitRate::Kbps64 => 64_000,
            BitRate::Kbps65 => 65_000,
            BitRate::Kbps80 => 80_000,
            BitRate::Kbps96 => 96_000,
            BitRate::Kbps112 => 112_000,
            BitRate::Kbps128 => 128_000,
            BitRate::Kbps144 => 144_000,
            BitRate::Kbps160 => 160_000,
            BitRate::Kbps176 => 176_000,
            BitRate::Kbps192 => 192_000,
            BitRate::Kbps224 => 224_000,
            BitRate::Kbps256 => 256_000,
            BitRate::Kbps284 => 284_000,
            BitRate::Kbps288 => 288_000,
            BitRate::Kbps320 => 320_000,
            BitRate::Kbps352 => 352_000,
            BitRate::Kbps384 => 384_000,
            BitRate::Kbps416 => 416_000,
            BitRate::Kbps448 => 448_000,
        }
    }
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SampleRate {
    Hz8000,
    Hz11025,
    Hz12000,
    Hz16000,
    Hz22050,
    Hz24000,
    Hz32000,
    Hz44100,
    Hz48000,
}

impl SampleRate {
    pub fn hz(self) -> u64 {
        match self {
            SampleRate::Hz8000 => 8_000,
            SampleRate::Hz11025 => 11_025,
            SampleRate::Hz12000 => 12_000,
            SampleRate::Hz16000 => 16_000,
            SampleRate::Hz22050 => 22_050,
            SampleRate::Hz24000 => 24_000,
            SampleRate::Hz32000 => 32_000,
            SampleRate::Hz44100 => 44_100,
            SampleRate::Hz48000 => 48_000,
        }
    }
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum ChannelMode {
    Stereo,
    JointStereo,
    DualChannel,
    Mono,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum ModeExtension {
    Bands4To31,
    Bands8To31,
    Bands12To31,
    Bands16To31,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Emphasis {
    None,
    FiftyFifteenMs,
    Reserved,
    CCITJ17,
}