Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 30/33] avcodec/mpegpicture: Add function to completely free MPEG-Picture
Date: Wed, 26 Jan 2022 22:34:48 +0100
Message-ID: <AM7PR03MB6660BC2BFAA503885CD8F9DD8F209@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB66600AC2EF455B4D004E12E28F5F9@AM7PR03MB6660.eurprd03.prod.outlook.com>

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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
The new_picture is actually only used by encoders;
if it were not for svq1enc (which relies on ff_mpv_common_init()
and ff_mpv_common_end() to allocate and free it), I'd have moved
everything related to it to mpegvideo_enc.c. I probably do it later
anyway.
(And yes, I am aware of the fact that freeing this frame in
ff_mpv_encode_end() is redundant.)

 libavcodec/mpegpicture.c   | 47 +++++++++++++++++++++-----------------
 libavcodec/mpegpicture.h   |  2 +-
 libavcodec/mpegvideo.c     | 25 +++++---------------
 libavcodec/mpegvideo_enc.c |  3 +--
 4 files changed, 34 insertions(+), 43 deletions(-)

diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index f78a3c23e3..349ab81055 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_free_picture(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);
 }
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index a354c2a83c..cee16c07d3 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -108,7 +108,7 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me,
 int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src);
 void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *picture);
 
-void ff_free_picture_tables(Picture *pic);
+void ff_free_picture(AVCodecContext *avctx, Picture *pic);
 int ff_update_picture_tables(Picture *dst, Picture *src);
 
 int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared);
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 3b889e0791..7c63c738f3 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -874,8 +874,6 @@ void ff_mpv_free_context_frame(MpegEncContext *s)
 /* init common structure for both encoder and decoder */
 void ff_mpv_common_end(MpegEncContext *s)
 {
-    int i;
-
     if (!s)
         return;
 
@@ -895,25 +893,14 @@ void ff_mpv_common_end(MpegEncContext *s)
         return;
 
     if (s->picture) {
-        for (i = 0; i < MAX_PICTURE_COUNT; i++) {
-            ff_free_picture_tables(&s->picture[i]);
-            ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
-            av_frame_free(&s->picture[i].f);
-        }
+        for (int i = 0; i < MAX_PICTURE_COUNT; i++)
+            ff_free_picture(s->avctx, &s->picture[i]);
     }
     av_freep(&s->picture);
-    ff_free_picture_tables(&s->last_picture);
-    ff_mpeg_unref_picture(s->avctx, &s->last_picture);
-    av_frame_free(&s->last_picture.f);
-    ff_free_picture_tables(&s->current_picture);
-    ff_mpeg_unref_picture(s->avctx, &s->current_picture);
-    av_frame_free(&s->current_picture.f);
-    ff_free_picture_tables(&s->next_picture);
-    ff_mpeg_unref_picture(s->avctx, &s->next_picture);
-    av_frame_free(&s->next_picture.f);
-    ff_free_picture_tables(&s->new_picture);
-    ff_mpeg_unref_picture(s->avctx, &s->new_picture);
-    av_frame_free(&s->new_picture.f);
+    ff_free_picture(s->avctx, &s->last_picture);
+    ff_free_picture(s->avctx, &s->current_picture);
+    ff_free_picture(s->avctx, &s->next_picture);
+    ff_free_picture(s->avctx, &s->new_picture);
 
     s->context_initialized      = 0;
     s->context_reinit           = 0;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9a5634c505..baa45d20ab 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -941,8 +941,7 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
     for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
         av_frame_free(&s->tmp_frames[i]);
 
-    ff_free_picture_tables(&s->new_picture);
-    ff_mpeg_unref_picture(avctx, &s->new_picture);
+    ff_free_picture(avctx, &s->new_picture);
 
     av_freep(&avctx->stats_out);
     av_freep(&s->ac_stats);
-- 
2.32.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-01-26 21:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 17:36 [FFmpeg-devel] [PATCH 01/21] avcodec/h263: Remove declaration for inexistent function Andreas Rheinhardt
2022-01-25 17:41 ` [FFmpeg-devel] [PATCH 02/21] avcodec/h263: Move decoding-only stuff to a new header h263dec.h Andreas Rheinhardt
     [not found] ` <20220125174148.994967-1-andreas.rheinhardt@outlook.com>
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 03/21] avcodec/mpeg4videoenc: Use stack variable for vo_type Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 04/21] avcodec/mpeg4videodec: Keep vo_type in sync between threads Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 05/21] avcodec/mpeg4?video: Move vo_type to Mpeg4DecContext Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 06/21] avcodec/ituh263enc: Use stack variable for custom_pcf Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 07/21] avcodec/mpeg12enc: Use stack variable for aspect_ratio_info Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 08/21] avcodec/mpeg12enc: Return early if no Sequence Header is written Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 09/21] avcodec/mpeg12enc: Reindent after the previous commit Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 10/21] avcodec/mpeg4videoenc: Use stack variable for aspect_ratio_info Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 11/21] avcodec/ituh263enc: " Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 12/21] avcodec/ituh263dec: " Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 13/21] avcodec/mpeg4videodec: " Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 14/21] avcodec/mpegvideo: Move aspect_ratio_info to Mpeg1Context Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 15/21] avcodec/mpegvideo: Move timecode_frame_start " Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 16/21] avcodec/mpegvideo_enc: Don't sync gop_picture_number among slice threads Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 17/21] avcodec/mpegvideo: Move gop_picture_number to MPEG12EncContext Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 18/21] avcodec/mpegvideo_enc: Move msmpeg4/wmv1 encoders to msmpeg4enc.c Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 19/21] avcodec/mpegvideo_enc: Move H.263p? encoders to ituh263enc.c Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 20/21] avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it Andreas Rheinhardt
2022-01-25 17:41   ` [FFmpeg-devel] [PATCH 21/21] avcodec/mpegvideo: Move frame_rate_index to (Mpeg1|MPEG12Enc)Context Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 22/33] avcodec/mpegvideo_enc: Localize check for invalid number of b-frames Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 23/33] avcodec/mpegvideo_enc: Don't hardcode list of codecs supporting bframes Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 24/33] avcodec/mpegvideo: Fix off-by-one error when decoding >8 bit MPEG-4 Andreas Rheinhardt
2022-01-27 10:13   ` Kieran Kunhya
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 25/33] avcodec/mpegvideo: Fix crash when using lowres with 10bit MPEG-4 Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 26/33] fate/mpeg4: Add test for MPEG-4 Simple Studio Profile Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 27/33] avcodec/mpegvideo: Move handling Simple Studio Profile to mpeg4videodec Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 28/33] avcodec/mpegvideo: Move MPEG-4 Simple Studio Profile fields to mpeg4video Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 29/33] avcodec/mpegpicture: Let ff_mpeg_unref_picture() free picture tables Andreas Rheinhardt
2022-01-26 21:34 ` Andreas Rheinhardt [this message]
2022-01-27 14:21   ` [FFmpeg-devel] [PATCH 30/33] avcodec/mpegpicture: Add function to completely free MPEG-Picture James Almer
2022-01-27 14:35     ` Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 31/33] avcodec/h264data: Add missing rational.h inclusion Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 32/33] avcodec/mpegvideo: Use offset instead of pointer for vbv_delay Andreas Rheinhardt
2022-01-26 21:34 ` [FFmpeg-devel] [PATCH 33/33] avcodec/mpeg4videodec: Move use_intra_dc_vlc to stack, fix data race Andreas Rheinhardt
2022-01-28 11:36 ` [FFmpeg-devel] [PATCH 01/21] avcodec/h263: Remove declaration for inexistent function Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM7PR03MB6660BC2BFAA503885CD8F9DD8F209@AM7PR03MB6660.eurprd03.prod.outlook.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git