1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-04-14 00:58:38 +02:00

avcodec/eatgq: Move transient GetByteContext from context to stack

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-10-20 06:10:51 +02:00
parent 7f45691769
commit b76f07b8c3

View File

@ -45,7 +45,6 @@ typedef struct TgqContext {
int width, height; int width, height;
int qtable[64]; int qtable[64];
DECLARE_ALIGNED(16, int16_t, block)[6][64]; DECLARE_ALIGNED(16, int16_t, block)[6][64];
GetByteContext gb;
} TgqContext; } TgqContext;
static av_cold int tgq_decode_init(AVCodecContext *avctx) static av_cold int tgq_decode_init(AVCodecContext *avctx)
@ -147,34 +146,35 @@ static void tgq_idct_put_mb_dconly(TgqContext *s, AVFrame *frame,
} }
} }
static int tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x) static int tgq_decode_mb(TgqContext *s, GetByteContext *gbyte,
AVFrame *frame, int mb_y, int mb_x)
{ {
int mode; int mode;
int i; int i;
int8_t dc[6]; int8_t dc[6];
mode = bytestream2_get_byte(&s->gb); mode = bytestream2_get_byte(gbyte);
if (mode > 12) { if (mode > 12) {
GetBitContext gb; GetBitContext gb;
int ret = init_get_bits8(&gb, s->gb.buffer, FFMIN(bytestream2_get_bytes_left(&s->gb), mode)); int ret = init_get_bits8(&gb, gbyte->buffer, FFMIN(bytestream2_get_bytes_left(gbyte), mode));
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
tgq_decode_block(s, s->block[i], &gb); tgq_decode_block(s, s->block[i], &gb);
tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y); tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
bytestream2_skip(&s->gb, mode); bytestream2_skip(gbyte, mode);
} else { } else {
if (mode == 3) { if (mode == 3) {
memset(dc, bytestream2_get_byte(&s->gb), 4); memset(dc, bytestream2_get_byte(gbyte), 4);
dc[4] = bytestream2_get_byte(&s->gb); dc[4] = bytestream2_get_byte(gbyte);
dc[5] = bytestream2_get_byte(&s->gb); dc[5] = bytestream2_get_byte(gbyte);
} else if (mode == 6) { } else if (mode == 6) {
bytestream2_get_buffer(&s->gb, dc, 6); bytestream2_get_buffer(gbyte, dc, 6);
} else if (mode == 12) { } else if (mode == 12) {
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
dc[i] = bytestream2_get_byte(&s->gb); dc[i] = bytestream2_get_byte(gbyte);
bytestream2_skip(&s->gb, 1); bytestream2_skip(gbyte, 1);
} }
} else { } else {
av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode); av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode);
@ -202,6 +202,7 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
TgqContext *s = avctx->priv_data; TgqContext *s = avctx->priv_data;
GetByteContext gbyte;
int x, y, ret; int x, y, ret;
int big_endian; int big_endian;
@ -210,21 +211,21 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
big_endian = AV_RL32(&buf[4]) > 0x000FFFFF; big_endian = AV_RL32(&buf[4]) > 0x000FFFFF;
bytestream2_init(&s->gb, buf + 8, buf_size - 8); bytestream2_init(&gbyte, buf + 8, buf_size - 8);
if (big_endian) { if (big_endian) {
s->width = bytestream2_get_be16u(&s->gb); s->width = bytestream2_get_be16u(&gbyte);
s->height = bytestream2_get_be16u(&s->gb); s->height = bytestream2_get_be16u(&gbyte);
} else { } else {
s->width = bytestream2_get_le16u(&s->gb); s->width = bytestream2_get_le16u(&gbyte);
s->height = bytestream2_get_le16u(&s->gb); s->height = bytestream2_get_le16u(&gbyte);
} }
ret = ff_set_dimensions(s->avctx, s->width, s->height); ret = ff_set_dimensions(s->avctx, s->width, s->height);
if (ret < 0) if (ret < 0)
return ret; return ret;
tgq_calculate_qtable(s, bytestream2_get_byteu(&s->gb)); tgq_calculate_qtable(s, bytestream2_get_byteu(&gbyte));
bytestream2_skip(&s->gb, 3); bytestream2_skipu(&gbyte, 3);
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret; return ret;
@ -233,7 +234,7 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++) for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++)
for (x = 0; x < FFALIGN(avctx->width, 16) >> 4; x++) for (x = 0; x < FFALIGN(avctx->width, 16) >> 4; x++)
if (tgq_decode_mb(s, frame, y, x) < 0) if (tgq_decode_mb(s, &gbyte, frame, y, x) < 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
*got_frame = 1; *got_frame = 1;