[FFmpeg-devel] [PATCH 037/114] avcodec/motionpixels: Simplify creating VLC tables
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Tue Nov 10 12:47:34 EET 2020
By using ff_init_vlc_from_lengths(), we do not have to keep track of the
codes themselves, but can offload this to ff_init_vlc_from_lengths().
Furthermore, the old code presumed sizeof(int) == 4; this is no longer
so.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/motionpixels.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index 927f9fdc14..3bc31870d9 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -29,7 +29,6 @@
#include "motionpixels_tablegen.h"
typedef struct HuffCode {
- int code;
uint8_t size;
uint8_t delta;
} HuffCode;
@@ -121,7 +120,7 @@ static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int
}
}
-static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code)
+static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size)
{
while (get_bits1(gb)) {
++size;
@@ -129,8 +128,7 @@ static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int
av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits);
return AVERROR_INVALIDDATA;
}
- code <<= 1;
- if (mp_get_code(mp, gb, size, code + 1) < 0)
+ if (mp_get_code(mp, gb, size) < 0)
return AVERROR_INVALIDDATA;
}
if (mp->current_codes_count >= mp->codes_count) {
@@ -138,7 +136,6 @@ static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int
return AVERROR_INVALIDDATA;
}
- mp->codes[mp->current_codes_count ].code = code;
mp->codes[mp->current_codes_count++].size = size;
return 0;
}
@@ -155,7 +152,7 @@ static int mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb)
for (i = 0; i < mp->codes_count; ++i)
mp->codes[i].delta = get_bits(gb, 4);
mp->current_codes_count = 0;
- if ((ret = mp_get_code(mp, gb, 0, 0)) < 0)
+ if ((ret = mp_get_code(mp, gb, 0)) < 0)
return ret;
if (mp->current_codes_count < mp->codes_count) {
av_log(mp->avctx, AV_LOG_ERROR, "too few codes\n");
@@ -321,10 +318,12 @@ static int mp_decode_frame(AVCodecContext *avctx,
goto end;
if (mp->codes_count > 1) {
- ret = ff_init_vlc_sparse(&mp->vlc, mp->max_codes_bits, mp->codes_count,
- &mp->codes[0].size, sizeof(HuffCode), 1,
- &mp->codes[0].code, sizeof(HuffCode), 4,
- &mp->codes[0].delta, sizeof(HuffCode), 1, 0);
+ /* The entries of the mp->codes array are sorted from right to left
+ * in the Huffman tree, hence -(int)sizeof(HuffCode). */
+ ret = ff_init_vlc_from_lengths(&mp->vlc, mp->max_codes_bits, mp->codes_count,
+ &mp->codes[mp->codes_count - 1].size, -(int)sizeof(HuffCode),
+ &mp->codes[mp->codes_count - 1].delta, -(int)sizeof(HuffCode), 1,
+ 0, 0);
if (ret < 0)
goto end;
}
--
2.25.1
More information about the ffmpeg-devel
mailing list