From 19d5a9aba34d06e95e13b90aa991aa8084cf33bf Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 23 Mar 2013 19:05:38 +0100 Subject: [PATCH] Fix mpeg audio header parser, only pass a single frame to libav decoder --- audioomx.cc | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 68d3c56..751c61c 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -1581,7 +1581,7 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const UCHAR *data,unsigned int size,un int lsf=0; int mpeg2=0; int layer=4-(data[test+2]&0x03)>>1; - int bitrate_index=data[test+2]&0xf0>>4; + 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; @@ -1591,18 +1591,20 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const UCHAR *data,unsigned int size,un mpeg2=1; } int sample_rate=sample_rates[ (data[test+2]&0x0C)>>2]>>(lsf+mpeg2); - int frame_size=bitrate_tab[lsf][layer - 1][bitrate_index]; + int frame_size=0; + int temp_frame_size=bitrate_tab[lsf][layer - 1][bitrate_index]; if (layer==1) { - frame_size=(frame_size*12000)/sample_rate; + frame_size=(temp_frame_size*12000)/sample_rate; frame_size=(frame_size+padding)*4; } else if (layer==2) { - frame_size=(frame_size*144000)/sample_rate; + frame_size=(temp_frame_size*144000)/sample_rate; frame_size=frame_size+padding; } else { - frame_size=(frame_size*144000)/(sample_rate<log("Audio", Log::DEBUG, "FRAME: %d %d %d %d %d %d",lsf,layer,bitrate_index,sample_rate,padding,framesize); + //Log::getInstance()->log("Audio", Log::DEBUG, "FRAME: %d %d %d %d %d %d %d",lsf,layer,bitrate_index,sample_rate,padding,temp_frame_size, frame_size); + //Log::getInstance()->log("Audio", Log::DEBUG, "FRAME DIAG: %x %x %x ",data[test],data[test+1],data[test+2]); *framesize=frame_size; return test; // probably FrameSync @@ -2043,7 +2045,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, bool donotdecompress=false; unsigned int gotframesize=0; - if (!decompress_buffer_filled) { // only do this if no old data is present + // if (!decompress_buffer_filled) { // only do this if no old data is present int adv = 0; switch (packet.type) { case MPTYPE_MPEG_AUDIO: @@ -2064,7 +2066,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } break; }; - if (adv > 0) { + if (adv > 0 /*&& !decompress_buffer_filled*/) { incoming_paket_libav.data += adv; incoming_paket_libav.size-=adv; haveToCopy -= adv; @@ -2079,7 +2081,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } - } // + // } // if (gotframesize>0 && gotframesize>haveToCopy) { donotdecompress=true; @@ -2102,8 +2104,19 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } libav_mutex.Unlock(); // Log::getInstance()->log("Audio", Log::DEBUG,"libav out"); - len = avcodec_decode_audio4(current_context, decode_frame_libav, + int save_size=incoming_paket_libav.size; + + if (gotframesize<=incoming_paket_libav.size) { + if (gotframesize>0) incoming_paket_libav.size=gotframesize; + len = avcodec_decode_audio4(current_context, decode_frame_libav, &gotta, &incoming_paket_libav); + } else { + //Log::getInstance()->log("Audio", Log::DEBUG, "FRAME:E %d %d",gotframesize,incoming_paket_libav.size); + gotta=0; + len=0; + } + //Log::getInstance()->log("Audio", Log::DEBUG, "FRAME:T %d",len); + incoming_paket_libav.size=save_size; //Log::getInstance()->log("Audio", Log::DEBUG, "libav out1"); pthread_setcancelstate(oldcancelstate, NULL); pthread_setcanceltype(oldcanceltype, NULL); @@ -2122,7 +2135,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, if (decompress_buffer_filled) { // reset to normal decoding if (len>0) { - Log::getInstance()->log("Audio", Log::DEBUG,"saved audio: %d",len); + //Log::getInstance()->log("Audio", Log::DEBUG,"saved audio: %d",len); haveToCopy -= min(len-decompress_buffer_filled,0); *samplepos += min(len-decompress_buffer_filled,0); //if (current_context->frame_size>0) framesize=min(current_context->frame_size,haveToCopy); -- 2.39.5