From 47fa0ec6ac0901ab5c653a034d61c45de4929887 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 9 Mar 2013 17:37:59 +0100 Subject: [PATCH] Add mpeg audio header parser --- audioomx.cc | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 5e5926b..cf4f564 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -1566,8 +1566,46 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const UCHAR *data,unsigned int size,un if (size<=2) return size; // silly; unsigned int test=0; *framesize=0; + //inspired by libav parsing code while (test+1>1; + int bitrate_index=data[test+2]&0xf0>>4; + int padding=(data[test+2]&2)>>1; + if (0x10 & data[test+1]) { + lsf=((data[test+1]) &0x8)?0:1; + mpeg2=0; + } else { + lsf=1; + mpeg2=1; + } + int sample_rate=sample_rates[ (data[test+2]&0x0C)>>2]>>(lsf+mpeg2); + int frame_size=bitrate_tab[lsf][layer - 1][bitrate_index]; + if (layer==1) { + frame_size=(frame_size*12000)/sample_rate; + frame_size=(frame_size+padding)*4; + } else if (layer==2) { + frame_size=(frame_size*144000)/sample_rate; + frame_size=frame_size+padding; + } else { + frame_size=(frame_size*144000)/(sample_rate<log("Audio", Log::DEBUG,"Use saved audio buffer %d %d %d",packet.type,decompress_buffer_filled,packet.synced); + //Log::getInstance()->log("Audio", Log::DEBUG,"Use saved audio buffer %d %d %d",packet.type,decompress_buffer_filled,packet.synched); } else { incoming_paket_libav.data =(uint8_t*) buffer+packet.pos_buffer+*samplepos; incoming_paket_libav.size = haveToCopy; -- 2.39.5