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 8/8] avfilter/avfilter: Move frame_pool to FilterLinkInternal
Date: Wed, 14 Feb 2024 18:25:37 +0100
Message-ID: <AS8P250MB0744A24DA4F6396B09B2A5768F4E2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB074450C1E5A33DE788104EE68F4E2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>

Avoids ugly casts when uninitializing.
(One could actually avoid allocating this separately if one
were willing to expose FFFramePool to those files including
link_internal.h.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/audio.c         | 22 ++++++++++++----------
 libavfilter/avfilter.c      |  2 +-
 libavfilter/avfilter.h      |  5 -----
 libavfilter/link_internal.h |  2 ++
 libavfilter/video.c         | 22 ++++++++++++----------
 5 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index 35270c14d2..abcbaf7304 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -28,6 +28,7 @@
 #include "avfilter.h"
 #include "framepool.h"
 #include "internal.h"
+#include "link_internal.h"
 
 const AVFilterPad ff_audio_default_filterpad[1] = {
     {
@@ -44,6 +45,7 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
 {
     AVFrame *frame = NULL;
+    FilterLinkInternal *const li = ff_link_internal(link);
     int channels = link->ch_layout.nb_channels;
     int align = av_cpu_max_align();
 #if FF_API_OLD_CHANNEL_LAYOUT
@@ -54,10 +56,10 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-    if (!link->frame_pool) {
-        link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
-                                                    nb_samples, link->format, align);
-        if (!link->frame_pool)
+    if (!li->frame_pool) {
+        li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
+                                                  nb_samples, link->format, align);
+        if (!li->frame_pool)
             return NULL;
     } else {
         int pool_channels = 0;
@@ -65,7 +67,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         int pool_align = 0;
         enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
 
-        if (ff_frame_pool_get_audio_config(link->frame_pool,
+        if (ff_frame_pool_get_audio_config(li->frame_pool,
                                            &pool_channels, &pool_nb_samples,
                                            &pool_format, &pool_align) < 0) {
             return NULL;
@@ -74,15 +76,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
         if (pool_channels != channels || pool_nb_samples < nb_samples ||
             pool_format != link->format || pool_align != align) {
 
-            ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
-            link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
-                                                        nb_samples, link->format, align);
-            if (!link->frame_pool)
+            ff_frame_pool_uninit(&li->frame_pool);
+            li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
+                                                      nb_samples, link->format, align);
+            if (!li->frame_pool)
                 return NULL;
         }
     }
 
-    frame = ff_frame_pool_get(link->frame_pool);
+    frame = ff_frame_pool_get(li->frame_pool);
     if (!frame)
         return NULL;
 
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 52ef5ca9a4..44185ff3e6 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -202,7 +202,7 @@ void avfilter_link_free(AVFilterLink **link)
     li = ff_link_internal(*link);
 
     ff_framequeue_free(&li->fifo);
-    ff_frame_pool_uninit((FFFramePool**)&(*link)->frame_pool);
+    ff_frame_pool_uninit(&li->frame_pool);
     av_channel_layout_uninit(&(*link)->ch_layout);
 
     av_freep(link);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 9252713ae2..5eff35b836 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -666,11 +666,6 @@ struct AVFilterLink {
      */
     int64_t sample_count_in, sample_count_out;
 
-    /**
-     * A pointer to a FFFramePool struct.
-     */
-    void *frame_pool;
-
     /**
      * True if a frame is currently wanted on the output of this filter.
      * Set when ff_request_frame() is called by the output,
diff --git a/libavfilter/link_internal.h b/libavfilter/link_internal.h
index 57efd44a45..c01c15109e 100644
--- a/libavfilter/link_internal.h
+++ b/libavfilter/link_internal.h
@@ -29,6 +29,8 @@
 typedef struct FilterLinkInternal {
     AVFilterLink l;
 
+    struct FFFramePool *frame_pool;
+
     /**
      * Queue of frames waiting to be filtered.
      */
diff --git a/libavfilter/video.c b/libavfilter/video.c
index 243762c8fd..22412244ad 100644
--- a/libavfilter/video.c
+++ b/libavfilter/video.c
@@ -31,6 +31,7 @@
 #include "avfilter.h"
 #include "framepool.h"
 #include "internal.h"
+#include "link_internal.h"
 #include "video.h"
 
 const AVFilterPad ff_video_default_filterpad[1] = {
@@ -47,6 +48,7 @@ AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
 
 AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
 {
+    FilterLinkInternal *const li = ff_link_internal(link);
     AVFrame *frame = NULL;
     int pool_width = 0;
     int pool_height = 0;
@@ -68,13 +70,13 @@ AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int alig
         return frame;
     }
 
-    if (!link->frame_pool) {
-        link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
-                                                    link->format, align);
-        if (!link->frame_pool)
+    if (!li->frame_pool) {
+        li->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
+                                                  link->format, align);
+        if (!li->frame_pool)
             return NULL;
     } else {
-        if (ff_frame_pool_get_video_config(link->frame_pool,
+        if (ff_frame_pool_get_video_config(li->frame_pool,
                                            &pool_width, &pool_height,
                                            &pool_format, &pool_align) < 0) {
             return NULL;
@@ -83,15 +85,15 @@ AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int alig
         if (pool_width != w || pool_height != h ||
             pool_format != link->format || pool_align != align) {
 
-            ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
-            link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
-                                                        link->format, align);
-            if (!link->frame_pool)
+            ff_frame_pool_uninit(&li->frame_pool);
+            li->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
+                                                      link->format, align);
+            if (!li->frame_pool)
                 return NULL;
         }
     }
 
-    frame = ff_frame_pool_get(link->frame_pool);
+    frame = ff_frame_pool_get(li->frame_pool);
     if (!frame)
         return NULL;
 
-- 
2.34.1

_______________________________________________
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:[~2024-02-14 17:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 2/8] avfilter: Add a header for internal generic-layer APIs Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 3/8] avfilter/avfiltergraph: Avoid indirection when freeing filtergraph Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 4/8] avfilter/avfiltergraph: Avoid allocation for AVFilterGraphInternal Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 5/8] avfilter/avfilter: Move AVFilterGraph private fields to FFFilterGraph Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 6/8] avfilter/avfilter: Move init_state to FilterLinkInternal Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 7/8] avfilter/avfilter: Move age_index " Andreas Rheinhardt
2024-02-14 17:25 ` Andreas Rheinhardt [this message]
2024-02-17 21:14 ` [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal 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=AS8P250MB0744A24DA4F6396B09B2A5768F4E2@AS8P250MB0744.EURP250.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