[FFmpeg-cvslog] vble: merge len and val arrays

Derek Buitenhuis git at videolan.org
Fri Dec 2 01:00:51 CET 2011


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Wed Nov 30 17:28:49 2011 -0500| [e46abbcf77141a33ac21bbe1b71bdf934a658fb9] | committer: Ronald S. Bultje

vble: merge len and val arrays

There's no reason to use two arrays for this.

Based off commit 2fea60c60084c4e70d7cef128ea3bca5690ce465
to FFmpeg by Michael Niedermayer.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>

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

 libavcodec/vble.c |   25 ++++++-------------------
 1 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/libavcodec/vble.c b/libavcodec/vble.c
index 839af2b..09a9499 100644
--- a/libavcodec/vble.c
+++ b/libavcodec/vble.c
@@ -34,8 +34,7 @@ typedef struct {
 
     int            size;
     int            flags;
-    uint8_t        *len;
-    uint8_t        *val;
+    uint8_t        *val; /* First holds the lengths of vlc symbols and then their values */
 } VBLEContext;
 
 static uint8_t vble_read_reverse_unary(GetBitContext *gb)
@@ -63,23 +62,20 @@ static int vble_unpack(VBLEContext *ctx, GetBitContext *gb)
 
     /* Read all the lengths in first */
     for (i = 0; i < ctx->size; i++) {
-        ctx->len[i] = vble_read_reverse_unary(gb);
+        ctx->val[i] = vble_read_reverse_unary(gb);
 
-        if (ctx->len[i] == UINT8_MAX)
+        if (ctx->val[i] == UINT8_MAX)
             return -1;
     }
 
-    /* For any values that have length 0 */
-    memset(ctx->val, 0, ctx->size);
-
     for (i = 0; i < ctx->size; i++) {
         /* Check we have enough bits left */
-        if (get_bits_left(gb) < ctx->len[i])
+        if (get_bits_left(gb) < ctx->val[i])
             return -1;
 
         /* get_bits can't take a length of 0 */
-        if (ctx->len[i])
-            ctx->val[i] = (1 << ctx->len[i]) + get_bits(gb, ctx->len[i]) - 1;
+        if (ctx->val[i])
+            ctx->val[i] = (1 << ctx->val[i]) + get_bits(gb, ctx->val[i]) - 1;
     }
 
     return 0;
@@ -188,7 +184,6 @@ static av_cold int vble_decode_close(AVCodecContext *avctx)
         avctx->release_buffer(avctx, pic);
 
     av_freep(&avctx->coded_frame);
-    av_freep(&ctx->len);
     av_freep(&ctx->val);
 
     return 0;
@@ -214,14 +209,6 @@ static av_cold int vble_decode_init(AVCodecContext *avctx)
     ctx->size = avpicture_get_size(avctx->pix_fmt,
                                    avctx->width, avctx->height);
 
-    ctx->len = av_malloc(ctx->size * sizeof(*ctx->len));
-
-    if (!ctx->len) {
-        av_log(avctx, AV_LOG_ERROR, "Could not allocate lengths buffer.\n");
-        vble_decode_close(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     ctx->val = av_malloc(ctx->size * sizeof(*ctx->val));
 
     if (!ctx->val) {



More information about the ffmpeg-cvslog mailing list