[READ-ONLY] Mirror of https://github.com/probablykasper/redlux. AAC decoder for MPEG-4 and AAC files, with rodio support
aac audio decoder mp4 package
0

Configure Feed

Select the types of activity you want to include in your feed.

Remove panic

Kasper (Apr 5, 2021, 7:53 PM +0200) 4e747098 c3386ec6

+14 -7
+9 -6
src/adts.rs
··· 1 1 use mp4::{AudioObjectType, ChannelConfig, Mp4Sample, SampleFreqIndex}; 2 2 use std::ops::Range; 3 + use crate::Error; 3 4 4 5 fn get_bits(byte: u16, range: Range<u16>) -> u16 { 5 6 let shaved_left = byte << range.start - 1; ··· 20 21 sample_freq_index: SampleFreqIndex, 21 22 channel_config: ChannelConfig, 22 23 sample: &Mp4Sample, 23 - ) -> Vec<u8> { 24 + ) -> Result<Vec<u8>, Error> { 24 25 // ADTS header wiki reference: https://wiki.multimedia.cx/index.php/ADTS#:~:text=Audio%20Data%20Transport%20Stream%20(ADTS,to%20stream%20audio%2C%20usually%20AAC. 25 26 26 27 // byte7 and byte9 not included without CRC ··· 40 41 AudioObjectType::AacLowComplexity => 2, 41 42 AudioObjectType::AacScalableSampleRate => 3, 42 43 AudioObjectType::AacLongTermPrediction => 4, 43 - // types 5 (SBR) and 29 (PS) can be coerced down to type 2 (AAC-LC) 44 - AudioObjectType::SpectralBandReplication => 2, 45 - AudioObjectType::ParametricStereo => 2, 46 - x => panic!("Unsupported object type {}", x), 44 + // Audio object types 5 (SBR) and 29 (PS) are coerced to type 2 (AAC-LC). 45 + // The decoder will have to detect SBR/PS. This is called "Implicit 46 + // Signaling" and it's the only option for ADTS. 47 + AudioObjectType::SpectralBandReplication => 2, // SBR, needed to support HE-AAC v1 48 + AudioObjectType::ParametricStereo => 2, // PS, needed to support HE-AAC v2 49 + aot => return Err(Error::UnsupportedObjectType(aot)), 47 50 }; 48 51 let adts_object_type = object_type - 1; 49 52 byte2 = (byte2 << 2) | adts_object_type; // EE ··· 102 105 byte6 = (byte6 << 6) | 0b111111; // OOOOOO 103 106 byte6 = (byte6 << 2) | 0b00; // PP 104 107 105 - return vec![byte0, byte1, byte2, byte3, byte4, byte5, byte6]; 108 + return Ok(vec![byte0, byte1, byte2, byte3, byte4, byte5, byte6]) 106 109 }
+5 -1
src/lib.rs
··· 1 1 //! AAC decoder for MPEG-4 (MP4, M4A etc) and AAC files. Supports rodio. 2 2 use fdk_aac::dec::{Decoder as AacDecoder, DecoderError, Transport}; 3 + use mp4::AudioObjectType; 3 4 use std::io::{Read, Seek}; 4 5 use std::time::Duration; 5 6 use std::{error, fmt, io}; ··· 14 15 /// Unable to get information about a track, such as audio profile, sample 15 16 /// frequency or channel config. 16 17 TrackReadingError, 18 + /// Unsupported audio object type 19 + UnsupportedObjectType(AudioObjectType), 17 20 // Unable to find track in file 18 21 TrackNotFound, 19 22 /// Error decoding track ··· 31 34 match &self { 32 35 Error::FileHeaderError => "Error reading file header", 33 36 Error::TrackReadingError => "Error reading file track info", 37 + Error::UnsupportedObjectType(_) => "Unsupported audio object type", 34 38 Error::TrackNotFound => "Unable to find track in file", 35 39 Error::TrackDecodingError(_) => "Error decoding track", 36 40 Error::SamplesError => "Error reading samples", ··· 176 180 sample_freq_index, 177 181 channel_config, 178 182 &sample, 179 - ); 183 + )?; 180 184 let adts_bytes = mp4::Bytes::copy_from_slice(&adts_header); 181 185 self.bytes = [adts_bytes, sample.bytes].concat(); 182 186 self.position += 1;