From ed88e41fc52567cc9dd3e04d66e75238130259f4 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 23 Nov 2013 13:56:25 +0100 Subject: [PATCH] Detect mpeg audio frame header changes, and wait at least 4 packets after a change for audio output --- audioomx.cc | 24 +++++++++++++++++++++--- audioomx.h | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 09a66ea..4703bbf 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -64,6 +64,8 @@ AudioOMX::AudioOMX() decompress_buffer=NULL; decompress_buffer_size=0; decompress_buffer_filled=0; + mp3sameheader=0; + mp3sameheadercount=0; } @@ -1579,6 +1581,9 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const UCHAR *data,unsigned int size,un //inspired by libav parsing code while (test+1log("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; + //Log::getInstance()->log("Audio", Log::DEBUG, "FRAME DIAG: %x %x %x %d",data[test],data[test+1],data[test+2],mp3sameheadercount); - return test; // probably FrameSync + if (mp3sameheadercount>4) { + *framesize=frame_size; + return test; // probably FrameSync + } //skip it if the header changes too frequently } test++; } @@ -1829,6 +1846,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, if (packet.type != lastAType) {//Format Change //Push data out ! firstsynched = false; achange=true; + mp3sameheader=0; Log::getInstance()->log("Audio", Log::DEBUG,"Notice audio type change %d %d", packet.type,lastAType); lastAType = packet.type; decompress_buffer_filled=0; diff --git a/audioomx.h b/audioomx.h index 42f525b..b6b01e0 100644 --- a/audioomx.h +++ b/audioomx.h @@ -198,6 +198,9 @@ class AudioOMX : public Audio unsigned int decompress_buffer_filled; bool lsync; + unsigned int mp3sameheader; + int mp3sameheadercount; + int InitDecoderLibAV(); void DeinitDecoderLibAV(); -- 2.39.5