[FFmpeg-cvslog] alac: limit the rice param before passing to decode_scalar()

Justin Ruggles git at videolan.org
Thu Jul 19 23:35:49 CEST 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Mon Jul  9 10:33:28 2012 -0400| [d9837434a91dbb3632df335414aad538e5b0a6e9] | committer: Justin Ruggles

alac: limit the rice param before passing to decode_scalar()

reduces the number of parameters to decode_scalar() and slightly simplifies
the code

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d9837434a91dbb3632df335414aad538e5b0a6e9
---

 libavcodec/alac.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 8824ae8..76ef499 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -77,17 +77,14 @@ typedef struct {
     int extra_bits;                         /**< number of extra bits beyond 16-bit */
 } ALACContext;
 
-static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){
+static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
+{
     int x = get_unary_0_9(gb);
 
     if (x > 8) { /* RICE THRESHOLD */
         /* use alternative encoding */
         x = get_bits(gb, readsamplesize);
-    } else {
-        if (k >= limit)
-            k = limit;
-
-        if (k != 1) {
+    } else if (k != 1) {
             int extrabits = show_bits(gb, k);
 
             /* multiply x by 2^k - 1, as part of their strange algorithm */
@@ -98,7 +95,6 @@ static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsam
                 skip_bits(gb, k);
             } else
                 skip_bits(gb, k - 1);
-        }
     }
     return x;
 }
@@ -123,7 +119,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
         /* read k, that is bits as is */
         k = av_log2((history >> 9) + 3);
-        x = decode_scalar(&alac->gb, k, alac->rice_limit, readsamplesize);
+        k = FFMIN(k, alac->rice_limit);
+        x = decode_scalar(&alac->gb, k, readsamplesize);
 
         x_modified = sign_modifier + x;
         final_val = (x_modified + 1) / 2;
@@ -148,8 +145,9 @@ static void bastardized_rice_decompress(ALACContext *alac,
             sign_modifier = 1;
 
             k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
+            k = FFMIN(k, alac->rice_limit);
 
-            block_size = decode_scalar(&alac->gb, k, alac->rice_limit, 16);
+            block_size = decode_scalar(&alac->gb, k, 16);
 
             if (block_size > 0) {
                 if(block_size >= output_size - output_count){



More information about the ffmpeg-cvslog mailing list