Access Unit
A Rust library for handling audio codec frames, with support for AAC and FLAC formats. The library provides utilities for frame detection, parsing, and manipulation, with a focus on broadcast and streaming applications.
Features
- Automatic audio codec detection (AAC, FLAC, MP3) including MP4 container audio detection
- AAC ADTS frame handling and validation
- FLAC frame parsing and manipulation
- MP3 frame header parsing and detection
- Support for FMP4 container format
- Access Unit abstraction for media streaming
Audio Codec Support
AAC Support
- ADTS header parsing and validation
- Frame extraction and manipulation
- Support for common profiles (AAC-LC, HE-AAC v1/v2)
- Sample rate detection and validation
- Channel configuration handling
FLAC Support
- Frame header parsing
- Block size handling
- Sample rate and channel configuration
- Bits per sample validation
- UTF-8 coded sample/frame numbers
- CRC validation
MP3 Support
- Frame header validation (sync, version, layer, bitrate, sample rate)
- Frame length calculation
- Frame detection within arbitrary byte streams
Usage
Detecting Audio Type
use detect_audio;
let data: & = // your audio data
let audio_type = detect_audio;
match audio_type
Detecting MP4 Container Audio
use mp4;
let data: & = // MP4 data
if is_mp4
Working with AAC Frames
use aac;
// Check if data is valid AAC
if is_aac
FLAC Frame Handling
use flac;
// Parse FLAC frame header
let frame_info = decode_frame_header?;
// Split FLAC stream into frames
let frames = split_flac_frames;
// Extract single FLAC frame
let frame = extract_flac_frame;
// Create STREAMINFO metadata block
let streaminfo = create_streaminfo;
MP3 Frame Detection
use mp3;
if let Some = find_frame
Access Unit Handling
use AccessUnit;
let unit = AccessUnit ;
Frame Header Formats
AAC ADTS Header
|--- Sync Word (12 bits) ---|
|--- ID (1 bit) ---|
|--- Layer (2 bits) ---|
|--- Protection Absent (1 bit) ---|
|--- Profile (2 bits) ---|
|--- Sampling Frequency Index (4 bits) ---|
|--- Private Bit (1 bit) ---|
|--- Channel Configuration (3 bits) ---|
|--- Original/Copy (1 bit) ---|
|--- Home (1 bit) ---|
FLAC Frame Header
|--- Sync Code (15 bits) ---|
|--- Reserved (1 bit) ---|
|--- Block Size (4 bits) ---|
|--- Sample Rate (4 bits) ---|
|--- Channel Assignment (4 bits) ---|
|--- Sample Size (3 bits) ---|
|--- Reserved (1 bit) ---|
License
MIT