]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Implement missing case for decoding samples with large pivot value in APE
authorkostya <kostya@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Fri, 20 Nov 2009 07:49:53 +0000 (07:49 +0000)
committerkostya <kostya@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Fri, 20 Nov 2009 07:49:53 +0000 (07:49 +0000)
decoder.
This fixes issue 1555

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@20560 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavcodec/apedec.c

index 1e21e6a401a31a7c9daa0c92543a09ae384f43ba..20ebe9ed67385a39c8d75bc4694f6e09633043c5 100644 (file)
@@ -408,8 +408,24 @@ static inline int ape_decode_value(APEContext * ctx, APERice *rice)
             overflow |= range_decode_bits(ctx, 16);
         }
 
-        base = range_decode_culfreq(ctx, pivot);
-        range_decode_update(ctx, 1, base);
+        if (pivot < 0x10000) {
+            base = range_decode_culfreq(ctx, pivot);
+            range_decode_update(ctx, 1, base);
+        } else {
+            int base_hi = pivot, base_lo;
+            int bbits = 0;
+
+            while (base_hi & ~0xFFFF) {
+                base_hi >>= 1;
+                bbits++;
+            }
+            base_hi = range_decode_culfreq(ctx, base_hi + 1);
+            range_decode_update(ctx, 1, base_hi);
+            base_lo = range_decode_culfreq(ctx, 1 << bbits);
+            range_decode_update(ctx, 1, base_lo);
+
+            base = (base_hi << bbits) + base_lo;
+        }
 
         x = base + overflow * pivot;
     }