[FFmpeg-devel] [PATCH v2 27/71] avcodec/h263, mpeg(picture|video): Only allocate mbskip_table for MPEG-4
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Sat May 11 23:50:51 EEST 2024
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 at outlook.com>
---
libavcodec/h263.c | 3 ++-
libavcodec/mpegpicture.c | 3 ++-
libavcodec/mpegvideo.c | 19 +++++++++++--------
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 3edf810bcc..b4cf5ee0de 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -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;
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index ad6157f0c1..ca265da9fc 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -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]);
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index eab4451e1e..5c6ec7db55 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -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);
--
2.40.1
More information about the ffmpeg-devel
mailing list