History

avfilter/avfiltergraph: Avoid allocation for AVFilterGraphInternal

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.

Andreas Rheinhardt committed 2 years ago

Commit 03567ed1 parent a1aec774 files · +43 −35Browse files

Showing the changes to libavfilter (4 of 4 files). Show all

Unified · Split

4 files
  1. libavfilter/avfilter.c +3 −3
  2. libavfilter/avfilter_internal.h +13 −4
  3. libavfilter/avfiltergraph.c +15 −17
  4. libavfilter/pthread.c +12 −11
libavfilter/avfilter.c+3−3
@@ -187,7 +187,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 186 unmodified lines
187187 av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
188188 link->format = -1;
189189 link->colorspace = AVCOL_SPC_UNSPECIFIED;
190− ff_framequeue_init(&li->fifo, &src->graph->internal->frame_queues);
190+ ff_framequeue_init(&li->fifo, &fffiltergraph(src->graph)->frame_queues);
191191
192192 return 0;
193193 }
@@ -904,9 +904,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) · 710 unmodified lines
904904
905905 if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
906906 ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
907− ctx->graph->internal->thread_execute) {
907+ fffiltergraph(ctx->graph)->thread_execute) {
908908 ctx->thread_type = AVFILTER_THREAD_SLICE;
909− ctxi->execute = ctx->graph->internal->thread_execute;
909+ ctxi->execute = fffiltergraph(ctx->graph)->thread_execute;
910910 } else {
911911 ctx->thread_type = 0;
912912 }
libavfilter/avfilter_internal.h+13−4
@@ -78,11 +78,20 @@ typedef struct AVFilterCommand { · 77 unmodified lines
7878 struct AVFilterCommand *next;
7979 } AVFilterCommand;
8080
81−struct AVFilterGraphInternal {
81+typedef struct FFFilterGraph {
82+ /**
83+ * The public AVFilterGraph. See avfilter.h for it.
84+ */
85+ AVFilterGraph p;
8286 void *thread;
8387 avfilter_execute_func *thread_execute;
8488 FFFrameQueueGlobal frame_queues;
85−};
89+} FFFilterGraph;
90+
91+static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph)
92+{
93+ return (FFFilterGraph*)graph;
94+}
8695
8796 /**
8897 * Update the position of a link in the age heap.
@@ -119,8 +128,8 @@ int ff_filter_activate(AVFilterContext *filter); · 30 unmodified lines
119128 int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
120129 AVDictionary **options, const char *args);
121130
122−int ff_graph_thread_init(AVFilterGraph *graph);
131+int ff_graph_thread_init(FFFilterGraph *graph);
123132
124−void ff_graph_thread_free(AVFilterGraph *graph);
133+void ff_graph_thread_free(FFFilterGraph *graph);
125134
126135 #endif /* AVFILTER_AVFILTER_INTERNAL_H */
libavfilter/avfiltergraph.c+15−17
@@ -67,33 +67,30 @@ static const AVClass filtergraph_class = { · 66 unmodified lines
6767 };
6868
6969 #if !HAVE_THREADS
70−void ff_graph_thread_free(AVFilterGraph *graph)
70+void ff_graph_thread_free(FFFilterGraph *graph)
7171 {
7272 }
7373
74−int ff_graph_thread_init(AVFilterGraph *graph)
74+int ff_graph_thread_init(FFFilterGraph *graph)
7575 {
76− graph->thread_type = 0;
77− graph->nb_threads = 1;
76+ graph->p.thread_type = 0;
77+ graph->p.nb_threads = 1;
7878 return 0;
7979 }
8080 #endif
8181
8282 AVFilterGraph *avfilter_graph_alloc(void)
8383 {
84− AVFilterGraph *ret = av_mallocz(sizeof(*ret));
85− if (!ret)
86− return NULL;
84+ FFFilterGraph *graph = av_mallocz(sizeof(*graph));
85+ AVFilterGraph *ret;
8786
88− ret->internal = av_mallocz(sizeof(*ret->internal));
89− if (!ret->internal) {
90− av_freep(&ret);
87+ if (!graph)
9188 return NULL;
92− }
9389
90+ ret = &graph->p;
9491 ret->av_class = &filtergraph_class;
9592 av_opt_set_defaults(ret);
96− ff_framequeue_global_init(&ret->internal->frame_queues);
93+ ff_framequeue_global_init(&graph->frame_queues);
9794
9895 return ret;
9996 }
@@ -119,6 +116,7 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter · 19 unmodified lines
119116 void avfilter_graph_free(AVFilterGraph **graphp)
120117 {
121118 AVFilterGraph *graph = *graphp;
119+ FFFilterGraph *graphi = fffiltergraph(graph);
122120
123121 if (!graph)
124122 return;
@@ -126,14 +124,13 @@ void avfilter_graph_free(AVFilterGraph **graphp) · 1 unmodified line
126124 while (graph->nb_filters)
127125 avfilter_free(graph->filters[0]);
128126
129− ff_graph_thread_free(graph);
127+ ff_graph_thread_free(graphi);
130128
131129 av_freep(&graph->sink_links);
132130
133131 av_opt_free(graph);
134132
135133 av_freep(&graph->filters);
136− av_freep(&graph->internal);
137134 av_freep(graphp);
138135 }
139136
@@ -169,12 +166,13 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 29 unmodified lines
169166 const char *name)
170167 {
171168 AVFilterContext **filters, *s;
169+ FFFilterGraph *graphi = fffiltergraph(graph);
172170
173− if (graph->thread_type && !graph->internal->thread_execute) {
171+ if (graph->thread_type && !graphi->thread_execute) {
174172 if (graph->execute) {
175− graph->internal->thread_execute = graph->execute;
173+ graphi->thread_execute = graph->execute;
176174 } else {
177− int ret = ff_graph_thread_init(graph);
175+ int ret = ff_graph_thread_init(graphi);
178176 if (ret < 0) {
179177 av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
180178 return NULL;
libavfilter/pthread.c+12−11
@@ -58,7 +58,7 @@ static void slice_thread_uninit(ThreadContext *c) · 57 unmodified lines
5858 static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,
5959 void *arg, int *ret, int nb_jobs)
6060 {
61− ThreadContext *c = ctx->graph->internal->thread;
61+ ThreadContext *c = fffiltergraph(ctx->graph)->thread;
6262
6363 if (nb_jobs <= 0)
6464 return 0;
@@ -79,8 +79,9 @@ static int thread_init_internal(ThreadContext *c, int nb_threads) · 14 unmodified lines
7979 return FFMAX(nb_threads, 1);
8080 }
8181
82−int ff_graph_thread_init(AVFilterGraph *graph)
82+int ff_graph_thread_init(FFFilterGraph *graphi)
8383 {
84+ AVFilterGraph *graph = &graphi->p;
8485 int ret;
8586
8687 if (graph->nb_threads == 1) {
@@ -88,27 +89,27 @@ int ff_graph_thread_init(AVFilterGraph *graph) · 1 unmodified line
8889 return 0;
8990 }
9091
91− graph->internal->thread = av_mallocz(sizeof(ThreadContext));
92− if (!graph->internal->thread)
92+ graphi->thread = av_mallocz(sizeof(ThreadContext));
93+ if (!graphi->thread)
9394 return AVERROR(ENOMEM);
9495
95− ret = thread_init_internal(graph->internal->thread, graph->nb_threads);
96+ ret = thread_init_internal(graphi->thread, graph->nb_threads);
9697 if (ret <= 1) {
97− av_freep(&graph->internal->thread);
98+ av_freep(&graphi->thread);
9899 graph->thread_type = 0;
99100 graph->nb_threads = 1;
100101 return (ret < 0) ? ret : 0;
101102 }
102103 graph->nb_threads = ret;
103104
104− graph->internal->thread_execute = thread_execute;
105+ graphi->thread_execute = thread_execute;
105106
106107 return 0;
107108 }
108109
109−void ff_graph_thread_free(AVFilterGraph *graph)
110+void ff_graph_thread_free(FFFilterGraph *graph)
110111 {
111− if (graph->internal->thread)
112− slice_thread_uninit(graph->internal->thread);
113− av_freep(&graph->internal->thread);
112+ if (graph->thread)
113+ slice_thread_uninit(graph->thread);
114+ av_freep(&graph->thread);
114115 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t