* [FFmpeg-devel] [PATCH 2/8] avfilter: Add a header for internal generic-layer APIs
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
@ 2024-02-14 17:25 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 3/8] avfilter/avfiltergraph: Avoid indirection when freeing filtergraph Andreas Rheinhardt
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This commit moves the generic-layer stuff (that is not used
by filters) to a new header of its own, similarly to
5e7b5b0090bdf68e0897fe55ee657fdccc0cbca2 for libavcodec.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfilter.c | 1 +
libavfilter/avfilter_internal.h | 84 +++++++++++++++++++++++++++++++++
libavfilter/avfiltergraph.c | 2 +-
libavfilter/graphparser.c | 1 +
libavfilter/internal.h | 50 --------------------
libavfilter/pthread.c | 3 +-
libavfilter/thread.h | 28 -----------
7 files changed, 88 insertions(+), 81 deletions(-)
create mode 100644 libavfilter/avfilter_internal.h
delete mode 100644 libavfilter/thread.h
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 2d935cf576..5dcb548e90 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -36,6 +36,7 @@
#include "audio.h"
#include "avfilter.h"
+#include "avfilter_internal.h"
#include "filters.h"
#include "formats.h"
#include "framequeue.h"
diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h
new file mode 100644
index 0000000000..3dd51fb993
--- /dev/null
+++ b/libavfilter/avfilter_internal.h
@@ -0,0 +1,84 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * APIs internal to the generic filter(graph) layer.
+ *
+ * MUST NOT be included by individual filters.
+ */
+
+#ifndef AVFILTER_AVFILTER_INTERNAL_H
+#define AVFILTER_AVFILTER_INTERNAL_H
+
+#include "avfilter.h"
+#include "framequeue.h"
+
+typedef struct AVFilterCommand {
+ double time; ///< time expressed in seconds
+ char *command; ///< command
+ char *arg; ///< optional argument for the command
+ int flags;
+ struct AVFilterCommand *next;
+} AVFilterCommand;
+
+struct AVFilterGraphInternal {
+ void *thread;
+ avfilter_execute_func *thread_execute;
+ FFFrameQueueGlobal frame_queues;
+};
+
+/**
+ * Update the position of a link in the age heap.
+ */
+void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link);
+
+/**
+ * Allocate a new filter context and return it.
+ *
+ * @param filter what filter to create an instance of
+ * @param inst_name name to give to the new filter context
+ *
+ * @return newly created filter context or NULL on failure
+ */
+AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
+
+/**
+ * Remove a filter from a graph;
+ */
+void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
+
+int ff_filter_activate(AVFilterContext *filter);
+
+/**
+ * Parse filter options into a dictionary.
+ *
+ * @param logctx context for logging
+ * @param priv_class a filter's private class for shorthand options or NULL
+ * @param options dictionary to store parsed options in
+ * @param args options string to parse
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
+ AVDictionary **options, const char *args);
+
+int ff_graph_thread_init(AVFilterGraph *graph);
+
+void ff_graph_thread_free(AVFilterGraph *graph);
+
+#endif /* AVFILTER_AVFILTER_INTERNAL_H */
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index ea0d7713e3..df22de03a0 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -34,12 +34,12 @@
#include "avfilter.h"
+#include "avfilter_internal.h"
#include "buffersink.h"
#include "formats.h"
#include "framequeue.h"
#include "internal.h"
#include "link_internal.h"
-#include "thread.h"
#define OFFSET(x) offsetof(AVFilterGraph, x)
#define F AV_OPT_FLAG_FILTERING_PARAM
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index 229e647c0a..5d6dcdb9d3 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -29,6 +29,7 @@
#include "libavutil/opt.h"
#include "avfilter.h"
+#include "avfilter_internal.h"
#include "internal.h"
#define WHITESPACES " \n\t\r"
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 3d46923cad..0e3f68d1f4 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -26,20 +26,6 @@
#include "libavutil/internal.h"
#include "avfilter.h"
-#include "framequeue.h"
-
-typedef struct AVFilterCommand {
- double time; ///< time expressed in seconds
- char *command; ///< command
- char *arg; ///< optional argument for the command
- int flags;
- struct AVFilterCommand *next;
-} AVFilterCommand;
-
-/**
- * Update the position of a link in the age heap.
- */
-void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link);
/**
* A filter pad used for either input or output.
@@ -127,12 +113,6 @@ struct AVFilterPad {
int (*config_props)(AVFilterLink *link);
};
-struct AVFilterGraphInternal {
- void *thread;
- avfilter_execute_func *thread_execute;
- FFFrameQueueGlobal frame_queues;
-};
-
typedef struct FFFilterContext {
/**
* The public AVFilterContext. See avfilter.h for it.
@@ -356,23 +336,6 @@ int ff_request_frame(AVFilterLink *link);
*/
int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
-/**
- * Allocate a new filter context and return it.
- *
- * @param filter what filter to create an instance of
- * @param inst_name name to give to the new filter context
- *
- * @return newly created filter context or NULL on failure
- */
-AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
-
-int ff_filter_activate(AVFilterContext *filter);
-
-/**
- * Remove a filter from a graph;
- */
-void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
-
/**
* The filter is aware of hardware frames, and any hardware frame context
* should not be automatically propagated through it.
@@ -415,17 +378,4 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
int default_pool_size);
-/**
- * Parse filter options into a dictionary.
- *
- * @param logctx context for logging
- * @param priv_class a filter's private class for shorthand options or NULL
- * @param options dictionary to store parsed options in
- * @param args options string to parse
- *
- * @return a non-negative number on success, a negative error code on failure
- */
-int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
- AVDictionary **options, const char *args);
-
#endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index 1a063d3cc0..a0336a8e04 100644
--- a/libavfilter/pthread.c
+++ b/libavfilter/pthread.c
@@ -29,8 +29,7 @@
#include "libavutil/slicethread.h"
#include "avfilter.h"
-#include "internal.h"
-#include "thread.h"
+#include "avfilter_internal.h"
typedef struct ThreadContext {
AVFilterGraph *graph;
diff --git a/libavfilter/thread.h b/libavfilter/thread.h
deleted file mode 100644
index c709f17a33..0000000000
--- a/libavfilter/thread.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVFILTER_THREAD_H
-#define AVFILTER_THREAD_H
-
-#include "avfilter.h"
-
-int ff_graph_thread_init(AVFilterGraph *graph);
-
-void ff_graph_thread_free(AVFilterGraph *graph);
-
-#endif /* AVFILTER_THREAD_H */
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 3/8] avfilter/avfiltergraph: Avoid indirection when freeing filtergraph
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 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 4/8] avfilter/avfiltergraph: Avoid allocation for AVFilterGraphInternal Andreas Rheinhardt
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfiltergraph.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index df22de03a0..a9befb954f 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -117,23 +117,25 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
}
}
-void avfilter_graph_free(AVFilterGraph **graph)
+void avfilter_graph_free(AVFilterGraph **graphp)
{
- if (!*graph)
+ AVFilterGraph *graph = *graphp;
+
+ if (!graph)
return;
- while ((*graph)->nb_filters)
- avfilter_free((*graph)->filters[0]);
+ while (graph->nb_filters)
+ avfilter_free(graph->filters[0]);
- ff_graph_thread_free(*graph);
+ ff_graph_thread_free(graph);
- av_freep(&(*graph)->sink_links);
+ av_freep(&graph->sink_links);
- av_opt_free(*graph);
+ av_opt_free(graph);
- av_freep(&(*graph)->filters);
- av_freep(&(*graph)->internal);
- av_freep(graph);
+ av_freep(&graph->filters);
+ av_freep(&graph->internal);
+ av_freep(graphp);
}
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 4/8] avfilter/avfiltergraph: Avoid allocation for AVFilterGraphInternal
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 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 5/8] avfilter/avfilter: Move AVFilterGraph private fields to FFFilterGraph Andreas Rheinhardt
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
To do this, allocate AVFilterGraphInternal jointly with AVFilterGraph
and rename it to FFFilterGraph in the process (similarly to
AVStream/FFStream).
The AVFilterGraphInternal* will be removed on the next major version
bump.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfilter.c | 6 +++---
libavfilter/avfilter_internal.h | 17 +++++++++++++----
libavfilter/avfiltergraph.c | 32 +++++++++++++++-----------------
libavfilter/pthread.c | 23 ++++++++++++-----------
4 files changed, 43 insertions(+), 35 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 5dcb548e90..796ec29afd 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -188,7 +188,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
link->format = -1;
link->colorspace = AVCOL_SPC_UNSPECIFIED;
- ff_framequeue_init(&li->fifo, &src->graph->internal->frame_queues);
+ ff_framequeue_init(&li->fifo, &fffiltergraph(src->graph)->frame_queues);
return 0;
}
@@ -905,9 +905,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
- ctx->graph->internal->thread_execute) {
+ fffiltergraph(ctx->graph)->thread_execute) {
ctx->thread_type = AVFILTER_THREAD_SLICE;
- ctxi->execute = ctx->graph->internal->thread_execute;
+ ctxi->execute = fffiltergraph(ctx->graph)->thread_execute;
} else {
ctx->thread_type = 0;
}
diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h
index 3dd51fb993..9ddb82bf26 100644
--- a/libavfilter/avfilter_internal.h
+++ b/libavfilter/avfilter_internal.h
@@ -36,11 +36,20 @@ typedef struct AVFilterCommand {
struct AVFilterCommand *next;
} AVFilterCommand;
-struct AVFilterGraphInternal {
+typedef struct FFFilterGraph {
+ /**
+ * The public AVFilterGraph. See avfilter.h for it.
+ */
+ AVFilterGraph p;
void *thread;
avfilter_execute_func *thread_execute;
FFFrameQueueGlobal frame_queues;
-};
+} FFFilterGraph;
+
+static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph)
+{
+ return (FFFilterGraph*)graph;
+}
/**
* Update the position of a link in the age heap.
@@ -77,8 +86,8 @@ int ff_filter_activate(AVFilterContext *filter);
int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
AVDictionary **options, const char *args);
-int ff_graph_thread_init(AVFilterGraph *graph);
+int ff_graph_thread_init(FFFilterGraph *graph);
-void ff_graph_thread_free(AVFilterGraph *graph);
+void ff_graph_thread_free(FFFilterGraph *graph);
#endif /* AVFILTER_AVFILTER_INTERNAL_H */
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a9befb954f..1e7874adc6 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -68,33 +68,30 @@ static const AVClass filtergraph_class = {
};
#if !HAVE_THREADS
-void ff_graph_thread_free(AVFilterGraph *graph)
+void ff_graph_thread_free(FFFilterGraph *graph)
{
}
-int ff_graph_thread_init(AVFilterGraph *graph)
+int ff_graph_thread_init(FFFilterGraph *graph)
{
- graph->thread_type = 0;
- graph->nb_threads = 1;
+ graph->p.thread_type = 0;
+ graph->p.nb_threads = 1;
return 0;
}
#endif
AVFilterGraph *avfilter_graph_alloc(void)
{
- AVFilterGraph *ret = av_mallocz(sizeof(*ret));
- if (!ret)
- return NULL;
+ FFFilterGraph *graph = av_mallocz(sizeof(*graph));
+ AVFilterGraph *ret;
- ret->internal = av_mallocz(sizeof(*ret->internal));
- if (!ret->internal) {
- av_freep(&ret);
+ if (!graph)
return NULL;
- }
+ ret = &graph->p;
ret->av_class = &filtergraph_class;
av_opt_set_defaults(ret);
- ff_framequeue_global_init(&ret->internal->frame_queues);
+ ff_framequeue_global_init(&graph->frame_queues);
return ret;
}
@@ -120,6 +117,7 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
void avfilter_graph_free(AVFilterGraph **graphp)
{
AVFilterGraph *graph = *graphp;
+ FFFilterGraph *graphi = fffiltergraph(graph);
if (!graph)
return;
@@ -127,14 +125,13 @@ void avfilter_graph_free(AVFilterGraph **graphp)
while (graph->nb_filters)
avfilter_free(graph->filters[0]);
- ff_graph_thread_free(graph);
+ ff_graph_thread_free(graphi);
av_freep(&graph->sink_links);
av_opt_free(graph);
av_freep(&graph->filters);
- av_freep(&graph->internal);
av_freep(graphp);
}
@@ -170,12 +167,13 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
const char *name)
{
AVFilterContext **filters, *s;
+ FFFilterGraph *graphi = fffiltergraph(graph);
- if (graph->thread_type && !graph->internal->thread_execute) {
+ if (graph->thread_type && !graphi->thread_execute) {
if (graph->execute) {
- graph->internal->thread_execute = graph->execute;
+ graphi->thread_execute = graph->execute;
} else {
- int ret = ff_graph_thread_init(graph);
+ int ret = ff_graph_thread_init(graphi);
if (ret < 0) {
av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
return NULL;
diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index a0336a8e04..06590fe65a 100644
--- a/libavfilter/pthread.c
+++ b/libavfilter/pthread.c
@@ -58,7 +58,7 @@ static void slice_thread_uninit(ThreadContext *c)
static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,
void *arg, int *ret, int nb_jobs)
{
- ThreadContext *c = ctx->graph->internal->thread;
+ ThreadContext *c = fffiltergraph(ctx->graph)->thread;
if (nb_jobs <= 0)
return 0;
@@ -79,8 +79,9 @@ static int thread_init_internal(ThreadContext *c, int nb_threads)
return FFMAX(nb_threads, 1);
}
-int ff_graph_thread_init(AVFilterGraph *graph)
+int ff_graph_thread_init(FFFilterGraph *graphi)
{
+ AVFilterGraph *graph = &graphi->p;
int ret;
if (graph->nb_threads == 1) {
@@ -88,27 +89,27 @@ int ff_graph_thread_init(AVFilterGraph *graph)
return 0;
}
- graph->internal->thread = av_mallocz(sizeof(ThreadContext));
- if (!graph->internal->thread)
+ graphi->thread = av_mallocz(sizeof(ThreadContext));
+ if (!graphi->thread)
return AVERROR(ENOMEM);
- ret = thread_init_internal(graph->internal->thread, graph->nb_threads);
+ ret = thread_init_internal(graphi->thread, graph->nb_threads);
if (ret <= 1) {
- av_freep(&graph->internal->thread);
+ av_freep(&graphi->thread);
graph->thread_type = 0;
graph->nb_threads = 1;
return (ret < 0) ? ret : 0;
}
graph->nb_threads = ret;
- graph->internal->thread_execute = thread_execute;
+ graphi->thread_execute = thread_execute;
return 0;
}
-void ff_graph_thread_free(AVFilterGraph *graph)
+void ff_graph_thread_free(FFFilterGraph *graph)
{
- if (graph->internal->thread)
- slice_thread_uninit(graph->internal->thread);
- av_freep(&graph->internal->thread);
+ if (graph->thread)
+ slice_thread_uninit(graph->thread);
+ av_freep(&graph->thread);
}
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 5/8] avfilter/avfilter: Move AVFilterGraph private fields to FFFilterGraph
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
` (2 preceding siblings ...)
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 4/8] avfilter/avfiltergraph: Avoid allocation for AVFilterGraphInternal Andreas Rheinhardt
@ 2024-02-14 17:25 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 6/8] avfilter/avfilter: Move init_state to FilterLinkInternal Andreas Rheinhardt
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
(These fields were in AVFilterGraph although AVFilterGraphInternal
existed for years.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfilter.h | 12 ------------
libavfilter/avfilter_internal.h | 6 ++++++
libavfilter/avfiltergraph.c | 32 +++++++++++++++++---------------
3 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b5346f40ab..1d2909e28d 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -899,18 +899,6 @@ typedef struct AVFilterGraph {
avfilter_execute_func *execute;
char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
-
- /**
- * Private fields
- *
- * The following fields are for internal use only.
- * Their type, offset, number and semantic can change without notice.
- */
-
- AVFilterLink **sink_links;
- int sink_links_count;
-
- unsigned disable_auto_convert;
} AVFilterGraph;
/**
diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h
index 9ddb82bf26..72712608e7 100644
--- a/libavfilter/avfilter_internal.h
+++ b/libavfilter/avfilter_internal.h
@@ -41,6 +41,12 @@ typedef struct FFFilterGraph {
* The public AVFilterGraph. See avfilter.h for it.
*/
AVFilterGraph p;
+
+ AVFilterLink **sink_links;
+ int sink_links_count;
+
+ unsigned disable_auto_convert;
+
void *thread;
avfilter_execute_func *thread_execute;
FFFrameQueueGlobal frame_queues;
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 1e7874adc6..5278cf2010 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -127,7 +127,7 @@ void avfilter_graph_free(AVFilterGraph **graphp)
ff_graph_thread_free(graphi);
- av_freep(&graph->sink_links);
+ av_freep(&graphi->sink_links);
av_opt_free(graph);
@@ -159,7 +159,7 @@ fail:
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
{
- graph->disable_auto_convert = flags;
+ fffiltergraph(graph)->disable_auto_convert = flags;
}
AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
@@ -471,7 +471,7 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx)
char inst_name[30];
const char *opts;
- if (graph->disable_auto_convert) {
+ if (fffiltergraph(graph)->disable_auto_convert) {
av_log(log_ctx, AV_LOG_ERROR,
"The filters '%s' and '%s' do not have a common format "
"and automatic conversion is disabled.\n",
@@ -1317,8 +1317,8 @@ static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
}
}
av_assert0(n == sink_links_count);
- graph->sink_links = sinks;
- graph->sink_links_count = sink_links_count;
+ fffiltergraph(graph)->sink_links = sinks;
+ fffiltergraph(graph)->sink_links_count = sink_links_count;
return 0;
}
@@ -1401,7 +1401,7 @@ int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const
return 0;
}
-static void heap_bubble_up(AVFilterGraph *graph,
+static void heap_bubble_up(FFFilterGraph *graph,
AVFilterLink *link, int index)
{
AVFilterLink **links = graph->sink_links;
@@ -1420,7 +1420,7 @@ static void heap_bubble_up(AVFilterGraph *graph,
link->age_index = index;
}
-static void heap_bubble_down(AVFilterGraph *graph,
+static void heap_bubble_down(FFFilterGraph *graph,
AVFilterLink *link, int index)
{
AVFilterLink **links = graph->sink_links;
@@ -1446,18 +1446,20 @@ static void heap_bubble_down(AVFilterGraph *graph,
void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link)
{
- heap_bubble_up (graph, link, link->age_index);
- heap_bubble_down(graph, link, link->age_index);
+ FFFilterGraph *graphi = fffiltergraph(graph);
+ heap_bubble_up (graphi, link, link->age_index);
+ heap_bubble_down(graphi, link, link->age_index);
}
int avfilter_graph_request_oldest(AVFilterGraph *graph)
{
- AVFilterLink *oldest = graph->sink_links[0];
+ FFFilterGraph *graphi = fffiltergraph(graph);
+ AVFilterLink *oldest = graphi->sink_links[0];
int64_t frame_count;
int r;
- while (graph->sink_links_count) {
- oldest = graph->sink_links[0];
+ while (graphi->sink_links_count) {
+ oldest = graphi->sink_links[0];
if (oldest->dst->filter->activate) {
r = av_buffersink_get_frame_flags(oldest->dst, NULL,
AV_BUFFERSINK_FLAG_PEEK);
@@ -1472,12 +1474,12 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph)
oldest->dst->name,
oldest->dstpad->name);
/* EOF: remove the link from the heap */
- if (oldest->age_index < --graph->sink_links_count)
- heap_bubble_down(graph, graph->sink_links[graph->sink_links_count],
+ if (oldest->age_index < --graphi->sink_links_count)
+ heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
oldest->age_index);
oldest->age_index = -1;
}
- if (!graph->sink_links_count)
+ if (!graphi->sink_links_count)
return AVERROR_EOF;
av_assert1(!oldest->dst->filter->activate);
av_assert1(oldest->age_index >= 0);
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 6/8] avfilter/avfilter: Move init_state to FilterLinkInternal
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
` (3 preceding siblings ...)
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 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 7/8] avfilter/avfilter: Move age_index " Andreas Rheinhardt
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfilter.c | 7 ++++---
libavfilter/avfilter.h | 7 -------
libavfilter/link_internal.h | 7 +++++++
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 796ec29afd..a3f8c403c3 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -323,6 +323,7 @@ int avfilter_config_links(AVFilterContext *filter)
for (i = 0; i < filter->nb_inputs; i ++) {
AVFilterLink *link = filter->inputs[i];
AVFilterLink *inlink;
+ FilterLinkInternal *li = ff_link_internal(link);
if (!link) continue;
if (!link->src || !link->dst) {
@@ -335,14 +336,14 @@ int avfilter_config_links(AVFilterContext *filter)
link->current_pts =
link->current_pts_us = AV_NOPTS_VALUE;
- switch (link->init_state) {
+ switch (li->init_state) {
case AVLINK_INIT:
continue;
case AVLINK_STARTINIT:
av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
return 0;
case AVLINK_UNINIT:
- link->init_state = AVLINK_STARTINIT;
+ li->init_state = AVLINK_STARTINIT;
if ((ret = avfilter_config_links(link->src)) < 0)
return ret;
@@ -413,7 +414,7 @@ int avfilter_config_links(AVFilterContext *filter)
return ret;
}
- link->init_state = AVLINK_INIT;
+ li->init_state = AVLINK_INIT;
}
}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 1d2909e28d..5c6e34e8fc 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -611,13 +611,6 @@ struct AVFilterLink {
*/
AVFilterFormatsConfig outcfg;
- /** stage of the initialization of the link properties (dimensions, etc) */
- enum {
- AVLINK_UNINIT = 0, ///< not started
- AVLINK_STARTINIT, ///< started, but incomplete
- AVLINK_INIT ///< complete
- } init_state;
-
/**
* Graph the filter belongs to.
*/
diff --git a/libavfilter/link_internal.h b/libavfilter/link_internal.h
index b5a8ac89ec..030eb24765 100644
--- a/libavfilter/link_internal.h
+++ b/libavfilter/link_internal.h
@@ -59,6 +59,13 @@ typedef struct FilterLinkInternal {
* corresponding code.
*/
int status_out;
+
+ /** stage of the initialization of the link properties (dimensions, etc) */
+ enum {
+ AVLINK_UNINIT = 0, ///< not started
+ AVLINK_STARTINIT, ///< started, but incomplete
+ AVLINK_INIT ///< complete
+ } init_state;
} FilterLinkInternal;
static inline FilterLinkInternal *ff_link_internal(AVFilterLink *link)
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 7/8] avfilter/avfilter: Move age_index to FilterLinkInternal
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
` (4 preceding siblings ...)
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 6/8] avfilter/avfilter: Move init_state to FilterLinkInternal Andreas Rheinhardt
@ 2024-02-14 17:25 ` Andreas Rheinhardt
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 8/8] avfilter/avfilter: Move frame_pool " Andreas Rheinhardt
2024-02-17 21:14 ` [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Also make FFFilterGraph.sink_links a FilterLinkInternal**
because sink_links is used to access FilterLinkInternal
fields.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/avfilter.c | 21 +++++++-----
libavfilter/avfilter.h | 5 ---
libavfilter/avfilter_internal.h | 5 +--
libavfilter/avfiltergraph.c | 61 +++++++++++++++++----------------
libavfilter/link_internal.h | 5 +++
5 files changed, 52 insertions(+), 45 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index a3f8c403c3..52ef5ca9a4 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -208,15 +208,17 @@ void avfilter_link_free(AVFilterLink **link)
av_freep(link);
}
-static void update_link_current_pts(AVFilterLink *link, int64_t pts)
+static void update_link_current_pts(FilterLinkInternal *li, int64_t pts)
{
+ AVFilterLink *const link = &li->l;
+
if (pts == AV_NOPTS_VALUE)
return;
link->current_pts = pts;
link->current_pts_us = av_rescale_q(pts, link->time_base, AV_TIME_BASE_Q);
/* TODO use duration */
- if (link->graph && link->age_index >= 0)
- ff_avfilter_graph_update_heap(link->graph, link);
+ if (link->graph && li->age_index >= 0)
+ ff_avfilter_graph_update_heap(link->graph, li);
}
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
@@ -266,7 +268,7 @@ static void link_set_out_status(AVFilterLink *link, int status, int64_t pts)
av_assert0(!li->status_out);
li->status_out = status;
if (pts != AV_NOPTS_VALUE)
- update_link_current_pts(link, pts);
+ update_link_current_pts(li, pts);
filter_unblock(link->dst);
ff_filter_set_ready(link->src, 200);
}
@@ -1393,7 +1395,7 @@ int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts
if (!li->status_in)
return *rstatus = 0;
*rstatus = li->status_out = li->status_in;
- update_link_current_pts(link, li->status_in_pts);
+ update_link_current_pts(li, li->status_in_pts);
*rpts = link->current_pts;
return 1;
}
@@ -1424,9 +1426,10 @@ int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
return samples >= min || (li->status_in && samples);
}
-static void consume_update(AVFilterLink *link, const AVFrame *frame)
+static void consume_update(FilterLinkInternal *li, const AVFrame *frame)
{
- update_link_current_pts(link, frame->pts);
+ AVFilterLink *const link = &li->l;
+ update_link_current_pts(li, frame->pts);
ff_inlink_process_commands(link, frame);
link->dst->is_disabled = !ff_inlink_evaluate_timeline_at_frame(link, frame);
link->frame_count_out++;
@@ -1448,7 +1451,7 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
}
frame = ff_framequeue_take(&li->fifo);
- consume_update(link, frame);
+ consume_update(li, frame);
*rframe = frame;
return 1;
}
@@ -1469,7 +1472,7 @@ int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
ret = take_samples(li, min, max, &frame);
if (ret < 0)
return ret;
- consume_update(link, frame);
+ consume_update(li, frame);
*rframe = frame;
return 1;
}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 5c6e34e8fc..9252713ae2 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -628,11 +628,6 @@ struct AVFilterLink {
*/
int64_t current_pts_us;
- /**
- * Index in the age array.
- */
- int age_index;
-
/**
* Frame rate of the stream on the link, or 1/0 if unknown or variable;
* if left to 0/0, will be automatically copied from the first input
diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h
index 72712608e7..5ad44ca866 100644
--- a/libavfilter/avfilter_internal.h
+++ b/libavfilter/avfilter_internal.h
@@ -42,7 +42,7 @@ typedef struct FFFilterGraph {
*/
AVFilterGraph p;
- AVFilterLink **sink_links;
+ struct FilterLinkInternal **sink_links;
int sink_links_count;
unsigned disable_auto_convert;
@@ -60,7 +60,8 @@ static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph)
/**
* Update the position of a link in the age heap.
*/
-void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link);
+void ff_avfilter_graph_update_heap(AVFilterGraph *graph,
+ struct FilterLinkInternal *li);
/**
* Allocate a new filter context and return it.
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 5278cf2010..9c91953cc9 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -1286,17 +1286,17 @@ static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
unsigned i, j;
int sink_links_count = 0, n = 0;
AVFilterContext *f;
- AVFilterLink **sinks;
+ FilterLinkInternal **sinks;
for (i = 0; i < graph->nb_filters; i++) {
f = graph->filters[i];
for (j = 0; j < f->nb_inputs; j++) {
f->inputs[j]->graph = graph;
- f->inputs[j]->age_index = -1;
+ ff_link_internal(f->inputs[j])->age_index = -1;
}
for (j = 0; j < f->nb_outputs; j++) {
f->outputs[j]->graph = graph;
- f->outputs[j]->age_index= -1;
+ ff_link_internal(f->outputs[j])->age_index = -1;
}
if (!f->nb_outputs) {
if (f->nb_inputs > INT_MAX - sink_links_count)
@@ -1311,8 +1311,9 @@ static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
f = graph->filters[i];
if (!f->nb_outputs) {
for (j = 0; j < f->nb_inputs; j++) {
- sinks[n] = f->inputs[j];
- f->inputs[j]->age_index = n++;
+ sinks[n] = ff_link_internal(f->inputs[j]);
+ sinks[n]->age_index = n;
+ n++;
}
}
}
@@ -1402,28 +1403,28 @@ int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const
}
static void heap_bubble_up(FFFilterGraph *graph,
- AVFilterLink *link, int index)
+ FilterLinkInternal *li, int index)
{
- AVFilterLink **links = graph->sink_links;
+ FilterLinkInternal **links = graph->sink_links;
av_assert0(index >= 0);
while (index) {
int parent = (index - 1) >> 1;
- if (links[parent]->current_pts_us >= link->current_pts_us)
+ if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
break;
links[index] = links[parent];
links[index]->age_index = index;
index = parent;
}
- links[index] = link;
- link->age_index = index;
+ links[index] = li;
+ li->age_index = index;
}
static void heap_bubble_down(FFFilterGraph *graph,
- AVFilterLink *link, int index)
+ FilterLinkInternal *li, int index)
{
- AVFilterLink **links = graph->sink_links;
+ FilterLinkInternal **links = graph->sink_links;
av_assert0(index >= 0);
@@ -1432,34 +1433,37 @@ static void heap_bubble_down(FFFilterGraph *graph,
if (child >= graph->sink_links_count)
break;
if (child + 1 < graph->sink_links_count &&
- links[child + 1]->current_pts_us < links[child]->current_pts_us)
+ links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
child++;
- if (link->current_pts_us < links[child]->current_pts_us)
+ if (li->l.current_pts_us < links[child]->l.current_pts_us)
break;
links[index] = links[child];
links[index]->age_index = index;
index = child;
}
- links[index] = link;
- link->age_index = index;
+ links[index] = li;
+ li->age_index = index;
}
-void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link)
+void ff_avfilter_graph_update_heap(AVFilterGraph *graph, FilterLinkInternal *li)
{
- FFFilterGraph *graphi = fffiltergraph(graph);
- heap_bubble_up (graphi, link, link->age_index);
- heap_bubble_down(graphi, link, link->age_index);
+ FFFilterGraph *graphi = fffiltergraph(graph);
+
+ heap_bubble_up (graphi, li, li->age_index);
+ heap_bubble_down(graphi, li, li->age_index);
}
int avfilter_graph_request_oldest(AVFilterGraph *graph)
{
FFFilterGraph *graphi = fffiltergraph(graph);
- AVFilterLink *oldest = graphi->sink_links[0];
+ FilterLinkInternal *oldesti = graphi->sink_links[0];
+ AVFilterLink *oldest = &oldesti->l;
int64_t frame_count;
int r;
while (graphi->sink_links_count) {
- oldest = graphi->sink_links[0];
+ oldesti = graphi->sink_links[0];
+ oldest = &oldesti->l;
if (oldest->dst->filter->activate) {
r = av_buffersink_get_frame_flags(oldest->dst, NULL,
AV_BUFFERSINK_FLAG_PEEK);
@@ -1474,22 +1478,21 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph)
oldest->dst->name,
oldest->dstpad->name);
/* EOF: remove the link from the heap */
- if (oldest->age_index < --graphi->sink_links_count)
+ if (oldesti->age_index < --graphi->sink_links_count)
heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
- oldest->age_index);
- oldest->age_index = -1;
+ oldesti->age_index);
+ oldesti->age_index = -1;
}
if (!graphi->sink_links_count)
return AVERROR_EOF;
av_assert1(!oldest->dst->filter->activate);
- av_assert1(oldest->age_index >= 0);
+ av_assert1(oldesti->age_index >= 0);
frame_count = oldest->frame_count_out;
while (frame_count == oldest->frame_count_out) {
- FilterLinkInternal * const li = ff_link_internal(oldest);
r = ff_filter_graph_run_once(graph);
if (r == AVERROR(EAGAIN) &&
- !oldest->frame_wanted_out && !li->frame_blocked_in &&
- !li->status_in)
+ !oldest->frame_wanted_out && !oldesti->frame_blocked_in &&
+ !oldesti->status_in)
ff_request_frame(oldest);
else if (r < 0)
return r;
diff --git a/libavfilter/link_internal.h b/libavfilter/link_internal.h
index 030eb24765..57efd44a45 100644
--- a/libavfilter/link_internal.h
+++ b/libavfilter/link_internal.h
@@ -60,6 +60,11 @@ typedef struct FilterLinkInternal {
*/
int status_out;
+ /**
+ * Index in the age array.
+ */
+ int age_index;
+
/** stage of the initialization of the link properties (dimensions, etc) */
enum {
AVLINK_UNINIT = 0, ///< not started
--
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 8/8] avfilter/avfilter: Move frame_pool to FilterLinkInternal
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
` (5 preceding siblings ...)
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 7/8] avfilter/avfilter: Move age_index " Andreas Rheinhardt
@ 2024-02-14 17:25 ` Andreas Rheinhardt
2024-02-17 21:14 ` [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-14 17:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal
2024-02-14 17:24 [FFmpeg-devel] [PATCH 1/8] avfilter/avfilter: Avoid allocation for AVFilterInternal Andreas Rheinhardt
` (6 preceding siblings ...)
2024-02-14 17:25 ` [FFmpeg-devel] [PATCH 8/8] avfilter/avfilter: Move frame_pool " Andreas Rheinhardt
@ 2024-02-17 21:14 ` Andreas Rheinhardt
7 siblings, 0 replies; 9+ messages in thread
From: Andreas Rheinhardt @ 2024-02-17 21:14 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> To do this, allocate AVFilterInternal jointly with AVFilterContext
> and rename it to FFFilterContext in the process (similarly to
> AVStream/FFStream).
> The AVFilterInternal* will be removed from AVFilterContext
> on the next major bump.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> Several of these patches are from the bump patchset; I have just
> removed the removal of the internal-pointers, so that this could
> be applied at any time.
>
> libavfilter/avfilter.c | 22 ++++++++++------------
> libavfilter/graphparser.c | 2 +-
> libavfilter/internal.h | 16 +++++++++++++---
> 3 files changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 9fe249f3f9..2d935cf576 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -159,7 +159,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
> src->outputs[srcpad] || dst->inputs[dstpad])
> return AVERROR(EINVAL);
>
> - if (!src->internal->initialized || !dst->internal->initialized) {
> + if (!fffilterctx(src)->initialized || !fffilterctx(dst)->initialized) {
> av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n");
> return AVERROR(EINVAL);
> }
> @@ -668,15 +668,17 @@ static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi
>
> AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
> {
> + FFFilterContext *ctx;
> AVFilterContext *ret;
> int preinited = 0;
>
> if (!filter)
> return NULL;
>
> - ret = av_mallocz(sizeof(AVFilterContext));
> - if (!ret)
> + ctx = av_mallocz(sizeof(*ctx));
> + if (!ctx)
> return NULL;
> + ret = &ctx->p;
>
> ret->av_class = &avfilter_class;
> ret->filter = filter;
> @@ -698,10 +700,7 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
> av_opt_set_defaults(ret->priv);
> }
>
> - ret->internal = av_mallocz(sizeof(*ret->internal));
> - if (!ret->internal)
> - goto err;
> - ret->internal->execute = default_execute;
> + ctx->execute = default_execute;
>
> ret->nb_inputs = filter->nb_inputs;
> if (ret->nb_inputs ) {
> @@ -735,7 +734,6 @@ err:
> av_freep(&ret->output_pads);
> ret->nb_outputs = 0;
> av_freep(&ret->priv);
> - av_freep(&ret->internal);
> av_free(ret);
> return NULL;
> }
> @@ -807,7 +805,6 @@ void avfilter_free(AVFilterContext *filter)
> av_expr_free(filter->enable);
> filter->enable = NULL;
> av_freep(&filter->var_values);
> - av_freep(&filter->internal);
> av_free(filter);
> }
>
> @@ -891,9 +888,10 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
>
> int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
> {
> + FFFilterContext *ctxi = fffilterctx(ctx);
> int ret = 0;
>
> - if (ctx->internal->initialized) {
> + if (ctxi->initialized) {
> av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n");
> return AVERROR(EINVAL);
> }
> @@ -908,7 +906,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
> ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
> ctx->graph->internal->thread_execute) {
> ctx->thread_type = AVFILTER_THREAD_SLICE;
> - ctx->internal->execute = ctx->graph->internal->thread_execute;
> + ctxi->execute = ctx->graph->internal->thread_execute;
> } else {
> ctx->thread_type = 0;
> }
> @@ -924,7 +922,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
> return ret;
> }
>
> - ctx->internal->initialized = 1;
> + ctxi->initialized = 1;
>
> return 0;
> }
> diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
> index 96ef6b15bf..229e647c0a 100644
> --- a/libavfilter/graphparser.c
> +++ b/libavfilter/graphparser.c
> @@ -626,7 +626,7 @@ int avfilter_graph_segment_init(AVFilterGraphSegment *seg, int flags)
>
> if (p->filter_name)
> return fail_creation_pending(seg, p->filter_name, __func__);
> - if (!p->filter || p->filter->internal->initialized)
> + if (!p->filter || fffilterctx(p->filter)->initialized)
> continue;
>
> ret = avfilter_init_dict(p->filter, NULL);
> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index a6cdf9994c..3d46923cad 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -133,18 +133,28 @@ struct AVFilterGraphInternal {
> FFFrameQueueGlobal frame_queues;
> };
>
> -struct AVFilterInternal {
> +typedef struct FFFilterContext {
> + /**
> + * The public AVFilterContext. See avfilter.h for it.
> + */
> + AVFilterContext p;
> +
> avfilter_execute_func *execute;
>
> // 1 when avfilter_init_*() was successfully called on this filter
> // 0 otherwise
> int initialized;
> -};
> +} FFFilterContext;
> +
> +static inline FFFilterContext *fffilterctx(AVFilterContext *ctx)
> +{
> + return (FFFilterContext*)ctx;
> +}
>
> static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func,
> void *arg, int *ret, int nb_jobs)
> {
> - return ctx->internal->execute(ctx, func, arg, ret, nb_jobs);
> + return fffilterctx(ctx)->execute(ctx, func, arg, ret, nb_jobs);
> }
>
> enum FilterFormatsState {
Will apply this patchset tomorrow with the change that link_internal.h
will be merged into avfilter_internal.h unless there are objections.
- Andreas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread