summaryrefslogtreecommitdiff
path: root/libavcodec/mpegpicture.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-26 19:02:37 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-29 19:30:25 +0100
commit5a04c6a2697568c2b7233a0a9f4f20aa8a2a1706 (patch)
tree266f975f3ad946e38ed46374e0d830ef95fe0715 /libavcodec/mpegpicture.c
parentd0ceb90f44ff342e8de8259548a04fb9fce2ed68 (diff)
avcodec/mpegpicture: Add function to completely free MPEG-Picture
Also use said function in mpegvideo.c and mpegvideo_enc.c; and make ff_free_picture_tables() static as it isn't needed anymore outside of mpegpicture.c. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mpegpicture.c')
-rw-r--r--libavcodec/mpegpicture.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index f78a3c23e3..27e497c404 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -30,6 +30,24 @@
#include "mpegpicture.h"
#include "mpegutils.h"
+static void av_noinline free_picture_tables(Picture *pic)
+{
+ pic->alloc_mb_width =
+ pic->alloc_mb_height = 0;
+
+ av_buffer_unref(&pic->mb_var_buf);
+ av_buffer_unref(&pic->mc_mb_var_buf);
+ av_buffer_unref(&pic->mb_mean_buf);
+ av_buffer_unref(&pic->mbskip_table_buf);
+ av_buffer_unref(&pic->qscale_table_buf);
+ av_buffer_unref(&pic->mb_type_buf);
+
+ for (int i = 0; i < 2; i++) {
+ av_buffer_unref(&pic->motion_val_buf[i]);
+ av_buffer_unref(&pic->ref_index_buf[i]);
+ }
+}
+
static int make_tables_writable(Picture *pic)
{
int ret, i;
@@ -240,7 +258,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me,
if (pic->qscale_table_buf)
if ( pic->alloc_mb_width != mb_width
|| pic->alloc_mb_height != mb_height)
- ff_free_picture_tables(pic);
+ free_picture_tables(pic);
if (shared) {
av_assert0(pic->f->data[0]);
@@ -285,7 +303,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me,
fail:
av_log(avctx, AV_LOG_ERROR, "Error allocating a picture.\n");
ff_mpeg_unref_picture(avctx, pic);
- ff_free_picture_tables(pic);
+ free_picture_tables(pic);
return AVERROR(ENOMEM);
}
@@ -310,7 +328,7 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
av_buffer_unref(&pic->hwaccel_priv_buf);
if (pic->needs_realloc)
- ff_free_picture_tables(pic);
+ free_picture_tables(pic);
memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
}
@@ -331,7 +349,7 @@ int ff_update_picture_tables(Picture *dst, Picture *src)
}
if (ret < 0) {
- ff_free_picture_tables(dst);
+ free_picture_tables(dst);
return ret;
}
@@ -450,22 +468,9 @@ int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
return ret;
}
-void ff_free_picture_tables(Picture *pic)
+void av_cold ff_mpv_picture_free(AVCodecContext *avctx, Picture *pic)
{
- int i;
-
- pic->alloc_mb_width =
- pic->alloc_mb_height = 0;
-
- av_buffer_unref(&pic->mb_var_buf);
- av_buffer_unref(&pic->mc_mb_var_buf);
- av_buffer_unref(&pic->mb_mean_buf);
- av_buffer_unref(&pic->mbskip_table_buf);
- av_buffer_unref(&pic->qscale_table_buf);
- av_buffer_unref(&pic->mb_type_buf);
-
- for (i = 0; i < 2; i++) {
- av_buffer_unref(&pic->motion_val_buf[i]);
- av_buffer_unref(&pic->ref_index_buf[i]);
- }
+ free_picture_tables(pic);
+ ff_mpeg_unref_picture(avctx, pic);
+ av_frame_free(&pic->f);
}