From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/hq_hqa: Make VLC tables static
Date: Mon, 4 Mar 2024 13:46:01 +0100
Message-ID: <DU0P250MB0747E87DA695698B02D213618F232@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <DU0P250MB0747A7792ABE401083F1D9408F232@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/hq_hqa.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 510a66fd91..096fb65dc7 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -22,6 +22,7 @@
#include "libavutil/attributes.h"
#include "libavutil/mem_internal.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "bytestream.h"
@@ -53,11 +54,12 @@ typedef struct HQContext {
AVCodecContext *avctx;
HQDSPContext hqhqadsp;
- VLC hq_ac_vlc;
- VLC hqa_cbp_vlc;
DECLARE_ALIGNED(16, int16_t, block)[12][64];
} HQContext;
+static VLCElem hq_ac_vlc[1184];
+static VLCElem hqa_cbp_vlc[32];
+
static inline void put_blocks(HQContext *c, AVFrame *pic,
int plane, int x, int y, int ilace,
int16_t *block0, int16_t *block1)
@@ -87,7 +89,7 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
}
for (;;) {
- val = get_vlc2(gb, c->hq_ac_vlc.table, 9, 2);
+ val = get_vlc2(gb, hq_ac_vlc, 9, 2);
if (val < 0)
return AVERROR_INVALIDDATA;
@@ -195,7 +197,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int qgroup,
if (get_bits_left(gb) < 1)
return AVERROR_INVALIDDATA;
- cbp = get_vlc2(gb, c->hqa_cbp_vlc.table, 5, 1);
+ cbp = get_vlc2(gb, hqa_cbp_vlc, 5, 1);
for (i = 0; i < 12; i++)
memset(c->block[i], 0, sizeof(*c->block));
@@ -372,33 +374,24 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic,
return avpkt->size;
}
-static av_cold int hq_init_vlcs(HQContext *c)
+static av_cold void hq_init_vlcs(void)
{
- int ret = vlc_init(&c->hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens),
- cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0);
- if (ret < 0)
- return ret;
+ VLC_INIT_STATIC_TABLE(hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens),
+ cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0);
- return vlc_init(&c->hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES,
- hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);
+ VLC_INIT_STATIC_TABLE(hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES,
+ hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);
}
static av_cold int hq_hqa_decode_init(AVCodecContext *avctx)
{
+ static AVOnce init_static_once = AV_ONCE_INIT;
HQContext *ctx = avctx->priv_data;
ctx->avctx = avctx;
ff_hqdsp_init(&ctx->hqhqadsp);
- return hq_init_vlcs(ctx);
-}
-
-static av_cold int hq_hqa_decode_close(AVCodecContext *avctx)
-{
- HQContext *ctx = avctx->priv_data;
-
- ff_vlc_free(&ctx->hq_ac_vlc);
- ff_vlc_free(&ctx->hqa_cbp_vlc);
+ ff_thread_once(&init_static_once, hq_init_vlcs);
return 0;
}
@@ -411,7 +404,5 @@ const FFCodec ff_hq_hqa_decoder = {
.priv_data_size = sizeof(HQContext),
.init = hq_hqa_decode_init,
FF_CODEC_DECODE_CB(hq_hqa_decode_frame),
- .close = hq_hqa_decode_close,
.p.capabilities = AV_CODEC_CAP_DR1,
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-03-04 12:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 12:43 [FFmpeg-devel] [PATCH 1/2] avcodec/hq_hqadata: Move data in a header Andreas Rheinhardt
2024-03-04 12:46 ` Andreas Rheinhardt [this message]
2024-03-06 16:27 ` Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DU0P250MB0747E87DA695698B02D213618F232@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git