OSDN Git Service

fix qdm2 audio decoding
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 25 Apr 2010 01:10:25 +0000 (01:10 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 25 Apr 2010 01:10:25 +0000 (01:10 +0000)
it seems ffmpeg wants to be passed the same buffer repeatedly
while decoding this audio type.  we were exiting if ffmpeg said it
consumed 0 bytes.  Now we continue to feed the same buffer when
this happens.  I added a loop limit to protect against an hypothetical
ffmpeg bug that would never consume anything. I wonder if any other
codecs behave this way *scratches head in bewilderment*

git-svn-id: svn://localhost/HandBrake/trunk@3264 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/decavcodec.c

index 91949fb..a506154 100644 (file)
@@ -1172,6 +1172,7 @@ static void decodeAudio( hb_audio_t * audio, hb_work_private_t *pv, uint8_t *dat
 {
     AVCodecContext *context = pv->context;
     int pos = 0;
+    int loop_limit = 256;
 
     while ( pos < size )
     {
@@ -1190,10 +1191,18 @@ static void decodeAudio( hb_audio_t * audio, hb_work_private_t *pv, uint8_t *dat
         int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
         int nsamples;
         int len = avcodec_decode_audio3( context, buffer, &out_size, &avp );
-        if ( len <= 0 )
+        if ( len < 0 )
         {
             return;
         }
+        if ( len == 0 )
+        {
+            if ( !(loop_limit--) )
+                return;
+        }
+        else
+            loop_limit = 256;
+
         pos += len;
         if( out_size > 0 )
         {