aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-01 14:23:33 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:46 +0100
commit7a7295a8ce87e8b8d9f3dade5f7e05342ffba881 (patch)
treebbe76fcea04146d1fd60d7836f76e7753ec1c592 /libavcodec
parentf1ba4d479e4c785a8a4f85fb576ee166100a8cda (diff)
downloadffmpeg-7a7295a8ce87e8b8d9f3dade5f7e05342ffba881.tar.gz
avcodec/truemotion2: Simplify creating VLC table
ff_init_vlc_from_lengths() can be used to offload the computation of the codes; it also allows to omit the check whether the codes are already properly ordered (they are). In this case, this also allows to avoid the allocation of the buffer for the codes. This improves performance: The amount of decicycles for one call to tm2_build_huff_tables() when decoding tm20.avi from the FATE-suite decreased from 46239 to 40035. This test consisted of looping 50 times over the file and iterating the test ten times. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/truemotion2.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index ac3294d89c..012ad4ffde 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -108,15 +108,14 @@ typedef struct TM2Huff {
int num; ///< current number filled
int max_num; ///< total number of codes
int *nums; ///< literals
- uint32_t *bits; ///< codes
- int *lens; ///< codelengths
+ uint8_t *lens; ///< codelengths
} TM2Huff;
/**
*
* @returns the length of the longest code or an AVERROR code
*/
-static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
+static int tm2_read_tree(TM2Context *ctx, int length, TM2Huff *huff)
{
int ret, ret2;
if (length > huff->max_bits) {
@@ -134,14 +133,13 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *
return AVERROR_INVALIDDATA;
}
huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
- huff->bits[huff->num] = prefix;
huff->lens[huff->num] = length;
huff->num++;
return length;
} else { /* non-terminal node */
- if ((ret2 = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
+ if ((ret2 = tm2_read_tree(ctx, length + 1, huff)) < 0)
return ret2;
- if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
+ if ((ret = tm2_read_tree(ctx, length + 1, huff)) < 0)
return ret;
}
return FFMAX(ret, ret2);
@@ -177,15 +175,14 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
/* allocate space for codes - it is exactly ceil(nodes / 2) entries */
huff.max_num = (huff.nodes + 1) >> 1;
huff.nums = av_calloc(huff.max_num, sizeof(int));
- huff.bits = av_calloc(huff.max_num, sizeof(uint32_t));
- huff.lens = av_calloc(huff.max_num, sizeof(int));
+ huff.lens = av_mallocz(huff.max_num);
- if (!huff.nums || !huff.bits || !huff.lens) {
+ if (!huff.nums || !huff.lens) {
res = AVERROR(ENOMEM);
goto out;
}
- res = tm2_read_tree(ctx, 0, 0, &huff);
+ res = tm2_read_tree(ctx, 0, &huff);
if (res >= 0 && res != huff.max_bits) {
av_log(ctx->avctx, AV_LOG_ERROR, "Got less bits than expected: %i of %i\n",
@@ -200,9 +197,9 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
/* convert codes to vlc_table */
if (res >= 0) {
- res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
- huff.lens, sizeof(int), sizeof(int),
- huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
+ res = ff_init_vlc_from_lengths(&code->vlc, huff.max_bits, huff.max_num,
+ huff.lens, sizeof(huff.lens[0]),
+ NULL, 0, 0, 0, 0, ctx->avctx);
if (res < 0)
av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
else {
@@ -216,7 +213,6 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
out:
/* free allocated memory */
av_free(huff.nums);
- av_free(huff.bits);
av_free(huff.lens);
return res;