avcodec/h263, mpeg(picture|video): Only allocate mbskip_table for MPEG-4

It is the only user of said table and doing so is especially
important given that this buffer is zeroed every time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-05-03 18:04:49 +02:00
parent 2cbca73975
commit 101ed72c2f
3 changed files with 15 additions and 10 deletions

View File

@ -56,7 +56,8 @@ void ff_h263_update_motion_val(MpegEncContext * s){
const int wrap = s->b8_stride;
const int xy = s->block_index[0];
s->current_picture.mbskip_table[mb_xy] = s->mb_skipped;
if (s->current_picture.mbskip_table)
s->current_picture.mbskip_table[mb_xy] = s->mb_skipped;
if(s->mv_type != MV_TYPE_8X8){
int motion_x, motion_y;

View File

@ -138,10 +138,11 @@ static int alloc_picture_tables(BufferPoolContext *pools, Picture *pic,
if (!pic->name ## buf_suffix idx_suffix) \
return AVERROR(ENOMEM); \
} while (0)
GET_BUFFER(mbskip_table,,);
GET_BUFFER(qscale_table, _base,);
GET_BUFFER(mb_type, _base,);
if (pools->motion_val_pool) {
if (pools->mbskip_table_pool)
GET_BUFFER(mbskip_table,,);
for (int i = 0; i < 2; i++) {
GET_BUFFER(ref_index,, [i]);
GET_BUFFER(motion_val, _base, [i]);

View File

@ -594,6 +594,12 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed?
#define ALLOC_POOL(name, size, flags) do { \
pools->name ##_pool = ff_refstruct_pool_alloc((size), (flags)); \
if (!pools->name ##_pool) \
return AVERROR(ENOMEM); \
} while (0)
if (s->codec_id == AV_CODEC_ID_MPEG4 ||
(s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
/* interlaced direct mode decoding tables */
@ -608,12 +614,16 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
tmp += mv_table_size;
}
}
if (s->codec_id == AV_CODEC_ID_MPEG4 && !s->encoding) {
if (s->codec_id == AV_CODEC_ID_MPEG4) {
ALLOC_POOL(mbskip_table, mb_array_size + 2,
FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
if (!s->encoding) {
/* cbp, pred_dir */
if (!(s->cbp_table = av_mallocz(mb_array_size)) ||
!(s->pred_dir_table = av_mallocz(mb_array_size)))
return AVERROR(ENOMEM);
}
}
}
if (s->msmpeg4_version >= 3) {
@ -642,13 +652,6 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
return AVERROR(ENOMEM);
memset(s->mbintra_table, 1, mb_array_size);
#define ALLOC_POOL(name, size, flags) do { \
pools->name ##_pool = ff_refstruct_pool_alloc((size), (flags)); \
if (!pools->name ##_pool) \
return AVERROR(ENOMEM); \
} while (0)
ALLOC_POOL(mbskip_table, mb_array_size + 2, FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
ALLOC_POOL(qscale_table, mv_table_size, 0);
ALLOC_POOL(mb_type, mv_table_size * sizeof(uint32_t), 0);