1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/hqxvlc: Make dc9, dc10 VLC tables static

It allows to share them between frame threads.
dc11 can unfortunately not be made static without increasing
LOCALBUF_ELEMS in vlc.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-13 21:43:37 +01:00
parent 004367a0a3
commit 997b33f64c
2 changed files with 18 additions and 17 deletions

View File

@ -70,7 +70,7 @@ typedef struct HQXContext {
const VLCElem *dc_vlc; const VLCElem *dc_vlc;
VLC dc_vlcs[3]; VLC dc11_vlc;
} HQXContext; } HQXContext;
#define HQX_HEADER_SIZE 59 #define HQX_HEADER_SIZE 59
@ -481,7 +481,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame,
av_log(avctx, AV_LOG_ERROR, "Invalid DC precision 8.\n"); av_log(avctx, AV_LOG_ERROR, "Invalid DC precision 8.\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
ctx->dc_vlc = ctx->dc_vlcs[dcb_code - 1].table; ctx->dc_vlc = dcb_code == 3 ? ctx->dc11_vlc.table : dc_vlc[dcb_code - 1];
ctx->dcb = dcb_code + 8; ctx->dcb = dcb_code + 8;
ret = av_image_check_size(ctx->width, ctx->height, 0, avctx); ret = av_image_check_size(ctx->width, ctx->height, 0, avctx);
if (ret < 0) { if (ret < 0) {
@ -539,12 +539,9 @@ static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame,
static av_cold int hqx_decode_close(AVCodecContext *avctx) static av_cold int hqx_decode_close(AVCodecContext *avctx)
{ {
int i;
HQXContext *ctx = avctx->priv_data; HQXContext *ctx = avctx->priv_data;
for (i = 0; i < 3; i++) { ff_vlc_free(&ctx->dc11_vlc);
ff_vlc_free(&ctx->dc_vlcs[i]);
}
return 0; return 0;
} }
@ -553,11 +550,11 @@ static av_cold int hqx_decode_init(AVCodecContext *avctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT; static AVOnce init_static_once = AV_ONCE_INIT;
HQXContext *ctx = avctx->priv_data; HQXContext *ctx = avctx->priv_data;
int ret; int ret = vlc_init(&ctx->dc11_vlc, HQX_DC_VLC_BITS, FF_ARRAY_ELEMS(dc11_vlc_lens),
dc11_vlc_lens, 1, 1, dc11_vlc_bits, 2, 2, 0);
INIT_DC_TABLE(0, dc9); if (ret < 0)
INIT_DC_TABLE(1, dc10); return ret;
INIT_DC_TABLE(2, dc11);
ff_hqxdsp_init(&ctx->hqxdsp); ff_hqxdsp_init(&ctx->hqxdsp);

View File

@ -1529,16 +1529,17 @@ static const uint8_t hqx_ac_lens[] = {
static const uint16_t hqx_ac_nb_elems[] = { 815, 907, 512, 354, 257, 194 }; static const uint16_t hqx_ac_nb_elems[] = { 815, 907, 512, 354, 257, 194 };
static VLCElem cbp_vlc[(1 << HQX_CBP_VLC_BITS) + 15630 /* RL_VLC_ELEMS for hqx_ac */]; static VLCElem cbp_vlc[(1 << HQX_CBP_VLC_BITS) + 896 /* dc9 */ + 1344 /* dc10 */
+ 15630 /* RL_VLC_ELEMS for hqx_ac */];
static const VLCElem *dc_vlc[2];
#define INIT_DC_TABLE(idx, name) \ #define INIT_DC_TABLE(idx, name) \
do { \ do { \
ret = vlc_init(&ctx->dc_vlcs[idx], HQX_DC_VLC_BITS, \ dc_vlc[idx] = ff_vlc_init_tables(&state, HQX_DC_VLC_BITS, \
FF_ARRAY_ELEMS(name ## _vlc_lens), \ FF_ARRAY_ELEMS(name ## _vlc_lens), \
name ## _vlc_lens, 1, 1, \ name ## _vlc_lens, 1, 1, \
name ## _vlc_bits, 2, 2, 0); \ name ## _vlc_bits, 2, 2, 0); \
if (ret < 0) \
return ret; \
} while (0) } while (0)
static av_cold av_unused void hqx_init_static(void) static av_cold av_unused void hqx_init_static(void)
@ -1550,6 +1551,9 @@ static av_cold av_unused void hqx_init_static(void)
ff_vlc_init_tables(&state, HQX_CBP_VLC_BITS, FF_ARRAY_ELEMS(cbp_vlc_lens), ff_vlc_init_tables(&state, HQX_CBP_VLC_BITS, FF_ARRAY_ELEMS(cbp_vlc_lens),
cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0);
INIT_DC_TABLE(0, dc9);
INIT_DC_TABLE(1, dc10);
for (int i = 0; i < NUM_HQX_AC; ++i) { for (int i = 0; i < NUM_HQX_AC; ++i) {
RL_VLC_ELEM *lut = state.table; RL_VLC_ELEM *lut = state.table;
unsigned nb_codes = state.size; unsigned nb_codes = state.size;